summaryrefslogtreecommitdiff
path: root/sys/src/ape/lib/bsd/gethostbyname.c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@gmx.de>2013-03-31 18:52:45 +0200
committercinap_lenrek <cinap_lenrek@gmx.de>2013-03-31 18:52:45 +0200
commitb6dc4ba5a44a2ed2a68266598ceb28b7a7d51af2 (patch)
treeb2af773db48a3606bd078055db925dbba6d4ffaa /sys/src/ape/lib/bsd/gethostbyname.c
parent9c7e1db701e0e80b42bb5990e2f6839d712bb984 (diff)
ape: initial IPv6 support, inet_pton()/inet_ntop(), getaddrinfo()/getnameinfo()
Diffstat (limited to 'sys/src/ape/lib/bsd/gethostbyname.c')
-rw-r--r--sys/src/ape/lib/bsd/gethostbyname.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/sys/src/ape/lib/bsd/gethostbyname.c b/sys/src/ape/lib/bsd/gethostbyname.c
index 749798510..9393865fb 100644
--- a/sys/src/ape/lib/bsd/gethostbyname.c
+++ b/sys/src/ape/lib/bsd/gethostbyname.c
@@ -29,7 +29,7 @@ struct hostent*
gethostbyname(char *name)
{
int i, t, fd, m;
- char *p, *bp;
+ char *p, *k, *bp;
int nn, na;
unsigned long x;
static struct hostent h;
@@ -44,7 +44,6 @@ gethostbyname(char *name)
/* connect to server */
fd = open("/net/cs", O_RDWR);
if(fd < 0){
- _syserrno();
h_errno = NO_RECOVERY;
return 0;
}
@@ -64,8 +63,8 @@ gethostbyname(char *name)
/* query the server */
if(write(fd, buf, strlen(buf)) < 0){
- _syserrno();
h_errno = TRY_AGAIN;
+ close(fd);
return 0;
}
lseek(fd, 0, 0);
@@ -81,19 +80,26 @@ gethostbyname(char *name)
/* parse the reply */
nn = na = 0;
for(bp = buf;;){
- p = strchr(bp, '=');
+ k = bp;
+ p = strchr(k, '=');
if(p == 0)
break;
*p++ = 0;
- if(strcmp(bp, "dom") == 0){
+ for(bp = p; *bp && *bp != ' '; bp++)
+ ;
+ if(*bp)
+ *bp++ = 0;
+ if(strcmp(k, "dom") == 0){
if(h.h_name == 0)
h.h_name = p;
if(nn < Nname)
nptr[nn++] = p;
- } else if(strcmp(bp, "sys") == 0){
+ } else if(strcmp(k, "sys") == 0){
if(nn < Nname)
nptr[nn++] = p;
- } else if(strcmp(bp, "ip") == 0){
+ } else if(strcmp(k, "ip") == 0){
+ if(strchr(p, ':') != 0)
+ continue; /* ignore ipv6 addresses */
x = inet_addr(p);
x = ntohl(x);
if(na < Nname){
@@ -105,11 +111,6 @@ gethostbyname(char *name)
na++;
}
}
- while(*p && *p != ' ')
- p++;
- if(*p)
- *p++ = 0;
- bp = p;
}
if(nn+na == 0){
h_errno = HOST_NOT_FOUND;