📄 udp.lst
字号:
C51 COMPILER V6.21 UDP 03/08/2002 13:07:33 PAGE 1
C51 COMPILER V6.21, COMPILATION OF MODULE UDP
OBJECT MODULE PLACED IN Udp.OBJ
COMPILER INVOKED BY: C:\KEIL\C51\BIN\C51.EXE Udp.c LARGE OPTIMIZE(SIZE) BROWSE DEBUG OBJECTEXTEND
stmt level source
1 #include <stdio.h>
2 #include <string.h>
3 #include "ethernet.h"
4 #include "ip.h"
5 #include "udp.h"
6 /* Return UDP data length (-1 if no data), 0 if not UDP */
7 int is_udp(IPKT *ip, int len)
8 {
9 1 UDPKT *udp;
10 1 WORD sum;
11 1 int dlen=0;
12 1 /* Check protocol & minimum length */
13 1 if (ip->i.pcol==PUDP && len>=sizeof(UDPHDR))
14 1 {
15 2 udp = (UDPKT *)ip; /* Do checksum */
16 2 sum = check_udp(udp, ip->i.sip, ip->i.dip, len);
17 2 if (!udp->u.check || sum==0xffff)
18 2 { /* If zero or correct.. */
19 3 len -= sizeof(UDPHDR); /* Subtract header len */
20 3 dlen = len>0 ? len : -1; /* Return -1 if data len=0 */
21 3 }
22 2 }
23 1 return(dlen);
24 1 }
25
26 /* Make a UDP datagram given the source & destination, data len */
27 int make_udp(ETHERFRAME * efp, NODE *srcep, NODE *destp, WORD dlen)
28 {
29 1 UDPKT *udp;
30 1 int ulen, ilen;
31 1 udp = (UDPKT *)(efp->edata);
32 1 udp->u.sport = srcep->port; /* Set ports */
33 1 udp->u.dport = destp->port;
34 1 ulen = dlen + sizeof(UDPHDR);
35 1 udp->u.len = ulen;
36 1 udp->u.check = 0;
37 1 ilen = make_ip(efp, srcep, destp, PUDP, (WORD)(ulen));
38 1 udp->u.check = ~check_udp(udp, udp->i.sip, udp->i.dip, ulen);
39 1 if (udp->u.check == 0) /* Change sum of 0 to FFFF */
40 1 udp->u.check = 0xffff;
41 1 return(ilen); /* Return IP length */
42 1 }
43
44 /* Return TCP checksum, given UDP (header + data) length.
45 ** The values must be in network byte-order */
46 WORD check_udp(UDPKT *udp, LWORD sip, LWORD dip, int ulen)
47 {
48 1 PHDR tph;
49 1 LWORD sum;
50 1 sum = csum(&udp->u, (WORD)ulen); /* Checksum TCP segment */
51 1 tph.len=ulen;
52 1 tph.srce = sip;
53 1 tph.dest = dip;
54 1 tph.z = 0;
55 1 tph.pcol = udp->i.pcol;
C51 COMPILER V6.21 UDP 03/08/2002 13:07:33 PAGE 2
56 1 sum += csum(&tph, sizeof(tph)); /* Checksum pseudo-header */
57 1 return((WORD)(sum + (sum /0x10000))); /* Return total plus carry */
58 1 }
59
60 /* Send a UDP datagram, given destination node, data and length */
61 void udp_transmit(ETHERFRAME *efp, NODE *sp, NODE *dp, void *dat, int len)
62 {
63 1 UDPKT *udp;
64 1 udp = (UDPKT *)efp->edata;
65 1 memmove(udp->udpdata, dat, len);
66 1 put_ethernet(efp, make_udp(efp, sp, dp, (WORD)max(len, 0)));
67 1 }
68
69
70 /* Get the frame driver type, source port, IP and Ethernet addrs */
71 void getudp_srce(ETHERFRAME *efp, NODE *np)
72 {
73 1 UDPKT *udp;
74 1 memset(np, 0, sizeof(NODE)); /* Clear unused fields */
75 1 getip_srce(efp, np); /* Get dtype, srce IP and Ether addrs */
76 1 udp = (UDPKT *)(efp->edata);
77 1 np->port = udp->u.sport; /* Get source port */
78 1 }
79
80 /* Get complete TCP local node data corresponding to frame dest IP address
81 ** Return 0 if no matching node */
82 int getudp_locdest(ETHERFRAME *efp, NODE *np)
83 {
84 1 UDPKT *udp;
85 1 int ok;
86 1 ok = getip_locdest(efp, np); /* Get addresses, dtype & netmask */
87 1 udp = (UDPKT *)(efp->edata); /* Get dest port */
88 1 np->port = udp->u.dport;
89 1 return(ok);
90 1 }
91
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 973 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- 86
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -