📄 ping.lst
字号:
C51 COMPILER V8.02 PING 10/17/2006 16:47:04 PAGE 1
C51 COMPILER V8.02, COMPILATION OF MODULE PING
OBJECT MODULE PLACED IN .\PING.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE ..\PING\PING.C BROWSE DEBUG OBJECTEXTEND PRINT(.\PING.lst) OBJECT(.\PING.ob
-j)
line level source
1 /*
2 ********************************************************************************
3 * Wiznet.
4 * 5F Simmtech Bldg., 228-3, Nonhyun-dong, Kangnam-gu,
5 * Seoul, Korea
6 *
7 * (c) Copyright 2002, Wiznet, Seoul, Korea
8 *
9 * Filename : PING.C
10 * Programmer(s) : Wooyoul Kim
11 * Version : 1.0
12 * Created : 2002/10/20
13 * Modified :
14 * Description : Implemation of Ping
15 To send 'ping-request' to peer & To receive 'ping-reply' from peer.
16 ********************************************************************************
17 */
18
19 /*
20 ###############################################################################
21 File Include Section
22 ###############################################################################
23 */
24 #include <reg51.h> // 8051 SFR definition file
25 #include "serial.h" // serial related functions
26 #include "util.h" // Useful function
27 #include "sockutil.h" // Util of W3100A
28 #include "ping.h" // header file
29
30 /*
31 ###############################################################################
32 Define Part
33 ###############################################################################
34 */
35
36 /*
37 ###############################################################################
38 Local Variable Declaration Section
39 ###############################################################################
40 */
41
42 /*
43 ###############################################################################
44 Function Implementation Section
45 ###############################################################################
46 */
47
48
49 /*
50 Description : Send ping-request to the specified peer and receive ping-reply from the specified peer.
51 Argument : count - Ping reqeust count.
52 If count is -1 then to send ping request to the specified peer infinitely.
53 size - Data size to be sent, The range is greater than 0 and less than 1460
54 time - wait ping reply time
C51 COMPILER V8.02 PING 10/17/2006 16:47:04 PAGE 2
55 addr - Peer Ip Address(Decimal Dotted-notation)
56 log - result of ping
57 Return Value : 1 - success, -1 - fail because free socket is not found or can't be opened.
58 Note :
59 */
60 char ping(int count, u_int size, u_int time, char* addr, PINGLOG* log)
61 {
62 1 PING xdata PingRequest; // Variable for Ping Request
63 1 PING xdata PingReply; // Variable for Ping Reply
64 1 u_long peerip; // 32 bit Peer IP Address
65 1 char tempip[4]; // ip address received from a destination
66 1 char xdata addrstr[16]; // Decimal dotted-notation IP address string
67 1 u_int xdata port; // port number received from a destination
68 1 u_int i,len;
69 1 SOCKET s = -1; // socket variable for pinging
70 1 char bLoop = 0; // Infinite = 1, finite = 0
71 1 char IsReceived = 0; // Received packet = 1, not received packet = 0
72 1 int xdata RemainTime=0; // Remained Time for waiting to ping-reply
73 1
74 1 /* Initialize PingRequest */
75 1 static u_int xdata RandomID = 0x1234; // Ping-Request ID
76 1 static u_int xdata RandomSeqNum = 0x4321; // Ping-Request packet's sequence number
77 1 PingRequest.Type = 8; // Ping-Request
78 1 PingRequest.Code = 0; // always 0
79 1 PingRequest.CheckSum = 0; // value of checksum before calucating checksum of ping-r
-equest packet
80 1 PingRequest.ID = RandomID++; // set ping-request's ID to random integer value
81 1 PingRequest.SeqNum = RandomSeqNum++; // set ping-request's sequence number to ramdom integer v
-alue
82 1 for(i = 0 ; i < 1452; i++) PingRequest.Data[i] = 'a' + i % 23; // fill 'a'~'w' characters into ping-reque
-st's data
83 1
84 1 /* Initialize result of pinging */
85 1 (*log).CheckSumErr=0; // Checksum Error
86 1 (*log).UnreachableMSG=0; // received unreachable message
87 1 (*log).TimeExceedMSG=0; // received time exceeded message
88 1 (*log).UnknownMSG = 0; // received unknown message
89 1 (*log).ARPErr=0; // fail to send arp-packet
90 1 (*log).PingRequest=0; // count of sending ping-request to the specified peer
91 1 (*log).PingReply=0; // count of receiving ping-reply from the specified peer
92 1 (*log).Loss=0; // count of occurring timeout.
93 1
94 1 /* Verify arguments */
95 1 if(count == -1) bLoop = 1; // if it is infinite
96 1 else if( count < 1 || count > 0x7FFF) count = 4; // set count to defalut value
97 1 if(size < 1 || size > 1452) size = 32; // set size to default value
98 1 if(time < 1 || time > 0x7FFF) time = 10; // set time to default value
99 1
100 1 /* Create a ping socket */
101 1 if((s = getSocket(SOCK_CLOSED,0)) == -1) return -1; // if it isn't exist free socket, Error
102 1 setIPprotocol(s,IPPROTO_ICMP); // Set upper-protocol of IP proctol
*** WARNING C206 IN LINE 102 OF ..\PING\PING.C: 'setIPprotocol': missing function-prototype
*** ERROR C267 IN LINE 102 OF ..\PING\PING.C: 'setIPprotocol': requires ANSI-style prototype
103 1 if(socket(s,SOCK_IPL_RAW,3000,0)==-1) return -1; // Open IP_RAW Mode , if fail then Error
104 1
105 1 peerip = inet_addr(addr); // convert address's string into 32bit address
106 1
107 1 PutString("\r\nPinging ");PutString(addr);PutString(" with ");PutString(ITOA(size,addrstr,10));PutStringL
-n(" bytes of data :\r\n");
108 1
109 1 /* Ping Service */
110 1 while(bLoop || count > 0) // if Infinite or count > 0, Loop
C51 COMPILER V8.02 PING 10/17/2006 16:47:04 PAGE 3
111 1 {
112 2 if(IsPressedKey()==1) // Is pressed "Ctrl-C" or "Ctrl-Break"?
113 2 if(GetByte()==0x03) bLoop=count=0;
114 2 IsReceived = 0;
115 2 count--;
116 2 RemainTime = time;
117 2 PingRequest.SeqNum++; // Increase Sequence number for next ping-request packet
118 2 PingRequest.CheckSum = 0;
119 2 PingRequest.CheckSum = checksum((u_char*)&PingRequest,size+8); // update checksum field
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -