diff options
Diffstat (limited to 'src/UDPServer/UDPServer.cpp')
-rw-r--r-- | src/UDPServer/UDPServer.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/UDPServer/UDPServer.cpp b/src/UDPServer/UDPServer.cpp index 42166b4..d2d1988 100644 --- a/src/UDPServer/UDPServer.cpp +++ b/src/UDPServer/UDPServer.cpp @@ -46,6 +46,7 @@ #include <string.h> #include <unistd.h> +#include <errno.h> #ifndef SOCK_CLOEXEC #define SOCK_CLOEXEC 0 @@ -55,6 +56,7 @@ UDPServer::UDPServer(const std::string& addr, int port) : f_port(port) , f_addr(addr) { + char errno_str[16]; char decimal_port[16]; snprintf(decimal_port, sizeof(decimal_port), "%d", f_port); decimal_port[sizeof(decimal_port) / sizeof(decimal_port[0]) - 1] = '\0'; @@ -69,11 +71,27 @@ UDPServer::UDPServer(const std::string& addr, int port) throw udp_client_server_runtime_error(("invalid address or port for UDP socket: \"" + addr + ":" + decimal_port + "\"").c_str()); } f_socket = socket(f_addrinfo->ai_family, SOCK_DGRAM | SOCK_CLOEXEC, IPPROTO_UDP); + // First call fails with LibVMA for some reason? + if (f_socket == -1) + f_socket = socket(f_addrinfo->ai_family, SOCK_DGRAM | SOCK_CLOEXEC, IPPROTO_UDP); if(f_socket == -1) { + sprintf(errno_str, "%d", errno); freeaddrinfo(f_addrinfo); - throw udp_client_server_runtime_error(("could not create UDP socket for: \"" + addr + ":" + decimal_port + "\"").c_str()); + throw udp_client_server_runtime_error(("could not create UDP socket for: \"" + addr + ":" + decimal_port + "\", errno: " + errno_str).c_str()); } + +/* + const char *strdev = "enp5s0d1"; + r = setsockopt(f_socket, SOL_SOCKET, SO_BINDTODEVICE, (void *)strdev, strlen(strdev)); + if(r != 0) + { + freeaddrinfo(f_addrinfo); + close(f_socket); + throw udp_client_server_runtime_error(("could not associate socket : \"" + addr + ":" + decimal_port + "\" with device \"" + strdev + "\"").c_str()); + } +*/ + r = bind(f_socket, f_addrinfo->ai_addr, f_addrinfo->ai_addrlen); if(r != 0) { |