mirror of
https://github.com/obgm/libcoap.git
synced 2026-12-01 18:37:10 +03:00
address.[hc]: Fixed byteorder in coap_is_mcast() on platform posix
As IN_MULTICAST does a 32 bit comparison in host byte order, sin_addr.s_addr needs to be converted using ntohl(). This change also moves the coap_is_mcast() implementation to address.c because it has become too complex for inlining.
This commit is contained in:
1 parent
fb66920d5f
commit
292b0f0790
2 files changed
+25
-18
No files matched your search
+9
-17
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* address.h -- representation of network addresses
|
||||
*
|
||||
* Copyright (C) 2010-2011,2015 Olaf Bergmann <bergmann@tzi.org>
|
||||
* Copyright (C) 2010-2011,2015-2016 Olaf Bergmann <bergmann@tzi.org>
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see README for terms
|
||||
* of use.
|
||||
@@ -89,22 +89,6 @@ _coap_address_isany_impl(const coap_address_t *a) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int
|
||||
_coap_is_mcast_impl(const coap_address_t *a) {
|
||||
if (!a)
|
||||
return 0;
|
||||
|
||||
switch (a->addr.sa.sa_family) {
|
||||
case AF_INET:
|
||||
return IN_MULTICAST(a->addr.sin.sin_addr.s_addr);
|
||||
case AF_INET6:
|
||||
return IN6_IS_ADDR_MULTICAST(&a->addr.sin6.sin6_addr);
|
||||
default: /* fall through and signal error */
|
||||
;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif /* WITH_POSIX */
|
||||
|
||||
/**
|
||||
@@ -148,6 +132,13 @@ coap_address_isany(const coap_address_t *a) {
|
||||
return _coap_address_isany_impl(a);
|
||||
}
|
||||
|
||||
#ifdef WITH_POSIX
|
||||
/**
|
||||
* Checks if given address @p a denotes a multicast address. This function
|
||||
* returns @c 1 if @p a is multicast, @c 0 otherwise.
|
||||
*/
|
||||
int coap_is_mcast(const coap_address_t *a);
|
||||
#else /* WITH_POSIX */
|
||||
/**
|
||||
* Checks if given address @p a denotes a multicast address. This function
|
||||
* returns @c 1 if @p a is multicast, @c 0 otherwise.
|
||||
@@ -156,5 +147,6 @@ static inline int
|
||||
coap_is_mcast(const coap_address_t *a) {
|
||||
return a && _coap_is_mcast_impl(a);
|
||||
}
|
||||
#endif /* WITH_POSIX */
|
||||
|
||||
#endif /* _COAP_ADDRESS_H_ */
|
||||
+16
-1
@@ -1,6 +1,6 @@
|
||||
/* address.c -- representation of network addresses
|
||||
*
|
||||
* Copyright (C) 2015 Olaf Bergmann <bergmann@tzi.org>
|
||||
* Copyright (C) 2015-2016 Olaf Bergmann <bergmann@tzi.org>
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see
|
||||
* README for terms of use.
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#ifdef WITH_POSIX
|
||||
#include <assert.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
@@ -37,6 +38,20 @@ coap_address_equals(const coap_address_t *a, const coap_address_t *b) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int coap_is_mcast(const coap_address_t *a) {
|
||||
if (!a)
|
||||
return 0;
|
||||
|
||||
switch (a->addr.sa.sa_family) {
|
||||
case AF_INET:
|
||||
return IN_MULTICAST(ntohl(a->addr.sin.sin_addr.s_addr));
|
||||
case AF_INET6:
|
||||
return IN6_IS_ADDR_MULTICAST(&a->addr.sin6.sin6_addr);
|
||||
default: /* fall through and signal error */
|
||||
;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#else /* WITH_POSIX */
|
||||
|
||||
/* make compilers happy that do not like empty modules */
|
||||
|
||||
Reference in new issue
Block a user