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

Support DNS names for PrrtSocket_bind().

parent b4e35f53
Loading
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -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;

+6 −1
Original line number Diff line number Diff line
@@ -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: