diff options
author | Sunghee Lee <sh2011.lee@samsung.com> | 2019-09-28 11:50:27 +0900 |
---|---|---|
committer | Angelo Mantellini <manangel@cisco.com> | 2019-10-01 13:09:14 +0200 |
commit | 2db5743133aaec8e7a1fd4f8a9ba6fdf77f9bc9a (patch) | |
tree | ff955e21d39cad9324eb363f5614828c8f20d202 | |
parent | c43b10fc4946134ff0e0bac9248408330f512432 (diff) |
[HICN-274] Use bindSocket API in Android
Signed-off-by: Sunghee Lee <sh2011.lee@samsung.com>
Change-Id: I10a2fa173662cc49d93a64426e2b4495670823ff
Signed-off-by: Angelo Mantellini <manangel@cisco.com>
-rw-r--r-- | hicn-light/src/hicn/CMakeLists.txt | 3 | ||||
-rw-r--r-- | hicn-light/src/hicn/io/udpListener.c | 38 |
2 files changed, 36 insertions, 5 deletions
diff --git a/hicn-light/src/hicn/CMakeLists.txt b/hicn-light/src/hicn/CMakeLists.txt index 0f711e353..9129cba17 100644 --- a/hicn-light/src/hicn/CMakeLists.txt +++ b/hicn-light/src/hicn/CMakeLists.txt @@ -43,9 +43,6 @@ list(APPEND TO_INSTALL_HEADER_FILES ${CMAKE_CURRENT_BINARY_DIR}/hicn-light/config.h ) -set(TO_INSTALL_HEADER_FILES -) - if (ANDROID_API) build_library(${LIBHICN_LIGHT} STATIC diff --git a/hicn-light/src/hicn/io/udpListener.c b/hicn-light/src/hicn/io/udpListener.c index 02deb49d1..f6b434fed 100644 --- a/hicn-light/src/hicn/io/udpListener.c +++ b/hicn-light/src/hicn/io/udpListener.c @@ -72,6 +72,10 @@ static ListenerOps udpTemplate = { static void _readcb(int fd, PARCEventType what, void * listener_void); +#ifdef __ANDROID__ +extern int bindSocket(int sock, const char* ifname); +#endif + #ifdef __linux__ ListenerOps *udpListener_CreateInet6(Forwarder *forwarder, struct sockaddr_in6 sin6, const char *interfaceName) { @@ -122,8 +126,23 @@ ListenerOps *udpListener_CreateInet6(Forwarder *forwarder, if (failure == 0) { #ifdef __linux__ - setsockopt(udp->udp_socket, SOL_SOCKET, SO_BINDTODEVICE, + int ret = setsockopt(udp->udp_socket, SOL_SOCKET, SO_BINDTODEVICE, interfaceName, strlen(interfaceName) + 1); + if (ret < 0) { + logger_Log(udp->logger, LoggerFacility_IO, PARCLogLevel_Debug, __func__, + "setsockopt(%d, SO_BINDTODEVICE, %s) failed (%d) %s", + udp->udp_socket, interfaceName, errno, strerror(errno)); +#ifdef __ANDROID__ + ret = bindSocket(udp->udp_socket, interfaceName); + if (ret < 0) { + logger_Log(udp->logger, LoggerFacility_IO, PARCLogLevel_Debug, __func__, + "bindSocket(%d, %s) failed", udp->udp_socket, interfaceName); + } else { + logger_Log(udp->logger, LoggerFacility_IO, PARCLogLevel_Debug, __func__, + "bindSocket(%d, %s) success", udp->udp_socket, interfaceName); + } +#endif + } #endif ops = parcMemory_AllocateAndClear(sizeof(ListenerOps)); @@ -214,8 +233,23 @@ ListenerOps *udpListener_CreateInet(Forwarder *forwarder, failure = bind(udp->udp_socket, (struct sockaddr *)&sin, sizeof(sin)); if (failure == 0) { #ifdef __linux__ - setsockopt(udp->udp_socket, SOL_SOCKET, SO_BINDTODEVICE, + int ret = setsockopt(udp->udp_socket, SOL_SOCKET, SO_BINDTODEVICE, interfaceName, strlen(interfaceName) + 1); + if (ret < 0) { + logger_Log(udp->logger, LoggerFacility_IO, PARCLogLevel_Debug, __func__, + "setsockopt(%d, SO_BINDTODEVICE, %s) failed (%d) %s", + udp->udp_socket, interfaceName, errno, strerror(errno)); +#ifdef __ANDROID__ + ret = bindSocket(udp->udp_socket, interfaceName); + if (ret < 0) { + logger_Log(udp->logger, LoggerFacility_IO, PARCLogLevel_Debug, __func__, + "bindSocket(%d, %s) failed", udp->udp_socket, interfaceName); + } else { + logger_Log(udp->logger, LoggerFacility_IO, PARCLogLevel_Debug, __func__, + "bindSocket(%d, %s) success", udp->udp_socket, interfaceName); + } +#endif + } #endif ops = parcMemory_AllocateAndClear(sizeof(ListenerOps)); parcAssertNotNull(ops, "parcMemory_AllocateAndClear(%zu) returned NULL", |