libcoap
4.1.2
src
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
17
coap_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 */
43
static
inline
void
dummy()
44
{
45
}
46
47
#endif
/* not WITH_POSIX */
48
coap_address_t::sin6
struct sockaddr_in6 sin6
Definition:
address.h:65
coap_address_t::sin
struct sockaddr_in sin
Definition:
address.h:64
coap_address_t
multi-purpose address abstraction
Definition:
address.h:59
assert
#define assert(...)
Definition:
mem.c:17
address.h
Representation of network addresses.
coap_address_equals
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
coap_address_t::addr
union coap_address_t::@0 addr
coap_address_t::size
socklen_t size
size of addr
Definition:
address.h:60
coap_address_t::sa
struct sockaddr sa
Definition:
address.h:62
Generated on Mon Jan 16 2017 18:42:32 for libcoap by
1.8.13