libcoap  4.1.2
address.c
Go to the documentation of this file.
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
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 */
43 static inline void dummy()
44 {
45 }
46 
47 #endif /* not WITH_POSIX */
48 
struct sockaddr_in6 sin6
Definition: address.h:63
struct sockaddr_in sin
Definition: address.h:62
multi-purpose address abstraction
Definition: address.h:57
#define assert(...)
Definition: mem.c:17
Representation of network addresses.
int coap_address_equals(const coap_address_t *a, const coap_address_t *b)
Compares given address objects a and b.
Definition: address.c:17
union coap_address_t::@0 addr
socklen_t size
size of addr
Definition: address.h:58
struct sockaddr sa
Definition: address.h:60