Annotation of researchv10no/ipc/libin/udp_lib.c, revision 1.1.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:                        flabclr(fd);    /* for security unix */
                     49:                        break;
                     50:                }
                     51:        }
                     52:        if (fd < 0)
                     53:                return -1;
                     54: 
                     55:        if (write(fd, (char *)&uu, sizeof(uu)) < 0) {
                     56: err:           close(fd);
                     57:                return -1;
                     58:        }
                     59:        if (read (fd, (char *)&ur, sizeof(ur)) != sizeof(ur))
                     60:                goto err;
                     61:        if (ur.reply != UDPR_OK)
                     62:                goto err;
                     63:        if (reply)
                     64:                *reply = ur;
                     65:        return fd;
                     66: }

unix.superglobalmegacorp.com

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