blob: 64b3dce57dfd56f23ff78d347470a46365ddb71f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <netinet/in.h>
#include <netns/ns.h>
#include <string.h>
int
net_addrcmp(sa1, sa2)
struct sockaddr *sa1;
struct sockaddr *sa2;
{
if (sa1->sa_len != sa2->sa_len)
return (sa1->sa_len < sa2->sa_len) ? -1 : 1;
if (sa1->sa_family != sa2->sa_family)
return (sa1->sa_family < sa2->sa_family) ? -1 : 1;
switch(sa1->sa_family) {
case AF_INET:
return (memcmp(&((struct sockaddr_in *)sa1)->sin_addr,
&((struct sockaddr_in *)sa2)->sin_addr,
sizeof(struct in_addr)));
case AF_INET6:
return (memcmp(&((struct sockaddr_in6 *)sa1)->sin6_addr,
&((struct sockaddr_in6 *)sa2)->sin6_addr,
sizeof(struct in6_addr)));
case AF_NS:
return (memcmp(&((struct sockaddr_ns *)sa1)->sns_addr,
&((struct sockaddr_ns *)sa2)->sns_addr,
sizeof(struct ns_addr)));
case AF_LOCAL:
return (strcmp(((struct sockaddr_un *)sa1)->sun_path,
((struct sockaddr_un *)sa1)->sun_path));
default:
return -1;
}
}
|