chiark / gitweb /
disobedience, playrtp: Have `playrtp' handle volume control.
[disorder] / lib / addr.c
index f23da74b1646e07796de7beabe650a8937d09426..1b62251629c2bb96b626f01b0fe4e5c45dee27f7 100644 (file)
@@ -33,6 +33,9 @@
 #if HAVE_SYS_UN_H
 # include <sys/un.h>
 #endif
+#if HAVE_WS2TCPIP_H
+# include <Ws2tcpip.h>
+#endif
 
 #include "log.h"
 #include "printf.h"
@@ -66,12 +69,14 @@ struct addrinfo *get_address(const struct stringlist *a,
   struct addrinfo *res;
   char *name;
   int rc;
+  char errbuf[1024];
 
   switch(a->n) {  
   case 1:
     byte_xasprintf(&name, "host * service %s", a->s[0]);
     if((rc = getaddrinfo(0, a->s[0], pref, &res))) {
-      disorder_error(0, "getaddrinfo %s: %s", a->s[0], gai_strerror(rc));
+      disorder_error(0, "getaddrinfo %s: %s", a->s[0],
+                     format_error(ec_getaddrinfo, rc, errbuf, sizeof errbuf));
       return 0;
     }
     break;
@@ -79,7 +84,8 @@ struct addrinfo *get_address(const struct stringlist *a,
     byte_xasprintf(&name, "host %s service %s", a->s[0], a->s[1]);
     if((rc = getaddrinfo(a->s[0], a->s[1], pref, &res))) {
       disorder_error(0, "getaddrinfo %s %s: %s",
-                    a->s[0], a->s[1], gai_strerror(rc));
+                     a->s[0], a->s[1],
+                     format_error(ec_getaddrinfo, rc, errbuf, sizeof errbuf));
       return 0;
     }
     break;
@@ -167,12 +173,12 @@ static inline char *format_sockaddr4(const struct sockaddr_in *sin4) {
 
   if(sin4->sin_port)
     byte_xasprintf(&r, "%s port %u",
-                  inet_ntop(sin4->sin_family, &sin4->sin_addr,
+                  inet_ntop(sin4->sin_family, (void *)&sin4->sin_addr,
                             buffer, sizeof buffer),
                   ntohs(sin4->sin_port));
   else
     byte_xasprintf(&r, "%s",
-                  inet_ntop(sin4->sin_family, &sin4->sin_addr,
+                  inet_ntop(sin4->sin_family, (void *)&sin4->sin_addr,
                             buffer, sizeof buffer));
   return r;
 }
@@ -183,12 +189,12 @@ static inline char *format_sockaddr6(const struct sockaddr_in6 *sin6) {
 
   if(sin6->sin6_port)
     byte_xasprintf(&r, "%s port %u",
-                  inet_ntop(sin6->sin6_family, &sin6->sin6_addr,
+                  inet_ntop(sin6->sin6_family, (void *)&sin6->sin6_addr,
                             buffer, sizeof buffer),
                   ntohs(sin6->sin6_port));
   else
     byte_xasprintf(&r, "%s",
-                  inet_ntop(sin6->sin6_family, &sin6->sin6_addr,
+                  inet_ntop(sin6->sin6_family, (void *)&sin6->sin6_addr,
                             buffer, sizeof buffer));
   return r;
 }
@@ -229,6 +235,8 @@ int netaddress_parse(struct netaddress *na,
                     int nvec,
                     char **vec) {
   const char *port;
+  long p;
+  int e;
 
   na->af = AF_UNSPEC;
   if(nvec > 0 && vec[0][0] == '-') {
@@ -279,8 +287,7 @@ int netaddress_parse(struct netaddress *na,
     }
     if(port[strspn(port, "0123456789")])
       return -1;
-    long p;
-    int e = xstrtol(&p, port, NULL, 10);
+    e = xstrtol(&p, port, NULL, 10);
 
     if(e)
       return -1;
@@ -317,7 +324,7 @@ void netaddress_format(const struct netaddress *na,
   if(na->port != -1) {
     char buffer[64];
 
-    snprintf(buffer, sizeof buffer, "%d", na->port);
+    byte_snprintf(buffer, sizeof buffer, "%d", na->port);
     vector_append(v, xstrdup(buffer));
   }
   vector_terminate(v);
@@ -339,17 +346,19 @@ struct addrinfo *netaddress_resolve(const struct netaddress *na,
   struct addrinfo *res, hints[1];
   char service[64];
   int rc;
+  char errbuf[1024];
 
   memset(hints, 0, sizeof hints);
   hints->ai_family = na->af;
   hints->ai_protocol = protocol;
   hints->ai_flags = passive ? AI_PASSIVE : 0;
-  snprintf(service, sizeof service, "%d", na->port);
+  byte_snprintf(service, sizeof service, "%d", na->port);
   rc = getaddrinfo(na->address, service, hints, &res);
   if(rc) {
     disorder_error(0, "getaddrinfo %s %d: %s",
                   na->address ? na->address : "*",
-                  na->port, gai_strerror(rc));
+                   na->port,
+                   format_error(ec_getaddrinfo, rc, errbuf, sizeof errbuf));
     return NULL;
   }
   return res;