📄 sockutil.lst
字号:
179 3 }
180 2 }
181 1 }
182
183
184 /*
185 ********************************************************************************
186 * Description: Read established network information(G/W, IP, S/N, Mac) of W3100A and Output that through S
-erial.
187 * Arguments :
188 * Returns :
189 * Note : Mac Address is output into format of Dotted HexaDecimal.Others are output into format of D
-otted Decimal Format.
190 ********************************************************************************
191 */
192 void GetNetConfig()
193 {
194 1 char xdata str[16];
195 1 u_char xdata addr[6];
196 1 u_char i;
197 1 PutStringLn("\r\n====================================");
198 1 PutStringLn(" Net Config Information");
199 1 PutStringLn("====================================");
200 1 PutString("MAC ADDRESS : ");
201 1 for(i = 0; i < 5; i++) // HexaDecimal
202 1 {
203 2 PutHTOA(*(SRC_HA_PTR+i));
204 2 PutByte('.');
205 2 }
206 1 PutHTOA(*(SRC_HA_PTR+i));
207 1
208 1 GetSubMask(addr);
209 1 inet_ntoa(addr,str); // Dotted Decimal Format convert
210 1 PutString("\r\nSUBNET MASK : "); PutStringLn(str);
211 1
212 1 GetGWAddress(addr);
213 1 inet_ntoa(addr,str);
214 1 PutString("G/W IP ADDRESS : ");PutStringLn(str);
215 1
216 1 GetIPAddress(addr);
217 1 inet_ntoa(addr,str);
218 1 PutString("LOCAL IP ADDRESS : "); PutStringLn(str);
219 1 PutStringLn("====================================");
220 1 }
221
222
223
224 /*
225 ###############################################################################
226 Unused Function Implementation Part
227 ###############################################################################
228 */
229 #ifndef __UNUSED_SOCK_UTIL__
/*
********************************************************************************
* Output destination IP address of appropriate channel
*
* Description : Output destination IP address of appropriate channel
* Arguments : s - Channel number which try to get destination IP Address
C51 COMPILER V8.02 SOCKUTIL 10/17/2006 16:52:42 PAGE 5
* addr - Buffer address to store destination IP address
* Returns : None
* Note : API Function
* Output format is written in Hexadecimal.
********************************************************************************
*/
char* GetDestAddr(SOCKET s,u_char* addr)
{
addr[0] = *(DST_IP_PTR(s));
addr[1] = *(DST_IP_PTR(s)+1);
addr[2] = *(DST_IP_PTR(s)+2);
addr[3] = *(DST_IP_PTR(s)+3);
return addr;
}
/*
Description : Converts a string containing an (Ipv4) Internet Protocol decimal dotted address into a 32
-bit address
Argument : addr - dotted notation address string.
Return Value : 32bit address
Note :
*/
u_long inet_addr(u_char* addr)
{
char i;
char Num[4];
u_long inetaddr;
u_char * paddr = (char*)&inetaddr;
char * NextTok = addr;
for(i = 0; i < 4; i++)
{
NextTok = StrTok(NextTok,'.',Num);
*(paddr+i) = ATOI(Num,10);
}
return inetaddr;
}
/*
Description : Calculate checksum of a stream
Argument : src - pointer to stream
len - size of stream
Return Value : checksum
Note :
*/
u_int checksum(u_char * src, u_int len)
{
u_int sum, tsum, i, j;
u_long lsum;
j = len >> 1;
lsum = 0;
for (i = 0; i < j; i++)
{
tsum = src[i * 2];
tsum = tsum << 8;
tsum += src[i * 2 + 1];
lsum += tsum;
}
C51 COMPILER V8.02 SOCKUTIL 10/17/2006 16:52:42 PAGE 6
if (len % 2)
{
tsum = src[i * 2];
lsum += tsum;
}
sum = lsum;
sum = ~(sum + (lsum >> 16));
return sum;
}
/*
Description : Get handle of socket which status is same to 'status'
Argument : status - socket's status to be found
start - base of socket to be found
Return Value : socket number
Note :
*/
SOCKET getSocket(u_char status, SOCKET start)
{
SOCKET i;
if(start == -1 || start > 3) start = 0;
for(i = start; i < start + MAX_SOCK_NUM ; i++)
if(select(i%MAX_SOCK_NUM,SEL_CONTROL)==status) return i%MAX_SOCK_NUM;
return -1;
}
/*
Description : Verify decimal dotted notation IP address string
Argument : src - pointer to IP address string
Return Value : success - 1, fail - -1
Note :
*/
char VerifyIPAddress(char* src)
{
char i;
int tnum;
char Num[4];
char * NextTok = src;
for(i = 0; i < 4; i++)
{
NextTok = StrTok(NextTok,'.',Num);
if (NextTok == 0 && i != 3) return -1;
if(ValidATOI(Num,10,&tnum)==-1) return -1;
if(tnum < 0 && tnum > 255) return -1;
}
return 1;
}
#endif
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 834 ----
CONSTANT SIZE = 189 ----
XDATA SIZE = ---- 31
PDATA SIZE = ---- ----
DATA SIZE = ---- 32
IDATA SIZE = ---- ----
C51 COMPILER V8.02 SOCKUTIL 10/17/2006 16:52:42 PAGE 7
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 + -