X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/blobdiff_plain/2e9ba080dd30434f3e8f88e63029280889586a32..92db088e5b292c1180a090ed369b9851e933e610:/lib/addr.c diff --git a/lib/addr.c b/lib/addr.c index 052466c..d1c9d01 100644 --- a/lib/addr.c +++ b/lib/addr.c @@ -1,6 +1,6 @@ /* * This file is part of DisOrder. - * Copyright (C) 2004, 2007, 2008 Richard Kettlewell + * Copyright (C) 2004, 2007, 2008, 2013 Richard Kettlewell * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,10 +21,18 @@ #include "common.h" #include -#include -#include -#include -#include +#if HAVE_SYS_SOCKET_H +# include +#endif +#if HAVE_NETINET_IN_H +# include +#endif +#if HAVE_ARPA_INET_H +# include +#endif +#if HAVE_SYS_UN_H +# include +#endif #include "log.h" #include "printf.h" @@ -58,12 +66,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; @@ -71,7 +81,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; @@ -185,10 +196,12 @@ static inline char *format_sockaddr6(const struct sockaddr_in6 *sin6) { return r; } +#if HAVE_SYS_UN_H /** @brief Format a UNIX socket address */ static inline char *format_sockaddrun(const struct sockaddr_un *sun) { return xstrdup(sun->sun_path); } +#endif /** @brief Construct a text description a sockaddr * @param sa Socket address @@ -200,8 +213,10 @@ char *format_sockaddr(const struct sockaddr *sa) { return format_sockaddr4((const struct sockaddr_in *)sa); case AF_INET6: return format_sockaddr6((const struct sockaddr_in6 *)sa); +#if HAVE_SYS_UN_H case AF_UNIX: return format_sockaddrun((const struct sockaddr_un *)sa); +#endif default: return 0; } @@ -327,6 +342,7 @@ 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; @@ -337,7 +353,8 @@ struct addrinfo *netaddress_resolve(const struct netaddress *na, 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;