Annotation of researchv10no/sys/inet/udp_output.c, revision 1.1.1.1

1.1       root        1: /*     udp_output.c    6.1     83/07/29        */
                      2: 
                      3: #include "sys/param.h"
                      4: #include "sys/stream.h"
                      5: 
                      6: #include "sys/inet/in.h"
                      7: #include "sys/inet/ip.h"
                      8: #include "sys/inet/ip_var.h"
                      9: #include "sys/inet/udp.h"
                     10: #include "sys/inet/udp_var.h"
                     11: 
                     12: #define        IPPROTO_UDP     17
                     13: #define        UDP_DATA_LEN    (1500-sizeof(struct udpiphdr))
                     14: 
                     15: /*
                     16:  * send out list data,
                     17:  * as a UDP packet
                     18:  * allocate, prepend, and fill in UDP headers here
                     19:  */
                     20: udp_output(data, udp)
                     21: register struct block *data;
                     22: register struct udp *udp;
                     23: {
                     24:        register struct block *head;
                     25:        register struct udpiphdr *ui;
                     26:        register int len;
                     27: 
                     28:        len = bp_len(data);
                     29:        if ((head = allocb(sizeof(struct udpiphdr))) == NULL) {
                     30:                bp_free(data);
                     31:                return;
                     32:        }
                     33: if (head == data) panic("udp_output");
                     34:        head->wptr += sizeof(struct udpiphdr);
                     35:        head->next = data;
                     36:        /*
                     37:         * Fill in block with extended UDP header
                     38:         * and addresses and length put into network format.
                     39:         */
                     40:        ui = (struct udpiphdr *)head->rptr;
                     41:        ui->ui_next = 0;
                     42:        ui->ui_bp = 0;
                     43:        ui->ui_x1 = 0;
                     44:        ui->ui_pr = IPPROTO_UDP;
                     45:        ui->ui_len = (u_short)len + sizeof (struct udphdr);
                     46:        ui->ui_len = htons((u_short)(ui->ui_len));
                     47:        ui->ui_src = htonl(udp->src);
                     48:        ui->ui_dst = htonl(udp->dst);
                     49:        ui->ui_sport = htons(udp->sport);
                     50:        ui->ui_dport = htons(udp->dport);
                     51:        ui->ui_ulen = ui->ui_len;
                     52: 
                     53:        /* Stuff checksum and output datagram. */
                     54:        ui->ui_sum = 0;
                     55:        if ((ui->ui_sum = in_cksum(head, sizeof(struct udpiphdr)+len)) == 0)
                     56:                ui->ui_sum = -1;
                     57: 
                     58: 
                     59:        /* Put length and timeout time into the `real' ip header. */
                     60:        ((struct ip *)ui)->ip_len = sizeof(struct udpiphdr)+len;
                     61:        ((struct ip *)ui)->ip_ttl = MAXTTL;
                     62: 
                     63:        /* Ip expects internet addresses in host order. */
                     64:        ui->ui_src = ntohl(ui->ui_src);
                     65:        ui->ui_dst = ntohl(ui->ui_dst);
                     66:        udp_ldout(head);
                     67: }

unix.superglobalmegacorp.com

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