Statistics: Posted by Bentjudges — Mon Oct 09, 2017 11:58 pm
Statistics: Posted by davydnorris — Sat Aug 12, 2017 12:03 pm
Statistics: Posted by ESP_Faye — Mon Aug 07, 2017 2:08 pm
Statistics: Posted by moonyuan — Mon Jun 26, 2017 11:04 am
Code:
lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP)
Code:
static ip_addr_t ping_target;
IP4_ADDR(&ping_target,8,8,8,8);
Code:
861,385 @"511 - SENDING PING TO GOOGLE - H"
861,385 @"eap: 15752\n"
861,385 @"(ping_send) 158558927 - ALLOCATI"
861,385 @"NG PBUF SIZE: 40 - HEAP: 15752\n"
861,463 @"(ping_recv) 158657362 - Ping: re"
861,470 @"cv 90 id: 4368 seq_num: 4882 - H"
861,472 @"eap: 15528\n"
876,863 @"(network_controller_task) 174055"
876,884 @"435 - SENDING PING TO GOOGLE - H"
876,887 @"eap: 15592\n"
876,887 @"(ping_send) 174058845 - ALLOCATI"
876,888 @"NG PBUF SIZE: 40 - HEAP: 15592\n"
877,088 @"(ping_recv) 174281913 - Ping: re"
877,094 @"cv 210 id: 4368 seq_num: 4882 - "
877,097 @"Heap: 15368\n"
892,374 @"(network_controller_task) 189555"
892,374 @"424 - SENDING PING TO GOOGLE - H"
892,375 @"eap: 15432\n"
892,376 @"(ping_send) 189558839 - ALLOCATI"
892,381 @"NG PBUF SIZE: 40 - HEAP: 15432\n"
892,518 @"(ping_recv) 189712773 - Ping: re"
892,525 @"cv 140 id: 4368 seq_num: 4882 - "
892,527 @"Heap: 15208\n"
907,882 @"(network_controller_task) 205055"
907,882 @"421 - SENDING PING TO GOOGLE - H"
907,882 @"eap: 15240\n"
907,882 @"(ping_send) 205060480 - ALLOCATI"
907,882 @"NG PBUF SIZE: 40 - HEAP: 15240\n"
907,963 @"(ping_recv) 205157158 - Ping: re"
907,969 @"cv 90 id: 4368 seq_num: 4882 - H"
907,971 @"eap: 15016\n"
923,387 @"(network_controller_task) 220555"
923,387 @"424 - SENDING PING TO GOOGLE - H"
923,387 @"eap: 15080\n"
923,387 @"(ping_send) 220558839 - ALLOCATI"
923,387 @"NG PBUF SIZE: 40 - HEAP: 15080\n"
923,471 @"(ping_recv) 220656648 - Ping: re"
923,472 @"cv 90 id: 4368 seq_num: 4882 - H"
923,472 @"eap: 14856\n"
Statistics: Posted by gustavomassa — Tue Jun 20, 2017 2:47 pm
Statistics: Posted by gustavomassa — Wed Jun 14, 2017 8:00 am
Statistics: Posted by ememberus — Tue Jun 13, 2017 8:12 pm
Statistics: Posted by donghengqaz — Tue Jun 13, 2017 11:47 am
Code:
#define SOCKET_HOST ( ( const char * ) "google.com" )
#define SOCKET_PORT ( ( uint8 ) 80 )
static int socket_fd = -1;
static bool internetStatus = false;
LOCAL bool host2addr(const char *hostname , struct in_addr *in) {
struct addrinfo hints, *servinfo, *p;
struct sockaddr_in *h;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
if (lwip_getaddrinfo(hostname, 0 , &hints , &servinfo) != 0)
{
return false;
}
//loop through all the results and get the first resolve
for (p = servinfo; p != 0; p = p->ai_next)
{
h = (struct sockaddr_in *)p->ai_addr;
in->s_addr = h->sin_addr.s_addr;
}
lwip_freeaddrinfo(servinfo);
return true;
}
LOCAL bool openGoogleSocket() {
//create lwip TCP socket
socket_fd = lwip_socket(AF_INET, SOCK_STREAM, 0);
if( socket_fd != 0 )
{
IOT_ERROR("lwip_socket failed");
lwip_close(socket_fd);
internetStatus = false;
return false;
}
//set socket force close
lwip_force_close_set(1);
//set TCP socket keepAlive
uint32 opt = 0;
opt = 1;
if(lwip_setsockopt(socket_fd, SOL_SOCKET, SO_KEEPALIVE, &opt, sizeof(opt)) != 0) {
IOT_ERROR("lwip_setsockop SO_KEEPALIVE failed");
lwip_close(socket_fd);
internetStatus = false;
return false;
}
//set socket timeout
opt = 10000;
if(lwip_setsockopt(socket_fd, SOL_SOCKET, SO_RCVTIMEO, &opt, sizeof(opt)) != 0) {
IOT_ERROR("lwip_setsockop SO_RCVTIMEO failed");
lwip_close(socket_fd);
internetStatus = false;
return false;
}
//try to connect to google.com:80
struct sockaddr_in addr;
if (!host2addr(SOCKET_HOST, &(addr.sin_addr)))
{
IOT_ERROR("Invalid SOCKET_HOST: %s", SOCKET_HOST);
lwip_close(socket_fd);
internetStatus = false;
return false;
}
addr.sin_family = AF_INET;
addr.sin_port = htons(SOCKET_PORT);
if( lwip_connect(socket_fd, (struct sockaddr*)&addr, sizeof(addr)) != 0 )
{
IOT_ERROR("lwip_connect failed");
lwip_close(socket_fd);
internetStatus = false;
return false;
}
internetStatus = true;
return true;
}
LOCAL void closeGoogleSocket() {
lwip_force_close_set(1);
lwip_close(socket_fd);
}
bool isInternetConnected() {
if(!physicalStatus) {
internetStatus = false;
return false;
}
int error = 0;
socklen_t len = sizeof (error);
int retval = lwip_getsockopt (socket_fd, SOL_SOCKET, SO_ERROR, &error, &len);
if (retval != 0) {
/* there was a problem getting the error code */
IOT_ERROR("lwip_getsockopt SO_ERROR failed");
internetStatus = false;
return false;
}
if (error != 0) {
/* socket has a non zero error status */
IOT_ERROR("%d", error);
internetStatus = false;
return false;
}
/* write p */
if(lwip_write(socket_fd, "p", 1) != 1) {
internetStatus = false;
return false;
}
internetStatus = true;
return true;
}
Statistics: Posted by gustavomassa — Wed May 24, 2017 7:48 am