Sync usage with man page.
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / util / sock_addr.h
bloba3464880fd4673b78891379d5d183bea6dbcafc2
1 /* $NetBSD$ */
3 #ifndef _SOCK_ADDR_EQ_H_INCLUDED_
4 #define _SOCK_ADDR_EQ_H_INCLUDED_
6 /*++
7 /* NAME
8 /* sock_addr 3h
9 /* SUMMARY
10 /* socket address utilities
11 /* SYNOPSIS
12 /* #include <sock_addr.h>
13 /* DESCRIPTION
14 /* .nf
17 * System library.
19 #include <sys/socket.h>
20 #include <netinet/in.h>
21 #include <string.h>
24 * External interface.
26 #define SOCK_ADDR_PTR(ptr) ((struct sockaddr *)(ptr))
27 #define SOCK_ADDR_FAMILY(ptr) SOCK_ADDR_PTR(ptr)->sa_family
28 #ifdef HAS_SA_LEN
29 #define SOCK_ADDR_LEN(ptr) SOCK_ADDR_PTR(ptr)->sa_len
30 #endif
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 *);
42 #ifdef HAS_IPV6
44 #ifndef HAS_SA_LEN
45 #define SOCK_ADDR_LEN(sa) \
46 (SOCK_ADDR_PTR(sa)->sa_family == AF_INET6 ? \
47 sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in))
48 #endif
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)))
77 #else
79 #ifndef HAS_SA_LEN
80 #define SOCK_ADDR_LEN(sa) sizeof(struct sockaddr_in)
81 #endif
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))
94 #endif
96 /* LICENSE
97 /* .ad
98 /* .fi
99 /* The Secure Mailer license must be distributed with this software.
100 /* AUTHOR(S)
101 /* Wietse Venema
102 /* IBM T.J. Watson Research
103 /* P.O. Box 704
104 /* Yorktown Heights, NY 10598, USA
105 /*--*/
107 #endif