13 #include <sys/socket.h>
14 #include <netinet/in.h>
25 * for inet addresses only
28 getservbyname(char *name, char *proto)
33 static struct servent s;
34 static char buf[1024];
35 static char *nptr[Nname+1];
38 for(p = name; *p; p++)
44 /* connect to server */
45 fd = open("/net/cs", O_RDWR);
49 /* construct the query, always expect an ip# back */
51 snprintf(buf, sizeof buf, "!port=%s %s=*", name, proto);
53 snprintf(buf, sizeof buf, "!%s=%s port=*", proto, name);
55 /* query the server */
56 if(write(fd, buf, strlen(buf)) < 0){
61 for(i = 0; i < sizeof(buf)-1; i += m){
62 m = read(fd, buf+i, sizeof(buf) - 1 - i);
77 if(strcmp(bp, proto) == 0){
80 } else if(strcmp(bp, "port") == 0){
81 s.s_port = htons(atoi(p));
83 while(*p && *p != ' ')