Annotation of embedaddon/mtr/packet/sockaddr.c, revision 1.1.1.2
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: {
1.1.1.2 ! misho 8: if ( x == NULL )
1.1 misho 9: return NULL;
10:
1.1.1.2 ! misho 11: if ( ((struct sockaddr *)(x))->sa_family == AF_INET )
1.1 misho 12: {
13: return ((void *)(x) + offsetof(struct sockaddr_in, sin_addr));
1.1.1.2 ! misho 14: } else
! 15: if ( ((struct sockaddr *)(x))->sa_family == AF_INET6 )
1.1 misho 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: {
1.1.1.2 ! misho 25: if ( x == NULL )
1.1 misho 26: return 0;
1.1.1.2 ! misho 27: if ( ((struct sockaddr *)(x))->sa_family == AF_INET )
1.1 misho 28: {
29: return sizeof(struct in_addr);
1.1.1.2 ! misho 30: } else
! 31: if ( ((struct sockaddr *)(x))->sa_family == AF_INET6 )
1.1 misho 32: {
33: return sizeof(struct in6_addr);
34: }
35: return 0;
36: }
37:
38:
39: unsigned int sockaddr_size(const void *x)
40: {
1.1.1.2 ! misho 41: if ( x == NULL )
1.1 misho 42: return 0;
1.1.1.2 ! misho 43: if ( ((struct sockaddr *)(x))->sa_family == AF_INET )
1.1 misho 44: {
45: return sizeof(struct sockaddr_in);
1.1.1.2 ! misho 46: } else
! 47: if ( ((struct sockaddr *)(x))->sa_family == AF_INET6 )
1.1 misho 48: {
49: return sizeof(struct sockaddr_in6);
50: }
51: return 0;
52: }
53:
54: in_port_t *sockaddr_port_offset(const void *x)
55: {
1.1.1.2 ! misho 56: if ( x == NULL )
1.1 misho 57: return NULL;
58:
1.1.1.2 ! misho 59: if ( ((struct sockaddr *)(x))->sa_family == AF_INET )
1.1 misho 60: {
61: return ((void *)(x) + offsetof(struct sockaddr_in, sin_port));
1.1.1.2 ! misho 62: } else
! 63: if ( ((struct sockaddr *)(x))->sa_family == AF_INET6 )
1.1 misho 64: {
65: return ((void *)(x) + offsetof(struct sockaddr_in6, sin6_port));
66: }
67:
68: return NULL;
69: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>