📄 sockutil.lst
字号:
C51 COMPILER V8.02 SOCKUTIL 10/17/2006 16:52:42 PAGE 1
C51 COMPILER V8.02, COMPILATION OF MODULE SOCKUTIL
OBJECT MODULE PLACED IN SOCKUTIL.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE SOCKUTIL.C BROWSE DEBUG OBJECTEXTEND
line level source
1 /*
2 ###############################################################################
3
4 File Name : sockutil.c
5
6 Version : 1.0
7
8 Programmer(s) : Kim Woo Youl
9
10 Created : 2002/10/20
11
12 Description : Implementation of useful function of W3100A
13
14 Modified History :
15
16 Modified :
17 Programmer :
18 Description :
19
20 ###############################################################################
21 */
22
23 /*
24 ###############################################################################
25 Include Part
26 ###############################################################################
27 */
28 #include "reg51.h"
29 #include "socket.h"
30 #include "serial.h"
31 #include "util.h"
32 #include "sockutil.h"
33
34
35
36 /*
37 ###############################################################################
38 Define Part
39 ###############################################################################
40 */
41
42
43
44
45 /*
46 ###############################################################################
47 Grobal Variable Definition Part
48 ###############################################################################
49 */
50
51
52
53 /*
54 ###############################################################################
55 Local Variable Definition Part
C51 COMPILER V8.02 SOCKUTIL 10/17/2006 16:52:42 PAGE 2
56 ###############################################################################
57 */
58
59
60 /*
61 Description : Convert 32bit Address into Dotted Decimal Format
62 Argument : addr - Pointer variable to store converted value(INPUT)
63 addr_str - Character string to store Decimal Dotted Notation Format.(INPUT,OUTPUT)
64 Return Value :
65 Note :
66 */
67 void inet_ntoa(u_char* addr,char* addr_str)
68 {
69 1 char i ;
70 1 int d;
71 1
72 1 for(i = 0; i < 4; i++)
73 1 {
74 2 d = *(addr+i);
75 2 d = d & 0x00FF;
76 2 /* Convert to decimal number */
77 2 *addr_str++ = D2C(d/100);
78 2 *addr_str++ = D2C(( d / 10 )%10);
79 2 *addr_str++ = D2C(D2C(d%10));
80 2 *addr_str++ = '.';
81 2 }
82 1 *(--addr_str) = 0;
83 1 }
84
85 /*
86 Description : Get Source IP Address of W3100A.
87 Argument : addr - Pointer to store Source IP Address(32bit Address)(INPUT, OUTPUT)
88 Return Value :
89 Note :
90 */
91 void GetIPAddress(u_char* addr)
92 {
93 1 char i ;
94 1 for(i = 0; i < 4; i++)
95 1 addr[i] = *(SRC_IP_PTR+i);
96 1 }
97
98 /*
99 Description : Get Source IP Address of W3100A.
100 Argument : addr - Pointer to store Gateway IP Address(32bit Address)(INPUT, OUTPUT)
101 Return Value :
102 Note :
103 */
104 void GetGWAddress(u_char* addr)
105 {
106 1 char i ;
107 1 for(i = 0; i < 4; i++)
108 1 addr[i] = *(GATEWAY_PTR+i);
109 1 }
110
111 /*
112 Description : Get Source Subnet mask of W3100A.
113 Argument : addr - Pointer to store Subnet Mask(32bit Address)(INPUT, OUTPUT)
114 Return Value :
115 Note :
116 */
117 void GetSubMask(u_char* addr)
C51 COMPILER V8.02 SOCKUTIL 10/17/2006 16:52:42 PAGE 3
118 {
119 1 char i ;
120 1 for(i = 0; i < 4; i++)
121 1 addr[i] = *(SUBNET_MASK_PTR+i);
122 1 }
123
124 /*
125 Description : To be input Dotted Notation string from RS232C and convert 32-bit or 48bit Decimal Addres
-s
126 Argument : addr - Pointer variable to be stored Converted value (INPUT, OUTPUT)
127 base - binary,decimal,hexa-decimal (INPUT)
128 len - number of Dot Character string to be input(INPUT)
129 Return Value : Length of source string
130 Note : If converting has finished, then '1'.Else if user cancel the input or input wrong valued,
- then '-1'.
131 */
132 char GetDotNotationAddr(u_char* addr, u_int base, u_int len)
133 {
134 1 u_char xdata str[9]; // Consider the case of binary numberr
135 1 u_char i,c;
136 1 u_char j = 0;
137 1
138 1 if(base == 0x10) i = 2; // max number
139 1 else if (base == 10) i = 3;
140 1 else i = 8;
141 1
142 1 while(1)
143 1 {
144 2 c = GetByte(); // Read 1 Character
145 2 switch(c)
146 2 {
147 3 case 0x0D : // If New line
148 3 str[j++] = '\0';
149 3 *addr++ = (u_char) ATOI(str,base); // Convert to Decimal and Store
150 3 len--;
151 3 PutStringLn("");
152 3 if( len <= 0 ) return 1;
153 3 else return -1;
154 3 case '.' : // If Dot
155 3 str[j++] = '\0';
156 3 *addr++ = (u_char) ATOI(str,base);
157 3 len--;
158 3 PutByte('.');
159 3 j = 0;
160 3 break;
161 3 case 0x1B:
162 3 return -1; // Cancel
163 3 case 0x08:
164 3 if(j !=0)
165 3 {
166 4 PutByte(0x08);
167 4 PutByte(' ');
168 4 PutByte(0x08);
169 4 j--;
170 4 }
171 3 break;
172 3 default:
173 3 if( C2D(c) != c && j < i) // If Value to be input is not character and not above avaiable max input n
-umber.
174 3 {
175 4 PutByte(c); // echo.
176 4 str[j++] = c;
C51 COMPILER V8.02 SOCKUTIL 10/17/2006 16:52:42 PAGE 4
177 4 }
178 3 break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -