Annotation of embedaddon/mtr/packet/sockaddr.c, revision 1.1.1.1
1.1 misho 1: #include <stddef.h>
2: #include <sys/socket.h>
3: #include <netinet/in.h>
4: #include <arpa/inet.h>
5:
6: void *sockaddr_addr_offset(const void *x)
7: {
8: if( x == NULL )
9: return NULL;
10:
11: if( ((struct sockaddr *)(x))->sa_family == AF_INET )
12: {
13: return ((void *)(x) + offsetof(struct sockaddr_in, sin_addr));
14: }else
15: if( ((struct sockaddr *)(x))->sa_family == AF_INET6 )
16: {
17: return ((void *)(x) + offsetof(struct sockaddr_in6, sin6_addr));
18: }
19:
20: return NULL;
21: }
22:
23: unsigned int sockaddr_addr_size(const void *x)
24: {
25: if( x == NULL )
26: return 0;
27: if( ((struct sockaddr *)(x))->sa_family == AF_INET )
28: {
29: return sizeof(struct in_addr);
30: }else
31: if( ((struct sockaddr *)(x))->sa_family == AF_INET6 )
32: {
33: return sizeof(struct in6_addr);
34: }
35: return 0;
36: }
37:
38:
39: unsigned int sockaddr_size(const void *x)
40: {
41: if( x == NULL )
42: return 0;
43: if( ((struct sockaddr *)(x))->sa_family == AF_INET )
44: {
45: return sizeof(struct sockaddr_in);
46: }else
47: if( ((struct sockaddr *)(x))->sa_family == AF_INET6 )
48: {
49: return sizeof(struct sockaddr_in6);
50: }
51: return 0;
52: }
53:
54: in_port_t *sockaddr_port_offset(const void *x)
55: {
56: if( x == NULL )
57: return NULL;
58:
59: if( ((struct sockaddr *)(x))->sa_family == AF_INET )
60: {
61: return ((void *)(x) + offsetof(struct sockaddr_in, sin_port));
62: }else
63: if( ((struct sockaddr *)(x))->sa_family == AF_INET6 )
64: {
65: return ((void *)(x) + offsetof(struct sockaddr_in6, sin6_port));
66: }
67:
68: return NULL;
69: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>