12 #include <sys/socket.h>
13 #include <netinet/in.h>
26 * for inet addresses only
29 gethostbyname(char *name)
35 static struct hostent h;
36 static char buf[1024];
37 static char *nptr[Nname+1];
38 static char *aptr[Nname+1];
39 static char addr[Nname][4];
42 t = _sock_ipattr(name);
44 /* connect to server */
45 fd = open("/net/cs", O_RDWR);
47 h_errno = NO_RECOVERY;
51 /* construct the query, always expect an ip# back */
54 snprintf(buf, sizeof buf, "!sys=%s ip=*", name);
57 snprintf(buf, sizeof buf, "!dom=%s ip=*", name);
60 snprintf(buf, sizeof buf, "!ip=%s", name);
64 /* query the server */
65 if(write(fd, buf, strlen(buf)) < 0){
71 for(i = 0; i < sizeof(buf)-1; i += m){
72 m = read(fd, buf+i, sizeof(buf) - 1 - i);
88 for(bp = p; *bp && *bp != ' '; bp++)
92 if(strcmp(k, "dom") == 0){
97 } else if(strcmp(k, "sys") == 0){
100 } else if(strcmp(k, "ip") == 0){
101 if(inet_aton(p, &in) == 0)
104 memmove(addr[na], (unsigned char*)&in.s_addr, 4);
111 h_errno = HOST_NOT_FOUND;
118 h.h_addr_list = aptr;
120 h.h_addrtype = AF_INET;