Annotation of researchv10no/ipc/libin/tcp.c, revision 1.1

1.1     ! root        1: #include "defs.h"
        !             2: #include <ctype.h>
        !             3: #include <sys/inet/in.h>
        !             4: 
        !             5: /*
        !             6:  *  convert a port number into a file system name
        !             7:  */
        !             8: char *
        !             9: tcptofs(port)
        !            10:        int port;
        !            11: {
        !            12:        static char name[PATHLEN];
        !            13:        struct in_service *s;
        !            14: 
        !            15:        s = in_service((char *)0, "tcp", (unsigned long)port);
        !            16:        if(s)
        !            17:                sprintf(name, "/cs/%s", s->name);
        !            18:        else
        !            19:                sprintf(name, "/cs/tcp.%d", port);
        !            20:        return name;
        !            21: }
        !            22: 
        !            23: /*
        !            24:  *  convert an internal name into a port number
        !            25:  */
        !            26: fstotcp(name)
        !            27:        char *name;
        !            28: {
        !            29:        int port;
        !            30:        struct in_service *s;
        !            31: 
        !            32:        /*
        !            33:         *  the format could be
        !            34:         *      [/cs/][tcp.]nnn
        !            35:         *  where the []'s indicate optional peices and
        !            36:         *  nnn is the port number
        !            37:         */
        !            38:        if (strncmp(name, CSROOT, sizeof(CSROOT)-1)==0)
        !            39:                name += sizeof(CSROOT)-1;
        !            40:        if (strncmp(name, "tcp.", sizeof("tcp.")-1)==0)
        !            41:                name += sizeof("tcp.")-1;
        !            42:        for (port=0; *name; name++) {
        !            43:                if (!isdigit(*name)){
        !            44:                        port=0;
        !            45:                        break;
        !            46:                }
        !            47:                port = port*10 + (*name - '0');
        !            48:        }
        !            49:        /*
        !            50:         *  or this may be a name in /etc/inservices
        !            51:         */
        !            52:        if(port == 0) {
        !            53:                s = in_service(name, "tcp", (unsigned long)0);
        !            54:                if(s)
        !            55:                        port = s->port;
        !            56:        }
        !            57:        return port;
        !            58: }

unix.superglobalmegacorp.com

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