1 | #ifndef SH_IPVX_H
|
---|
2 | #define SH_IPVX_H
|
---|
3 |
|
---|
4 | #include <sys/types.h>
|
---|
5 | #include <sys/socket.h>
|
---|
6 | #include <netdb.h>
|
---|
7 | #include <netinet/in.h>
|
---|
8 | #include <arpa/inet.h>
|
---|
9 |
|
---|
10 | #if defined(USE_IPVX)
|
---|
11 | #define SH_SSP_LEN(a) ((a)->ss_family == AF_INET) ? \
|
---|
12 | sizeof(struct sockaddr_in) : \
|
---|
13 | sizeof(struct sockaddr_in6)
|
---|
14 |
|
---|
15 | #define SH_SS_LEN(a) ((a).ss_family == AF_INET) ? \
|
---|
16 | sizeof(struct sockaddr_in) : \
|
---|
17 | sizeof(struct sockaddr_in6)
|
---|
18 | #else
|
---|
19 | #define SH_SSP_LEN(a) sizeof(struct sockaddr_in)
|
---|
20 | #define SH_SS_LEN(a) sizeof(struct sockaddr_in)
|
---|
21 | #endif
|
---|
22 |
|
---|
23 | struct sh_sockaddr {
|
---|
24 | int ss_family;
|
---|
25 |
|
---|
26 | struct sockaddr_in sin;
|
---|
27 | #if defined(USE_IPVX)
|
---|
28 | struct sockaddr_in6 sin6;
|
---|
29 | #endif
|
---|
30 | };
|
---|
31 |
|
---|
32 | /* Cast a sockaddress
|
---|
33 | */
|
---|
34 | struct sockaddr * sh_ipvx_sockaddr_cast (struct sh_sockaddr * ss);
|
---|
35 |
|
---|
36 | /* Compare with any_address
|
---|
37 | */
|
---|
38 | int sh_ipvx_isany (struct sh_sockaddr * a);
|
---|
39 |
|
---|
40 | /* Compare two addresses
|
---|
41 | */
|
---|
42 | int sh_ipvx_cmp(struct sh_sockaddr * a, struct sh_sockaddr * b);
|
---|
43 |
|
---|
44 | /* Set the port
|
---|
45 | */
|
---|
46 | int sh_ipvx_set_port(struct sh_sockaddr * ss, int port);
|
---|
47 |
|
---|
48 | /* Save a sockaddress
|
---|
49 | */
|
---|
50 | void sh_ipvx_save(struct sh_sockaddr * ss, int sa_family, struct sockaddr * sa);
|
---|
51 |
|
---|
52 | /* Determine whether the given address is numeric
|
---|
53 | */
|
---|
54 | int sh_ipvx_is_numeric (const char * addr);
|
---|
55 |
|
---|
56 | /* Convert a network address to an ascii numeric address
|
---|
57 | */
|
---|
58 | int sh_ipvx_ntoa (char * name, size_t name_size, struct sh_sockaddr * ss);
|
---|
59 |
|
---|
60 | /* Convert an ascii numeric address to a network address
|
---|
61 | */
|
---|
62 | int sh_ipvx_aton (const char * name, struct sh_sockaddr * ss);
|
---|
63 |
|
---|
64 | /* Try to find canonical hostname
|
---|
65 | */
|
---|
66 | char * sh_ipvx_canonical(const char * hostname, char * numeric, size_t nlen);
|
---|
67 |
|
---|
68 | /* Convert address to hostname
|
---|
69 | */
|
---|
70 | char * sh_ipvx_addrtoname(struct sh_sockaddr * ss);
|
---|
71 |
|
---|
72 | /* Try a reverse lookup
|
---|
73 | */
|
---|
74 | int sh_ipvx_reverse_check_ok (char * peer, int port, struct sh_sockaddr * ss);
|
---|
75 | #endif
|
---|