static void ping_thread(void *arg) { int s; int timeout = PING_RCV_TIMEO; ip_addr_t ping_target; LWIP_UNUSED_ARG(arg); if ((s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP)) < 0) { return; } lwip_setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)); while (1) { ping_target = PING_TARGET; if (ping_send(s, &ping_target) == ERR_OK) { LWIP_DEBUGF( PING_DEBUG, ("ping: send ")); ip_addr_debug_print(PING_DEBUG, &ping_target); LWIP_DEBUGF( PING_DEBUG, ("\n")); ping_time = sys_now(); ping_recv(s); } else { LWIP_DEBUGF( PING_DEBUG, ("ping: send ")); ip_addr_debug_print(PING_DEBUG, &ping_target); LWIP_DEBUGF( PING_DEBUG, (" - error\n")); } sys_msleep(PING_DELAY); } }
//Entry point of ping application. void ping_Entry(void *arg) { int s; int timeout = PING_RCV_TIMEO; __PING_PARAM* pParam = (__PING_PARAM*)arg; ping_pkt_seq = 0; //Reset ping sequence number. ping_succ = 0; if((s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP)) < 0) { PrintLine(" ping : Create raw socket failed,quit."); return; } lwip_setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)); _hx_printf("\r\n Ping %s with %d bytes packet:\r\n",inet_ntoa(pParam->targetAddr),pParam->size); while (1) { //ping_target = PING_TARGET; //ping gw //IP4_ADDR(&ping_target, 127,0,0,1); //ping loopback. if (ping_send(s, &pParam->targetAddr,pParam->size) == ERR_OK) { //printf(" ping_Entry : Send out packet,addr = %s,size = %d\r\n",inet_ntoa(pParam->targetAddr),pParam->size); ping_time = sys_now(); ping_recv(s); ping_pkt_seq ++; } else { PrintLine(" ping : Send out packet failed."); } //sys_msleep(PING_DELAY); //Try the specified times. pParam->count --; if(0 == pParam->count) { break; } } //Show ping statistics. _hx_printf("\r\n"); _hx_printf(" ping statistics: total send = %d,received = %d,%d loss.\r\n", ping_pkt_seq,ping_succ,(ping_pkt_seq - ping_succ)); //Close socket. lwip_close(s); }
static void ping_thread(void *arg) { int s; LWIP_UNUSED_ARG(arg); if ((s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP)) < 0) { return; } while (1) { printf("sending ping\n"); ping_send(s,&ping_addr); ping_recv(s,&ping_addr); sleep(1); } }
static void ping_thread(void *arg) { int s; struct ip_addr dest_addr; if ((s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP)) < 0) { return; } IP4_ADDR(&dest_addr,192,168,2,1); while (1) { printf("sending ping\n"); ping_send(s,&dest_addr); ping_recv(s,&dest_addr); sleep(1); } }
static void ping_host_thread(void *arg) { int s,i=0; int timeout = PING_RCV_TIMEO; ip_addr_t ping_target; char *host = (char *)arg; //LWIP_UNUSED_ARG(arg); if ((s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP)) < 0) { return; } lwip_setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)); while (1) { //ping_target = PING_TARGET; if (i>4) break; i++; (ip4_addr_set_u32(&ping_target, ipaddr_addr(host))); if (ping_send(s, &ping_target) == ERR_OK) { //LWIP_DEBUGF( PING_DEBUG, ("ping: send ")); //ip_addr_debug_print(PING_DEBUG, &ping_target); //LWIP_DEBUGF( PING_DEBUG, ("\n")); rt_kprintf("ping: send "); ip_addr_debug_print1(&ping_target); rt_kprintf("\n"); ping_time = sys_now(); ping_recv(s); } else { //LWIP_DEBUGF( PING_DEBUG, ("ping: send ")); //ip_addr_debug_print(PING_DEBUG, &ping_target); //LWIP_DEBUGF( PING_DEBUG, (" - error\n")); rt_kprintf("ping: send "); ip_addr_debug_print1(&ping_target); rt_kprintf(" - error\n"); } sys_msleep(PING_DELAY); } }
static void ping_host(char * host) { int s,i=0; int timeout = PING_RCV_TIMEO; ip_addr_t ping_target; if ((s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP)) < 0) { return; } lwip_setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)); while (1) { if (i>4) break; i++; //ping_target = netif_default->gw; //IP4_ADDR(&ping_target,210,82,5,1); (ip4_addr_set_u32(&ping_target, ipaddr_addr(host))); if (ping_send(s, &ping_target) == ERR_OK) { //LWIP_DEBUGF( PING_DEBUG, ("ping: send ")); rt_kprintf("ping: send "); ip_addr_debug_print1(&ping_target); rt_kprintf("\n"); ping_time = sys_now(); ping_recv(s); } else { //LWIP_DEBUGF( PING_DEBUG, ("ping: send ")); rt_kprintf("ping: send "); ip_addr_debug_print1(&ping_target); rt_kprintf(" - error\n"); //LWIP_DEBUGF( PING_DEBUG, (" - error\n")); } sys_msleep(PING_DELAY); } }
static int ping_run (PING * ping, int (*finish) ()) { fd_set fdset; int fdmax; struct timeval resp_time; struct timeval last, intvl, now; struct timeval *t = NULL; int finishing = 0; int nresp = 0; int i; signal (SIGINT, sig_int); fdmax = ping->ping_fd + 1; for (i = 0; i < preload; i++) send_echo (ping); if (options & OPT_FLOOD) { intvl.tv_sec = 0; intvl.tv_usec = 10000; } else PING_SET_INTERVAL (intvl, ping->ping_interval); gettimeofday (&last, NULL); send_echo (ping); while (!stop) { int n; FD_ZERO (&fdset); FD_SET (ping->ping_fd, &fdset); gettimeofday (&now, NULL); resp_time.tv_sec = last.tv_sec + intvl.tv_sec - now.tv_sec; resp_time.tv_usec = last.tv_usec + intvl.tv_usec - now.tv_usec; while (resp_time.tv_usec < 0) { resp_time.tv_usec += 1000000; resp_time.tv_sec--; } while (resp_time.tv_usec >= 1000000) { resp_time.tv_usec -= 1000000; resp_time.tv_sec++; } if (resp_time.tv_sec < 0) resp_time.tv_sec = resp_time.tv_usec = 0; n = select (fdmax, &fdset, NULL, NULL, &resp_time); if (n < 0) { if (errno != EINTR) perror ("select"); continue; } else if (n == 1) { if (ping_recv (ping) == 0) nresp++; if (t == 0) { gettimeofday (&now, NULL); t = &now; } if (ping_timeout_p (&ping->ping_start_time, timeout)) break; if (ping->ping_count && nresp >= ping->ping_count) break; } else { if (!ping->ping_count || ping->ping_num_xmit < ping->ping_count) { send_echo (ping); if (!(options & OPT_QUIET) && options & OPT_FLOOD) { putchar ('.'); } if (ping_timeout_p (&ping->ping_start_time, timeout)) break; } else if (finishing) break; else { finishing = 1; intvl.tv_sec = MAXWAIT; } gettimeofday (&last, NULL); } } ping_unset_data (ping); if (finish) return (*finish) (); return 0; }