diff options
Diffstat (limited to 'hicn-light/src/io')
-rw-r--r-- | hicn-light/src/io/hicnListener.c | 26 | ||||
-rw-r--r-- | hicn-light/src/io/tcpListener.h | 3 | ||||
-rw-r--r-- | hicn-light/src/io/udpListener.c | 44 | ||||
-rw-r--r-- | hicn-light/src/io/udpListener.h | 3 |
4 files changed, 59 insertions, 17 deletions
diff --git a/hicn-light/src/io/hicnListener.c b/hicn-light/src/io/hicnListener.c index 789face90..bcf4de6a3 100644 --- a/hicn-light/src/io/hicnListener.c +++ b/hicn-light/src/io/hicnListener.c @@ -55,22 +55,24 @@ struct hicn_listener { PARCEvent *hicn_event; int hicn_fd; // this is the file descriptor got from hicn library - Address *localAddress; // this is the local address or 0::0 in case of the - // main listener this is the address used inside - // forwarder to identify the listener. Notice that this - // address is the same as the fisical interfaces on - // which we create the TUN. it is NOT the TUN address - // which is given by libhicn after the bind operation - // However the user alway uses this address since is - // the only one available at configuration time + Address + *localAddress; // this is the local address or 0::0 in case of the + // main listener this is the address used inside + // forwarder to identify the listener. Notice that this + // address is the same as the fisical interfaces on + // which we create the TUN. it is NOT the TUN address + // which is given by libhicn after the bind operation + // However the user alway uses this address since is + // the only one available at configuration time unsigned inetFamily; int connection_id; // this is used only if the listener is used to receive // data packets we assume that 1 connection is associated - // to one listener in this case so we set the connection_id - // we the connection is create. if this id is not set and a - // data packet is received, the packet is dropped + // to one listener in this case so we set the + // connection_id we the connection is create. if this id + // is not set and a data packet is received, the packet is + // dropped unsigned conn_id; }; @@ -216,7 +218,7 @@ ListenerOps *hicnListener_CreateInet6(Forwarder *forwarder, char *symbolic, // the call to libhicn is the same both for the main and the normal listeners // in both cases we need to set only the identifier. In the case of normal // listener (listener for data packet) we let the library select the right ip - //address we just need to set the right type of packet + // address we just need to set the right type of packet hicn_socket_helper_t *hicnSocketHelper = forwarder_GetHicnSocketHelper(forwarder); diff --git a/hicn-light/src/io/tcpListener.h b/hicn-light/src/io/tcpListener.h index c5d1e33af..9664b32b0 100644 --- a/hicn-light/src/io/tcpListener.h +++ b/hicn-light/src/io/tcpListener.h @@ -25,7 +25,10 @@ #ifndef tcpListener_h #define tcpListener_h +#ifndef _WIN32 #include <netinet/in.h> +#endif + #include <src/core/forwarder.h> #include <src/io/listener.h> #include <stdlib.h> diff --git a/hicn-light/src/io/udpListener.c b/hicn-light/src/io/udpListener.c index 31c0e673b..1a16d6161 100644 --- a/hicn-light/src/io/udpListener.c +++ b/hicn-light/src/io/udpListener.c @@ -13,14 +13,16 @@ * limitations under the License. */ +#ifndef _WIN32 #include <arpa/inet.h> +#include <unistd.h> +#endif #include <errno.h> #include <fcntl.h> #include <src/config.h> #include <stdbool.h> #include <stdio.h> #include <string.h> -#include <unistd.h> #include <src/core/messageHandler.h> @@ -83,13 +85,24 @@ ListenerOps *udpListener_CreateInet6(Forwarder *forwarder, parcAssertFalse(udp->udp_socket < 0, "Error opening UDP socket: (%d) %s", errno, strerror(errno)); + int failure = 0; +#ifndef _WIN32 // Set non-blocking flag int flags = fcntl(udp->udp_socket, F_GETFL, NULL); parcAssertTrue(flags != -1, "fcntl failed to obtain file descriptor flags (%d)", errno); - int failure = fcntl(udp->udp_socket, F_SETFL, flags | O_NONBLOCK); + failure = fcntl(udp->udp_socket, F_SETFL, flags | O_NONBLOCK); parcAssertFalse(failure, "fcntl failed to set file descriptor flags (%d)", errno); +#else + // Set non-blocking flag + u_long mode = 1; + int result = ioctlsocket(udp->udp_socket, FIONBIO, &mode); + if (result != NO_ERROR) { + parcAssertTrue(result != NO_ERROR, + "ioctlsocket failed to set file descriptor"); + } +#endif int one = 1; // don't hang onto address after listener has closed @@ -126,8 +139,11 @@ ListenerOps *udpListener_CreateInet6(Forwarder *forwarder, myerrno, strerror(myerrno)); parcMemory_Deallocate((void **)&str); } - +#ifndef _WIN32 close(udp->udp_socket); +#else + closesocket(udp->udp_socket); +#endif addressDestroy(&udp->localAddress); logger_Release(&udp->logger); parcMemory_Deallocate((void **)&udp); @@ -152,13 +168,23 @@ ListenerOps *udpListener_CreateInet(Forwarder *forwarder, parcAssertFalse(udp->udp_socket < 0, "Error opening UDP socket: (%d) %s", errno, strerror(errno)); + int failure = 0; +#ifndef _WIN32 // Set non-blocking flag int flags = fcntl(udp->udp_socket, F_GETFL, NULL); parcAssertTrue(flags != -1, "fcntl failed to obtain file descriptor flags (%d)", errno); - int failure = fcntl(udp->udp_socket, F_SETFL, flags | O_NONBLOCK); + failure = fcntl(udp->udp_socket, F_SETFL, flags | O_NONBLOCK); parcAssertFalse(failure, "fcntl failed to set file descriptor flags (%d)", errno); +#else + u_long mode = 1; + int result = ioctlsocket(udp->udp_socket, FIONBIO, &mode); + if (result != NO_ERROR) { + parcAssertTrue(result != NO_ERROR, + "ioctlsocket failed to set file descriptor"); + } +#endif int one = 1; // don't hang onto address after listener has closed @@ -217,7 +243,12 @@ static void udpListener_Destroy(UdpListener **listenerPtr) { "UdpListener %p destroyed", (void *)udp); } +#ifndef _WIN32 close(udp->udp_socket); +#else + closesocket(udp->udp_socket); +#endif + addressDestroy(&udp->localAddress); dispatcher_DestroyNetworkEvent(forwarder_GetDispatcher(udp->forwarder), &udp->udp_event); @@ -276,7 +307,8 @@ static size_t _peekMessageLength(UdpListener *udp, int fd, size_t packetLength = 0; - uint8_t fixedHeader[messageHandler_GetIPHeaderLength(IPv6)]; + uint8_t *fixedHeader = (uint8_t *)malloc( + sizeof(uint8_t) * messageHandler_GetIPHeaderLength(IPv6)); // peek at the UDP packet and read in the fixed header. // Also returns the socket information for the remote peer @@ -294,6 +326,8 @@ static size_t _peekMessageLength(UdpListener *udp, int fd, } } + free(fixedHeader); + return packetLength; } diff --git a/hicn-light/src/io/udpListener.h b/hicn-light/src/io/udpListener.h index 1cf3bd887..14c03fd52 100644 --- a/hicn-light/src/io/udpListener.h +++ b/hicn-light/src/io/udpListener.h @@ -16,7 +16,10 @@ #ifndef udpListener_h #define udpListener_h +#ifndef _WIN32 #include <netinet/in.h> +#endif + #include <src/core/forwarder.h> #include <src/io/listener.h> #include <stdlib.h> |