Annotation of researchv9/ipc/src/libin/in_service.c, revision 1.1.1.1

1.1       root        1: #include <stdio.h>
                      2: #include <sys/inet/in.h>
                      3: #include "config.h"
                      4: 
                      5: /* imported */
                      6: extern char *in_getw();
                      7: extern char *strchr();
                      8: extern char *strcpy();
                      9: 
                     10: /*
                     11:  *     Look up the service matching the given parameters.
                     12:  */
                     13: struct in_service *
                     14: in_service(name, proto, port)
                     15: char *name;
                     16: char *proto;
                     17: unsigned long port;
                     18: {
                     19:        static struct in_service serv;
                     20:        static char sname[64], sproto[64];
                     21:        char buf[512], *p;
                     22:        FILE *fp;
                     23: 
                     24:        if((fp = fopen(SERVICES, "r")) == 0){
                     25:                perror(SERVICES);
                     26:                return(0);
                     27:        }
                     28:        while(fgets(buf, sizeof(buf), fp)){
                     29:                if(buf[0] == '\n' || buf[0] == '#')
                     30:                        continue;
                     31:                if((p = in_getw(buf, sname)) == 0)
                     32:                        continue;
                     33:                serv.name = sname;
                     34:                if(name != NULL && strcmp(name, serv.name) != 0)
                     35:                        continue;
                     36:                if(in_getw(p, sproto)==0)
                     37:                        continue;
                     38:                serv.port = atoi(sproto);
                     39:                if((port || name==NULL) && port != serv.port)
                     40:                        continue;
                     41:                p = strchr(sproto, '/');
                     42:                serv.proto = p == NULL ? "tcp" : p+1;
                     43:                if(proto != NULL && strcmp(proto, serv.proto) != 0)
                     44:                        continue;
                     45: 
                     46:                /* we've got a match */
                     47:                fclose(fp);
                     48:                return(&serv);
                     49:        }
                     50:        fclose(fp);
                     51:        if (name == NULL) {
                     52:                sprintf(sname, "%d", port);
                     53:                strcpy(sproto, proto!=NULL ? proto : "tcp");
                     54:                serv.proto = sproto;
                     55:                serv.name = sname;
                     56:                serv.port = port;
                     57:                return(&serv);
                     58:        }
                     59:                
                     60:        return(NULL);
                     61: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.