示例#1
0
 int32_t MTD_FLASHMEM ICMP::ping(IPAddress const& dest)
 {       
     static uint32_t const TIMEOUT        = 4000;
     static int32_t const TIMEOUT_RESULT  = -1;
 
     uint32_t result = TIMEOUT_RESULT;
             
     // generate seq
     m_waitingSeq++;
     
     // prepare packet to send
     pbuf* hdrbuf = pbuf_alloc(PBUF_IP, sizeof(icmp_echo_hdr), PBUF_RAM);
     icmp_echo_hdr* hdr = (icmp_echo_hdr*)hdrbuf->payload;
     hdr->type   = ICMP_ECHO;
     hdr->code   = 0;
     hdr->chksum = 0;
     hdr->id     = htons(m_waitingID);
     hdr->seqno  = htons(m_waitingSeq);
     hdr->chksum = inet_chksum((uint16_t*)hdr, sizeof(icmp_echo_hdr));
     
     // send Echo request
     raw_pcb* pcb = raw_new(IP_PROTO_ICMP);
     raw_recv(pcb, ICMP::raw_recv_fn, this);
     raw_bind(pcb, IP_ADDR_ANY);            
     
     ip_addr_t addr = dest.get_ip_addr_t();
     raw_sendto(pcb, hdrbuf, &addr);
     pbuf_free(hdrbuf);
     
     uint32_t t1 = micros();
     if (m_queue.receive(TIMEOUT))
         result = (micros() - t1);
             
     raw_remove(pcb);
     
     return result;            
 }
示例#2
0
 void MTD_FLASHMEM NSLookup::setDNSServer(uint32_t num, IPAddress server)
 {
     ip_addr_t a = server.get_ip_addr_t();
     dns_setserver(num, &a);
 }