X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/putty/blobdiff_plain/db74a69d9e792e349fad5bd69643a3fc32829bf7..d47accad0f250d5d59079001443df42fb04d67f2:/unix/uxnet.c?ds=inline diff --git a/unix/uxnet.c b/unix/uxnet.c index 96d3aa51..4467d082 100644 --- a/unix/uxnet.c +++ b/unix/uxnet.c @@ -301,7 +301,9 @@ static int sk_nextaddr(SockAddr addr, SockAddrStep *step) void sk_getaddr(SockAddr addr, char *buf, int buflen) { - + /* XXX not clear what we should return for Unix-domain sockets; let's + * hope the question never arises */ + assert(addr->superfamily != UNIX); if (addr->superfamily == UNRESOLVED) { strncpy(buf, addr->hostname, buflen); buf[buflen-1] = '\0'; @@ -359,9 +361,10 @@ static int sockaddr_is_loopback(struct sockaddr *sa) int sk_address_is_local(SockAddr addr) { - if (addr->superfamily == UNRESOLVED) return 0; /* we don't know; assume not */ + else if (addr->superfamily == UNIX) + return 1; else { #ifndef NO_IPV6 return sockaddr_is_loopback(addr->ais->ai_addr); @@ -1392,6 +1395,23 @@ int net_service_lookup(char *service) return 0; } +char *get_hostname(void) +{ + int len = 128; + char *hostname = NULL; + do { + len *= 2; + hostname = sresize(hostname, len, char); + if ((gethostname(hostname, len) < 0) && + (errno != ENAMETOOLONG)) { + sfree(hostname); + hostname = NULL; + break; + } + } while (strlen(hostname) >= len-1); + return hostname; +} + SockAddr platform_get_x11_unix_address(const char *sockpath, int displaynum) { SockAddr ret = snew(struct SockAddr_tag);