mirror of
https://github.com/obgm/libcoap.git
synced 2026-11-15 12:44:55 +03:00
address.[hc]: make coap_address_equals() not inline on POSIX
gcc-4.8 -Winline keeps complaining about the function's size, so it is now placed into address.c.
This commit is contained in:
1 parent
3a78280982
commit
2250db4c95
2 files changed
+57
-23
No files matched your search
+9
-23
@@ -1,6 +1,6 @@
|
||||
/* address.h -- representation of network addresses
|
||||
*
|
||||
* Copyright (C) 2010,2011 Olaf Bergmann <bergmann@tzi.org>
|
||||
* Copyright (C) 2010,2011,2015 Olaf Bergmann <bergmann@tzi.org>
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see
|
||||
* README for terms of use.
|
||||
@@ -88,28 +88,12 @@ typedef struct coap_address_t {
|
||||
} addr;
|
||||
} coap_address_t;
|
||||
|
||||
static inline int
|
||||
_coap_address_equals_impl(const coap_address_t *a,
|
||||
const coap_address_t *b) {
|
||||
if (a->size != b->size || a->addr.sa.sa_family != b->addr.sa.sa_family)
|
||||
return 0;
|
||||
|
||||
/* need to compare only relevant parts of sockaddr_in6 */
|
||||
switch (a->addr.sa.sa_family) {
|
||||
case AF_INET:
|
||||
return
|
||||
a->addr.sin.sin_port == b->addr.sin.sin_port &&
|
||||
memcmp(&a->addr.sin.sin_addr, &b->addr.sin.sin_addr,
|
||||
sizeof(struct in_addr)) == 0;
|
||||
case AF_INET6:
|
||||
return a->addr.sin6.sin6_port == b->addr.sin6.sin6_port &&
|
||||
memcmp(&a->addr.sin6.sin6_addr, &b->addr.sin6.sin6_addr,
|
||||
sizeof(struct in6_addr)) == 0;
|
||||
default: /* fall through and signal error */
|
||||
;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/**
|
||||
* Compares given address objects @p a and @p b. This function returns
|
||||
* @c 1 if addresses are equal, @c 0 otherwise. The parameters @p a
|
||||
* and @p b must not be @c NULL;
|
||||
*/
|
||||
int coap_address_equals(const coap_address_t *a, const coap_address_t *b);
|
||||
|
||||
static inline int
|
||||
_coap_address_isany_impl(const coap_address_t *a) {
|
||||
@@ -160,6 +144,7 @@ coap_address_init(coap_address_t *addr) {
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef WITH_POSIX
|
||||
/**
|
||||
* Compares given address objects @p a and @p b. This function returns
|
||||
* @c 1 if addresses are equal, @c 0 otherwise. The parameters @p a
|
||||
@@ -170,6 +155,7 @@ coap_address_equals(const coap_address_t *a, const coap_address_t *b) {
|
||||
assert(a); assert(b);
|
||||
return _coap_address_equals_impl(a, b);
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Checks if given address object @p a denotes the wildcard
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/* address.c -- representation of network addresses
|
||||
*
|
||||
* Copyright (C) 2015 Olaf Bergmann <bergmann@tzi.org>
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see
|
||||
* README for terms of use.
|
||||
*/
|
||||
|
||||
#ifdef WITH_POSIX
|
||||
#include <assert.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include "address.h"
|
||||
|
||||
int
|
||||
coap_address_equals(const coap_address_t *a, const coap_address_t *b) {
|
||||
assert(a); assert(b);
|
||||
|
||||
if (a->size != b->size || a->addr.sa.sa_family != b->addr.sa.sa_family)
|
||||
return 0;
|
||||
|
||||
/* need to compare only relevant parts of sockaddr_in6 */
|
||||
switch (a->addr.sa.sa_family) {
|
||||
case AF_INET:
|
||||
return
|
||||
a->addr.sin.sin_port == b->addr.sin.sin_port &&
|
||||
memcmp(&a->addr.sin.sin_addr, &b->addr.sin.sin_addr,
|
||||
sizeof(struct in_addr)) == 0;
|
||||
case AF_INET6:
|
||||
return a->addr.sin6.sin6_port == b->addr.sin6.sin6_port &&
|
||||
memcmp(&a->addr.sin6.sin6_addr, &b->addr.sin6.sin6_addr,
|
||||
sizeof(struct in6_addr)) == 0;
|
||||
default: /* fall through and signal error */
|
||||
;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else /* WITH_POSIX */
|
||||
|
||||
/* make compilers happy that do not like empty modules */
|
||||
static inline void dummy()
|
||||
{
|
||||
}
|
||||
|
||||
#endif /* not WITH_POSIX */
|
||||
|
||||
Reference in new issue
Block a user