Annotation of researchv9/ipc/src/libin/udp_lib.c, revision 1.1

1.1     ! root        1: #include <sys/types.h>
        !             2: #include <sys/inet/udp_user.h>
        !             3: #include <errno.h>
        !             4: 
        !             5: extern int errno;
        !             6: 
        !             7: udp_connect(sport, dhost, dport)
        !             8: in_addr dhost;
        !             9: udp_port sport, dport;
        !            10: {
        !            11:        return udp_open(UDPC_CONNECT, sport, dhost, dport, (struct udpreply *)0);
        !            12: }
        !            13: 
        !            14: udp_listen(sport, reply)
        !            15: udp_port sport;
        !            16: struct udpreply *reply;
        !            17: {
        !            18:        return udp_open(UDPC_LISTEN, sport, 0L, 0, reply);
        !            19: }
        !            20: 
        !            21: udp_datagram(sport)
        !            22: udp_port sport;
        !            23: {
        !            24:        return udp_open(UDPC_DATAGRAM, sport, 0L, 0, (struct udpreply *)0);
        !            25: }
        !            26: 
        !            27: 
        !            28: udp_open(cmd, sport, dhost, dport, reply)
        !            29: int cmd;
        !            30: u_short sport, dport;
        !            31: in_addr dhost;
        !            32: struct udpreply *reply;
        !            33: {
        !            34:        int fd, n;
        !            35:        struct udpuser uu;
        !            36:        struct udpreply ur;
        !            37:        char name[16];
        !            38: 
        !            39:        uu.cmd = cmd;
        !            40:        uu.sport = sport;
        !            41:        uu.dport = dport;
        !            42:        uu.dst = dhost;
        !            43: 
        !            44:        for(n = 0; n < 100; n++){
        !            45:                sprintf(name, "/dev/udp%02d", n);
        !            46:                fd = open(name, 2);
        !            47:                if(fd >= 0)
        !            48:                        break;
        !            49:        }
        !            50:        if (fd < 0)
        !            51:                return -1;
        !            52: 
        !            53:        if (write(fd, (char *)&uu, sizeof(uu)) < 0) {
        !            54: err:           close(fd);
        !            55:                return -1;
        !            56:        }
        !            57:        if (read (fd, (char *)&ur, sizeof(ur)) != sizeof(ur))
        !            58:                goto err;
        !            59:        if (ur.reply != UDPR_OK)
        !            60:                goto err;
        !            61:        if (reply)
        !            62:                *reply = ur;
        !            63:        return fd;
        !            64: }

unix.superglobalmegacorp.com

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