1 /* address.c -- representation of network addresses 2 * 3 * Copyright (C) 2015 Olaf Bergmann <bergmann@tzi.org> 4 * 5 * This file is part of the CoAP library libcoap. Please see 6 * README for terms of use. 7 */ 8 9 #ifdef WITH_POSIX 10 #include <assert.h> 11 #include <netinet/in.h> 12 #include <sys/socket.h> 13 14 #include "address.h" 15 16 int coap_address_equals(const coap_address_t * a,const coap_address_t * b)17coap_address_equals(const coap_address_t *a, const coap_address_t *b) { 18 assert(a); assert(b); 19 20 if (a->size != b->size || a->addr.sa.sa_family != b->addr.sa.sa_family) 21 return 0; 22 23 /* need to compare only relevant parts of sockaddr_in6 */ 24 switch (a->addr.sa.sa_family) { 25 case AF_INET: 26 return 27 a->addr.sin.sin_port == b->addr.sin.sin_port && 28 memcmp(&a->addr.sin.sin_addr, &b->addr.sin.sin_addr, 29 sizeof(struct in_addr)) == 0; 30 case AF_INET6: 31 return a->addr.sin6.sin6_port == b->addr.sin6.sin6_port && 32 memcmp(&a->addr.sin6.sin6_addr, &b->addr.sin6.sin6_addr, 33 sizeof(struct in6_addr)) == 0; 34 default: /* fall through and signal error */ 35 ; 36 } 37 return 0; 38 } 39 40 #else /* WITH_POSIX */ 41 42 /* make compilers happy that do not like empty modules */ dummy()43static inline void dummy() 44 { 45 } 46 47 #endif /* not WITH_POSIX */ 48 49