From: Harlan Stenn Date: Fri, 7 Jan 2011 09:30:07 +0000 (+0000) Subject: Handle initial socket creation for sntp X-Git-Tag: NTP_4_2_7P131~42 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=965721f57aeda3871736d95422c95ace22207c32;p=thirdparty%2Fntp.git Handle initial socket creation for sntp bk: 4d26dd1fzwZ87SbP88Ozs_9DArUuUg --- diff --git a/sntp/main.c b/sntp/main.c index f87766466..8418799f6 100644 --- a/sntp/main.c +++ b/sntp/main.c @@ -5,6 +5,7 @@ #include "networking.h" #include "utilities.h" #include "log.h" +#include "libntp.h" #include #include @@ -20,6 +21,8 @@ int n_pending_dns = 0; int n_pending_ntp = 0; int ai_fam_pref = AF_UNSPEC; +SOCKET sock4 = -1; /* Socket for IPv4 */ +SOCKET sock6 = -1; /* Socket for IPv6 */ char *progname; struct event_base *base = NULL; @@ -282,12 +285,31 @@ dns_cb( : ""); for (ai = addr; ai; ai = ai->ai_next) { - char buf[128]; - const char *s = NULL; /* for display purposes */ - /* Open a socket */ - - /* Make it non-blocking */ + /* Open a socket and make it non-blocking */ + if (ai->ai_family == AF_INET) { + if (-1 == sock4) { + sock4 = socket(PF_INET, SOCK_DGRAM, 0); + if (-1 == sock4) { + /* error getting a socket */ + } + /* Make it nonb-locking */ + make_socket_nonblocking(sock4); + } + } + else if (ai->ai_family == AF_INET6) { + if (-1 == sock6) { + sock6 = socket(PF_INET6, SOCK_DGRAM, 0); + if (-1 == sock6) { + /* error getting a socket */ + } + /* Make it non-blocking */ + make_socket_nonblocking(sock6); + } + } + else { + /* unexpected ai_family value */ + } /* ** We're waiting for a response for either unicast