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

1.1       root        1: /*     udp_input.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: int    udpcksum = 0;
                     13: 
                     14: /*
                     15:  * UDP input routine
                     16:  */
                     17: udp_input(bp)
                     18: struct block *bp;
                     19: {
                     20:        register struct udpiphdr *ui;
                     21:        register struct block *head;
                     22:        int len, ulen;
                     23: 
                     24:        /*
                     25:         * Get IP and UDP header together in first block.
                     26:         * Note: IP leaves IP header in first block.
                     27:         */
                     28:        ui = (struct udpiphdr *)bp->rptr;
                     29: /*
                     30:  * must strip options so udpiphdr is in the right place
                     31:  */
                     32:        if (((struct ip *)ui)->ip_hl > (sizeof (struct ip) >> 2))
                     33:                ip_stripoptions(bp, (struct block *)0);
                     34: 
                     35:        if (BLEN(bp) < sizeof (struct udpiphdr)) {
                     36:                if ((bp = bp_pullup(bp, sizeof (struct udpiphdr))) == 0) {
                     37:                        udpstat.udps_hdrops++;
                     38:                        return;
                     39:                }
                     40:                ui = (struct udpiphdr *)bp->rptr;
                     41:        }
                     42: 
                     43:        /*
                     44:         * Checksum extended UDP header and data.
                     45:         */
                     46:        ulen = ((struct ip *)ui)->ip_len;
                     47:        len = sizeof (struct ip) + ulen;
                     48:        ui->ui_src = htonl(ui->ui_src);
                     49:        ui->ui_dst = htonl(ui->ui_dst);
                     50:        if (udpcksum) {
                     51:                ui->ui_next = 0;
                     52:                ui->ui_x1 = 0;
                     53:                ui->ui_len = htons((u_short)ulen);
                     54:                if (ui->ui_sum = in_cksum(bp, len)) {
                     55:                        printf("udp_cksum: sum %x len %d src %x\n", ui->ui_sum,
                     56:                                len, ui->ui_src);
                     57:                        udpstat.udps_badsum++;
                     58:                        bp_free(bp);
                     59:                        return;
                     60:                }
                     61:        }
                     62:        udpstat.udps_ipackets++;
                     63: 
                     64:        /*
                     65:         * Drop UDP and IP headers.
                     66:         */
                     67:        bp->rptr += sizeof(struct udpiphdr);
                     68: 
                     69:        /*
                     70:         * adjust size to reflect length 
                     71:         * find end of queue and adjust wptr accordingly
                     72:         */
                     73:        head = bp;
                     74:        len = 0;
                     75: /*
                     76:  * ulen is length of udphdr+data. since we've already shortened first buffer
                     77:  * by sizeof(udpiphdr), shorten ulen by sizeof(udphdr)
                     78:  */
                     79:        ulen -= sizeof(struct udphdr);
                     80:        while(bp) {
                     81:                len += bp->wptr - bp->rptr;
                     82:                if (len > ulen) {
                     83:                        bp->wptr -= len-ulen;
                     84:                        bp_free(bp->next);
                     85:                        bp->next = 0;
                     86:                }
                     87:                bp = bp->next;
                     88:        }
                     89: 
                     90:        /*
                     91:         * Convert UDP protocol specific fields to host format.
                     92:         */
                     93:        ui->ui_src = ntohl(ui->ui_src);
                     94:        ui->ui_dst = ntohl(ui->ui_dst);
                     95:        ui->ui_sport = ntohs(ui->ui_sport);
                     96:        ui->ui_dport = ntohs(ui->ui_dport);
                     97: 
                     98:        udpdrint(head, ui);
                     99: }

unix.superglobalmegacorp.com

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