Deleted Added
full compact
udp.c (84221) udp.c (92913)
1/* Taken from $NetBSD: net.c,v 1.20 1997/12/26 22:41:30 scottr Exp $ */
2
3/*
4 * Copyright (c) 1992 Regents of the University of California.
5 * All rights reserved.
6 *
7 * This software was developed by the Computer Systems Engineering group
8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and

--- 26 unchanged lines hidden (view full) ---

35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
38 *
39 * @(#) Header: net.c,v 1.9 93/08/06 19:32:15 leres Exp (LBL)
40 */
41
42#include <sys/cdefs.h>
1/* Taken from $NetBSD: net.c,v 1.20 1997/12/26 22:41:30 scottr Exp $ */
2
3/*
4 * Copyright (c) 1992 Regents of the University of California.
5 * All rights reserved.
6 *
7 * This software was developed by the Computer Systems Engineering group
8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and

--- 26 unchanged lines hidden (view full) ---

35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
38 *
39 * @(#) Header: net.c,v 1.9 93/08/06 19:32:15 leres Exp (LBL)
40 */
41
42#include <sys/cdefs.h>
43__FBSDID("$FreeBSD: head/lib/libstand/udp.c 84221 2001-09-30 22:28:01Z dillon $");
43__FBSDID("$FreeBSD: head/lib/libstand/udp.c 92913 2002-03-21 23:39:28Z obrien $");
44
45#include <sys/param.h>
46#include <sys/socket.h>
47
48#include <string.h>
49
50#include <net/if.h>
51#include <netinet/in.h>

--- 6 unchanged lines hidden (view full) ---

58#include <netinet/udp_var.h>
59
60#include "stand.h"
61#include "net.h"
62
63/* Caller must leave room for ethernet, ip and udp headers in front!! */
64ssize_t
65sendudp(d, pkt, len)
44
45#include <sys/param.h>
46#include <sys/socket.h>
47
48#include <string.h>
49
50#include <net/if.h>
51#include <netinet/in.h>

--- 6 unchanged lines hidden (view full) ---

58#include <netinet/udp_var.h>
59
60#include "stand.h"
61#include "net.h"
62
63/* Caller must leave room for ethernet, ip and udp headers in front!! */
64ssize_t
65sendudp(d, pkt, len)
66 register struct iodesc *d;
67 register void *pkt;
68 register size_t len;
66 struct iodesc *d;
67 void *pkt;
68 size_t len;
69{
69{
70 register ssize_t cc;
71 register struct ip *ip;
72 register struct udphdr *uh;
73 register u_char *ea;
70 ssize_t cc;
71 struct ip *ip;
72 struct udphdr *uh;
73 u_char *ea;
74
75#ifdef NET_DEBUG
76 if (debug) {
77 printf("sendudp: d=%lx called.\n", (long)d);
78 if (d) {
79 printf("saddr: %s:%d",
80 inet_ntoa(d->myip), ntohs(d->myport));
81 printf(" daddr: %s:%d\n",

--- 18 unchanged lines hidden (view full) ---

100 ip->ip_sum = in_cksum(ip, sizeof(*ip)); /* short, but special */
101
102 uh->uh_sport = d->myport;
103 uh->uh_dport = d->destport;
104 uh->uh_ulen = htons(len - sizeof(*ip));
105
106#ifndef UDP_NO_CKSUM
107 {
74
75#ifdef NET_DEBUG
76 if (debug) {
77 printf("sendudp: d=%lx called.\n", (long)d);
78 if (d) {
79 printf("saddr: %s:%d",
80 inet_ntoa(d->myip), ntohs(d->myport));
81 printf(" daddr: %s:%d\n",

--- 18 unchanged lines hidden (view full) ---

100 ip->ip_sum = in_cksum(ip, sizeof(*ip)); /* short, but special */
101
102 uh->uh_sport = d->myport;
103 uh->uh_dport = d->destport;
104 uh->uh_ulen = htons(len - sizeof(*ip));
105
106#ifndef UDP_NO_CKSUM
107 {
108 register struct udpiphdr *ui;
108 struct udpiphdr *ui;
109 struct ip tip;
110
111 /* Calculate checksum (must save and restore ip header) */
112 tip = *ip;
113 ui = (struct udpiphdr *)ip;
114 bzero(&ui->ui_x1, sizeof(ui->ui_x1));
115 ui->ui_len = uh->uh_ulen;
116 uh->uh_sum = in_cksum(ui, len);

--- 16 unchanged lines hidden (view full) ---

133}
134
135/*
136 * Receive a UDP packet and validate it is for us.
137 * Caller leaves room for the headers (Ether, IP, UDP)
138 */
139ssize_t
140readudp(d, pkt, len, tleft)
109 struct ip tip;
110
111 /* Calculate checksum (must save and restore ip header) */
112 tip = *ip;
113 ui = (struct udpiphdr *)ip;
114 bzero(&ui->ui_x1, sizeof(ui->ui_x1));
115 ui->ui_len = uh->uh_ulen;
116 uh->uh_sum = in_cksum(ui, len);

--- 16 unchanged lines hidden (view full) ---

133}
134
135/*
136 * Receive a UDP packet and validate it is for us.
137 * Caller leaves room for the headers (Ether, IP, UDP)
138 */
139ssize_t
140readudp(d, pkt, len, tleft)
141 register struct iodesc *d;
142 register void *pkt;
143 register size_t len;
141 struct iodesc *d;
142 void *pkt;
143 size_t len;
144 time_t tleft;
145{
144 time_t tleft;
145{
146 register ssize_t n;
147 register size_t hlen;
148 register struct ip *ip;
149 register struct udphdr *uh;
146 ssize_t n;
147 size_t hlen;
148 struct ip *ip;
149 struct udphdr *uh;
150 u_int16_t etype; /* host order */
151
152#ifdef NET_DEBUG
153 if (debug)
154 printf("readudp: called\n");
155#endif
156
157 uh = (struct udphdr *)pkt - 1;

--- 72 unchanged lines hidden (view full) ---

230 printf("readudp: bad dport %d != %d\n",
231 d->myport, ntohs(uh->uh_dport));
232#endif
233 return -1;
234 }
235
236#ifndef UDP_NO_CKSUM
237 if (uh->uh_sum) {
150 u_int16_t etype; /* host order */
151
152#ifdef NET_DEBUG
153 if (debug)
154 printf("readudp: called\n");
155#endif
156
157 uh = (struct udphdr *)pkt - 1;

--- 72 unchanged lines hidden (view full) ---

230 printf("readudp: bad dport %d != %d\n",
231 d->myport, ntohs(uh->uh_dport));
232#endif
233 return -1;
234 }
235
236#ifndef UDP_NO_CKSUM
237 if (uh->uh_sum) {
238 register struct udpiphdr *ui;
238 struct udpiphdr *ui;
239 struct ip tip;
240
241 n = ntohs(uh->uh_ulen) + sizeof(*ip);
242 if (n > RECV_SIZE - ETHER_SIZE) {
243 printf("readudp: huge packet, udp len %d\n", (int)n);
244 return -1;
245 }
246

--- 29 unchanged lines hidden ---
239 struct ip tip;
240
241 n = ntohs(uh->uh_ulen) + sizeof(*ip);
242 if (n > RECV_SIZE - ETHER_SIZE) {
243 printf("readudp: huge packet, udp len %d\n", (int)n);
244 return -1;
245 }
246

--- 29 unchanged lines hidden ---