39 #define NETINIT_ADDR_SET(name_p) \
41 if(ip_check(DEFAULT_IP_ADDR, netinfo.ip) != RET_OK) { \
42 ERR("Default IP Addr set fail"); return RET_NOK; \
43 } else DBGA(name_p" IP Addr(%d.%d.%d.%d)", \
44 netinfo.ip[0], netinfo.ip[1], netinfo.ip[2], netinfo.ip[3]); \
45 if(ip_check(DEFAULT_SN_MASK, netinfo.sn) != RET_OK) { \
46 ERR("Default SN Mask set fail"); return RET_NOK; \
47 } else DBGA(name_p" SN Mask(%d.%d.%d.%d)", \
48 netinfo.sn[0], netinfo.sn[1], netinfo.sn[2], netinfo.sn[3]); \
49 if(ip_check(DEFAULT_GW_ADDR, netinfo.gw) != RET_OK) { \
50 ERR("Default GW Addr set fail"); return RET_NOK; \
51 } else DBGA(name_p" GW Addr(%d.%d.%d.%d)", netinfo.gw[0], \
52 netinfo.gw[1], netinfo.gw[2], netinfo.gw[3]); \
53 if(ip_check(DEFAULT_DNS_ADDR, netinfo.dns) != RET_OK) { \
54 ERR("Default DNS Addr set fail"); return RET_NOK; \
55 } else DBGA(name_p" DNS Addr(%d.%d.%d.%d)", netinfo.dns[0], \
56 netinfo.dns[1], netinfo.dns[2], netinfo.dns[3]); \
61 memset(&netinfo, 0,
sizeof(netinfo));
64 ERR(
"Default MAC Addr set fail");
66 }
else DBGA(
"Default MAC Addr(%02x:%02x:%02x:%02x:%02x:%02x)", netinfo.
mac[0],
67 netinfo.
mac[1], netinfo.
mac[2], netinfo.
mac[3], netinfo.
mac[4], netinfo.
mac[5]);
69 #if (USE_DHCP == VAL_ENABLE)
70 NETINIT_ADDR_SET(
"Default");
74 NETINIT_ADDR_SET(
"Static");
98 LOG(
"---------------------------------------");
99 LOG(
"Current Network Configuration ");
102 LOG(
"---------------------------------------");
103 LOGA(
"MAC : %02X:%02X:%02X:%02X:%02X:%02X", netinfo->
mac[0], netinfo->
mac[1],
104 netinfo->
mac[2], netinfo->
mac[3], netinfo->
mac[4], netinfo->
mac[5]);
105 LOGA(
"IP : %d.%d.%d.%d", netinfo->
ip[0], netinfo->
ip[1], netinfo->
ip[2], netinfo->
ip[3]);
106 LOGA(
"SN : %d.%d.%d.%d", netinfo->
sn[0], netinfo->
sn[1], netinfo->
sn[2], netinfo->
sn[3]);
107 LOGA(
"GW : %d.%d.%d.%d", netinfo->
gw[0], netinfo->
gw[1], netinfo->
gw[2], netinfo->
gw[3]);
108 LOGA(
"DNS : %d.%d.%d.%d", netinfo->
dns[0], netinfo->
dns[1], netinfo->
dns[2], netinfo->
dns[3]);
110 LOG(
"---------------------------------------");
126 DBGA(
"WATCH Open - sock(%d), CB(%p)", sock, (
void*)cb);
128 ERRA(
"wrong arg - sock(%d)", sock);
131 if(watch_cb[sock] == NULL) watch_cb[sock] = cb;
146 DBGA(
"WATCH Close - sock(%d)", sock);
148 ERRA(
"wrong sock(%d)", sock);
153 watch_cb[sock] = NULL;
171 DBGA(
"WATCH Set - sock(%d), item(0x%x)", sock, item);
173 ERRA(
"wrong sock(%d)", sock);
177 BITSET(watch_sock[sock], 0x7F & item);
194 DBGA(
"WATCH Clear - sock(%d), item(0x%x)", sock, item);
196 ERRA(
"wrong sock(%d)", sock);
200 BITCLR(watch_sock[sock], 0x7F & item);
227 #define WCF_HANDLE(item_v, ret_v) \
229 BITCLR(watch_sock[i], item_v); \
230 watch_cb[i](i, item_v, ret_v); \
237 if(watch_sock[i] == 0)
continue;
243 if(ret !=
SOCKERR_BUSY) WCF_HANDLE(WATCH_SOCK_CLS_EVT, ret);
247 if(ret !=
SOCKERR_BUSY) WCF_HANDLE(WATCH_SOCK_CONN_EVT, ret);
252 if(ret !=
SOCKERR_BUSY) WCF_HANDLE(WATCH_SOCK_CLS_TRY, ret);
256 if(ret !=
SOCKERR_BUSY) WCF_HANDLE(WATCH_SOCK_CONN_TRY, ret);
260 if(ret !=
SOCKERR_BUSY) WCF_HANDLE(WATCH_SOCK_TCP_SEND, ret);
264 if(ret !=
SOCKERR_BUSY) WCF_HANDLE(WATCH_SOCK_UDP_SEND, ret);
283 int8 tmp[16], *split;
284 int32 digit, sumchk = 0;
286 digit = strlen((
char*)str);
287 if(digit > 15 || digit < 7) {
291 strcpy((
char*)tmp, (
char*)str);
292 split = (int8*)strtok((
char*)tmp,
".");
294 digit = atoi((
char*)split);
295 if(digit > 255 || digit < 0)
return RET_NOK;
296 if(ip) ip[cnt] = digit;
299 split = (int8*)strtok(NULL,
".");
302 if(cnt != 4 || sumchk == 0) {
322 val = strtol((
char*)str, (
char**)&ptr, 10);
324 if(val == 0 || val > 65535 || *ptr != 0)
return RET_NOK;
325 if(port) *port = val;
341 int8 tmp[18], *split;
344 if(strlen((
char*)str) != 17) {
348 strcpy((
char*)tmp, (
char*)str);
349 split = (int8*)strtok((
char*)tmp,
":");
351 digit = strtol((
char*)split, NULL, 16);
352 if(digit > 255 || digit < 0)
return RET_NOK;
353 if(mac) mac[cnt] = digit;
355 split = (int8*)strtok(NULL,
":");
373 static int8 addr_str[16];
374 memset(addr_str,0,16);
375 sprintf((
char*)addr_str,
"%d.%d.%d.%d",(int32)(addr>>24 & 0xFF),(int32)(addr>>16 & 0xFF),(int32)(addr>>8 & 0xFF),(int32)(addr & 0xFF));
388 static int8 addr_str[16];
389 memset(addr_str,0,16);
390 sprintf((
char*)addr_str,
"%03d.%03d.%03d.%03d",(int32)(addr>>24 & 0xFF),(int32)(addr>>16 & 0xFF),(int32)(addr>>8 & 0xFF),(int32)(addr & 0xFF));
407 strcpy((
char*)taddr,(
char*)addr);
410 for(i = 0; i < 4 ; i++)
412 nexttok = (int8*)strtok((
char*)nexttok,
".");
413 if(nexttok[0] ==
'0' && nexttok[1] ==
'x') num = strtol((
char*)nexttok+2, NULL, 16);
414 else num = strtol((
char*)nexttok, NULL, 10);
415 inetaddr = inetaddr << 8;
416 inetaddr |= (num & 0xFF);
431 ret = (i & 0xFF) << 8;
432 ret |= ((i >> 8)& 0xFF);
445 ret = (l & 0xFF) << 24;
446 ret |= ((l >> 8) & 0xFF) << 16;
447 ret |= ((l >> 16) & 0xFF) << 8;
448 ret |= ((l >> 24) & 0xFF);
460 #ifdef SYSTEM_LITTLE_ENDIAN
461 return swaps(hostshort);
476 #ifdef SYSTEM_LITTLE_ENDIAN
477 return swapl(hostlong);
493 #ifdef SYSTEM_LITTLE_ENDIAN
494 return htons(netshort);
509 #ifdef SYSTEM_LITTLE_ENDIAN
510 return swapl(netlong);