comparison src/lib/network.c @ 10789:a4666cc8cb7b HEAD

liblib: Added net_ip_cmp().
author Timo Sirainen <tss@iki.fi>
date Sat, 20 Feb 2010 16:19:19 +0200
parents 615eef3139c2
children 260e190306b0
comparison
equal deleted inserted replaced
10788:81537f59512a 10789:a4666cc8cb7b
28 # define SIZEOF_SOCKADDR(so) (sizeof(so.sin)) 28 # define SIZEOF_SOCKADDR(so) (sizeof(so.sin))
29 #endif 29 #endif
30 30
31 bool net_ip_compare(const struct ip_addr *ip1, const struct ip_addr *ip2) 31 bool net_ip_compare(const struct ip_addr *ip1, const struct ip_addr *ip2)
32 { 32 {
33 return net_ip_cmp(ip1, ip2) == 0;
34 }
35
36 int net_ip_cmp(const struct ip_addr *ip1, const struct ip_addr *ip2)
37 {
33 if (ip1->family != ip2->family) 38 if (ip1->family != ip2->family)
34 return 0; 39 return ip1->family - ip2->family;
35 40
36 #ifdef HAVE_IPV6 41 #ifdef HAVE_IPV6
37 if (ip1->family == AF_INET6) { 42 if (ip1->family == AF_INET6)
38 return memcmp(&ip1->u.ip6, &ip2->u.ip6, 43 return memcmp(&ip1->u.ip6, &ip2->u.ip6, sizeof(ip1->u.ip6));
39 sizeof(ip1->u.ip6)) == 0; 44 #endif
40 } 45
41 #endif 46 return memcmp(&ip1->u.ip4, &ip2->u.ip4, sizeof(ip1->u.ip4));
42
43 return memcmp(&ip1->u.ip4, &ip2->u.ip4, sizeof(ip1->u.ip4)) == 0;
44 } 47 }
45 48
46 unsigned int net_ip_hash(const struct ip_addr *ip) 49 unsigned int net_ip_hash(const struct ip_addr *ip)
47 { 50 {
48 const unsigned char *p; 51 const unsigned char *p;