3 #ifndef _SOCK_ADDR_EQ_H_INCLUDED_
4 #define _SOCK_ADDR_EQ_H_INCLUDED_
10 /* socket address utilities
12 /* #include <sock_addr.h>
19 #include <sys/socket.h>
20 #include <netinet/in.h>
26 #define SOCK_ADDR_PTR(ptr) ((struct sockaddr *)(ptr))
27 #define SOCK_ADDR_FAMILY(ptr) SOCK_ADDR_PTR(ptr)->sa_family
29 #define SOCK_ADDR_LEN(ptr) SOCK_ADDR_PTR(ptr)->sa_len
32 #define SOCK_ADDR_IN_PTR(sa) ((struct sockaddr_in *)(sa))
33 #define SOCK_ADDR_IN_FAMILY(sa) SOCK_ADDR_IN_PTR(sa)->sin_family
34 #define SOCK_ADDR_IN_PORT(sa) SOCK_ADDR_IN_PTR(sa)->sin_port
35 #define SOCK_ADDR_IN_ADDR(sa) SOCK_ADDR_IN_PTR(sa)->sin_addr
36 #define IN_ADDR(ia) (*((struct in_addr *) (ia)))
38 extern int sock_addr_cmp_addr(const struct sockaddr
*, const struct sockaddr
*);
39 extern int sock_addr_cmp_port(const struct sockaddr
*, const struct sockaddr
*);
40 extern int sock_addr_in_loopback(const struct sockaddr
*);
45 #define SOCK_ADDR_LEN(sa) \
46 (SOCK_ADDR_PTR(sa)->sa_family == AF_INET6 ? \
47 sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in))
50 #define SOCK_ADDR_PORT(sa) \
51 (SOCK_ADDR_PTR(sa)->sa_family == AF_INET6 ? \
52 SOCK_ADDR_IN6_PORT(sa) : SOCK_ADDR_IN_PORT(sa))
53 #define SOCK_ADDR_PORTP(sa) \
54 (SOCK_ADDR_PTR(sa)->sa_family == AF_INET6 ? \
55 &SOCK_ADDR_IN6_PORT(sa) : &SOCK_ADDR_IN_PORT(sa))
57 #define SOCK_ADDR_IN6_PTR(sa) ((struct sockaddr_in6 *)(sa))
58 #define SOCK_ADDR_IN6_FAMILY(sa) SOCK_ADDR_IN6_PTR(sa)->sin6_family
59 #define SOCK_ADDR_IN6_PORT(sa) SOCK_ADDR_IN6_PTR(sa)->sin6_port
60 #define SOCK_ADDR_IN6_ADDR(sa) SOCK_ADDR_IN6_PTR(sa)->sin6_addr
61 #define IN6_ADDR(ia) (*((struct in6_addr *) (ia)))
63 #define SOCK_ADDR_EQ_ADDR(sa, sb) \
64 ((SOCK_ADDR_FAMILY(sa) == AF_INET && SOCK_ADDR_FAMILY(sb) == AF_INET \
65 && SOCK_ADDR_IN_ADDR(sa).s_addr == SOCK_ADDR_IN_ADDR(sb).s_addr) \
66 || (SOCK_ADDR_FAMILY(sa) == AF_INET6 && SOCK_ADDR_FAMILY(sb) == AF_INET6 \
67 && memcmp((char *) &(SOCK_ADDR_IN6_ADDR(sa)), \
68 (char *) &(SOCK_ADDR_IN6_ADDR(sb)), \
69 sizeof(SOCK_ADDR_IN6_ADDR(sa))) == 0))
71 #define SOCK_ADDR_EQ_PORT(sa, sb) \
72 ((SOCK_ADDR_FAMILY(sa) == AF_INET && SOCK_ADDR_FAMILY(sb) == AF_INET \
73 && SOCK_ADDR_IN_PORT(sa) == SOCK_ADDR_IN_PORT(sb)) \
74 || (SOCK_ADDR_FAMILY(sa) == AF_INET6 && SOCK_ADDR_FAMILY(sb) == AF_INET6 \
75 && SOCK_ADDR_IN6_PORT(sa) == SOCK_ADDR_IN6_PORT(sb)))
80 #define SOCK_ADDR_LEN(sa) sizeof(struct sockaddr_in)
83 #define SOCK_ADDR_PORT(sa) SOCK_ADDR_IN_PORT(sa))
84 #define SOCK_ADDR_PORTP(sa) &SOCK_ADDR_IN_PORT(sa))
86 #define SOCK_ADDR_EQ_ADDR(sa, sb) \
87 (SOCK_ADDR_FAMILY(sa) == AF_INET && SOCK_ADDR_FAMILY(sb) == AF_INET \
88 && SOCK_ADDR_IN_ADDR(sa).s_addr == SOCK_ADDR_IN_ADDR(sb).s_addr)
90 #define SOCK_ADDR_EQ_PORT(sa, sb) \
91 (SOCK_ADDR_FAMILY(sa) == AF_INET && SOCK_ADDR_FAMILY(sb) == AF_INET \
92 && SOCK_ADDR_IN_PORT(sa) == SOCK_ADDR_IN_PORT(sb))
99 /* The Secure Mailer license must be distributed with this software.
102 /* IBM T.J. Watson Research
104 /* Yorktown Heights, NY 10598, USA