Annotation of researchv10no/cmd/nupas/ipc/s5sockbcon.c, revision 1.1

1.1     ! root        1: #include       "stdio.h"
        !             2: #include       "tiuser.h"
        !             3: #include       "sys/fcntl.h"
        !             4: #include       "sys/stropts.h"
        !             5: 
        !             6: /*
        !             7:  *     s5sockbcon():   System V socket-bind-connect sequence
        !             8:  *
        !             9:  *     Alan M Buckwalter       3-90
        !            10:  *
        !            11:  *     Mimic the BSD socket(), bind() and connect() sequence using
        !            12:  *     System V TLI calls.
        !            13:  *
        !            14:  *     In:     IP Address              (char *)
        !            15:  *             Port Number             (int)
        !            16:  *             UNIX Device             (char *)
        !            17:  *     Out:    Open File Descriptor or -1 on Failure
        !            18:  *
        !            19:  *     Warning, there is a bug in the standard UTS Phase I inet_addr()
        !            20:  *             library call that corrupts the passed string.  Make sure
        !            21:  *             this fix is installed on your system to avoid any nasty
        !            22:  *             side affects from this routine.
        !            23:  */
        !            24: 
        !            25: #define        MAXRETRY        10
        !            26: 
        !            27: s5sockbcon(add,port,dev)
        !            28: char *add,*dev;
        !            29: int port;
        !            30: {
        !            31:        int                     netfd,i;
        !            32:        char                    addrs[20];
        !            33:        struct  t_call          *callp;
        !            34:        struct  netbuf          addr;
        !            35:        static  int             stoa();
        !            36:        static  char            *atos();
        !            37:        extern int              t_errno;
        !            38: 
        !            39:        sprintf(addrs,"\\x%08x%04x0000\0",inet_addr(add),port);
        !            40:        stoa(addrs,&addr);
        !            41: 
        !            42: #ifdef DEBUG
        !            43:        fprintf(stderr,"%s - %d\n",atos(&addr),addr.len);
        !            44: #endif
        !            45: 
        !            46:        /* open transport endpoint */
        !            47:        if((netfd=t_open(dev,O_RDWR,NULL))<0) {
        !            48:                t_error("t_open");
        !            49:                return(-1);
        !            50:        }
        !            51: 
        !            52:        /* bind default address */
        !            53:        if(t_bind(netfd,NULL,NULL)<0) {
        !            54:                t_error("t_bind");
        !            55:                return(-1);
        !            56:        }
        !            57: 
        !            58:        /* allocate call structure */
        !            59:        if((callp=(struct t_call *)t_alloc(netfd,T_CALL,0))==NULL) {
        !            60:                t_error("t_alloc");
        !            61:                return(-1);
        !            62:        }
        !            63: 
        !            64:        callp->addr.buf=addr.buf;
        !            65:        callp->addr.len=addr.len;
        !            66: 
        !            67:        /* connect to the listener */
        !            68:        for (i=0;i<MAXRETRY;i++) {
        !            69:                if(t_connect(netfd,callp,NULL)==0)
        !            70:                        break;
        !            71:                if((t_errno==TLOOK)&&(t_look(netfd)==T_DISCONNECT)) {
        !            72:                        t_rcvdis(netfd,NULL);
        !            73:                } else {
        !            74:                        t_error("t_connect");
        !            75:                        return(-1);
        !            76:                }
        !            77:        }
        !            78:        if(i>2) {
        !            79:                t_error("t_connect");
        !            80:                return(-1);
        !            81:        }
        !            82: 
        !            83:        /* push the read/write streams modules */
        !            84:        if(ioctl(netfd,I_PUSH,"tirdwr")<0) {
        !            85:                t_error("ioctl");
        !            86:                return(-1);
        !            87:        }
        !            88:        return(netfd);
        !            89: }
        !            90: 
        !            91: static int
        !            92: stoa(s, np)
        !            93: register char  *s;
        !            94: struct netbuf  *np;
        !            95: {
        !            96:        static char     buf[128];
        !            97:        register char   *bp = buf;
        !            98:        int     b;
        !            99: 
        !           100:        if (s[0] == '\\' && tolower(s[1]) == 'x') {
        !           101:                while (*(s += 2)) {
        !           102:                        sscanf(s, "%2x", &b);
        !           103:                        *bp++ = b;
        !           104:                }
        !           105:                np->len = bp - buf;
        !           106:        } else
        !           107:                np->len = strlen(strcpy(buf, s));
        !           108:        np->buf = buf;
        !           109:        return 1;
        !           110: }
        !           111: 
        !           112: static char *
        !           113: atos(np)
        !           114: register struct netbuf *np;
        !           115: {
        !           116:        static char     buf[128];
        !           117:        register char   *bp = buf;
        !           118:        register int    i;
        !           119: 
        !           120:        bp += sprintf(bp, "\\x");
        !           121:        for (i = 0; i < np->len; i++)
        !           122:                bp += sprintf(bp, "%.2x", np->buf[i]);
        !           123:        return buf;
        !           124: }

unix.superglobalmegacorp.com

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