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