Commit 04459a83 authored by Andreas Schmidt's avatar Andreas Schmidt

Support DNS names for PrrtSocket_bind().

parent b4e35f53
Pipeline #2884 passed with stages
in 1 minute and 27 seconds
......@@ -9,6 +9,7 @@
#include <linux/net_tstamp.h>
#include <assert.h>
#include <sys/ioctl.h>
#include <netdb.h>
#include "../defines.h"
#include "../util/common.h"
#include "../util/dbg.h"
......@@ -126,10 +127,15 @@ bool PrrtSocket_bind(PrrtSocket *s, const char *ipAddress, const uint16_t port)
struct sockaddr_in *address = calloc(1, size);
check_mem(address);
// TODO: Allow DNS names to be passed as ipAddress.
struct hostent *host = gethostbyname(ipAddress);
check(host, "gethostbyname(%s): %s", ipAddress, hstrerror(h_errno));
char buf[16];
unsigned char* addr = (unsigned char*) host->h_addr;
snprintf(buf, 16, "%u.%u.%u.%u", addr[0], addr[1], addr[2], addr[3]);
address->sin_family = AF_INET;
address->sin_addr.s_addr = inet_addr(ipAddress);
address->sin_addr.s_addr = inet_addr(buf);
address->sin_port = htons((uint16_t) (port));
s->address = address;
......
......@@ -138,7 +138,12 @@ cdef class PrrtSocket:
self._c_socket = cprrt.PrrtSocket_create(maximum_payload_size, target_delay_us)
if thread_pinning:
cprrt.PrrtSocket_enable_thread_pinning(self._c_socket)
cprrt.PrrtSocket_bind(self._c_socket, host.encode("utf8"), port)
if not cprrt.PrrtSocket_bind(self._c_socket, host.encode("utf8"), port):
# PrrtSocket_bind calls PrrtSocket_close on error
# so we need to set _c_socket to NULL because otherwise __dealloc__
# will attempt to call PrrtSocket_close again on the closed socket
self._c_socket = NULL
raise ValueError("PrrtSocket_bind failed")
# Channel Properties
property data_rate_btl_fwd:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment