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

unix.superglobalmegacorp.com

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