6 static ushort PingSeqNo
;
8 static int PingSend(void)
15 /* XXX always send arp request */
17 memcpy(mac
, NetEtherNullAddr
, 6);
20 printf("sending ARP for %08lx\n", NetPingIP
);
23 NetArpWaitPacketIP
= NetPingIP
;
24 NetArpWaitPacketMAC
= mac
;
26 pkt
= NetArpWaitTxPacket
;
27 pkt
+= NetSetEther(pkt
, mac
, PROT_IP
);
32 * Construct an IP and ICMP header. (need to set no fragment bit - XXX)
34 ip
->ip_hl_v
= 0x45; /* IP_HDR_SIZE / 4 (not including UDP) */
36 ip
->ip_len
= htons(IP_HDR_SIZE_NO_UDP
+ 8);
37 ip
->ip_id
= htons(NetIPID
++);
38 ip
->ip_off
= htons(0x4000); /* No fragmentation */
40 ip
->ip_p
= 0x01; /* ICMP */
42 NetCopyIP((void*)&ip
->ip_src
, &NetOurIP
); /* already in network byte order */
43 NetCopyIP((void*)&ip
->ip_dst
, &NetPingIP
); /* - "" - */
44 ip
->ip_sum
= ~NetCksum((uchar
*)ip
, IP_HDR_SIZE_NO_UDP
/ 2);
46 s
= &ip
->udp_src
; /* XXX ICMP starts here */
47 s
[0] = htons(0x0800); /* echo-request, code */
48 s
[1] = 0; /* checksum */
49 s
[2] = 0; /* identifier */
50 s
[3] = htons(PingSeqNo
++); /* sequence number */
51 s
[1] = ~NetCksum((uchar
*)s
, 8/2);
53 /* size of the waiting packet */
54 NetArpWaitTxPacketSize
= (pkt
- NetArpWaitTxPacket
) + IP_HDR_SIZE_NO_UDP
+ 8;
56 /* and do the ARP request */
58 NetArpWaitTimerStart
= get_time_ns();
60 return 1; /* waiting */
67 NetState
= NETLOOP_FAIL
; /* we did not get the reply */
71 PingHandler (uchar
* pkt
, unsigned dest
, unsigned src
, unsigned len
)
74 IP_t
*ip
= (IP_t
*)pkt
;
76 tmp
= NetReadIP((void *)&ip
->ip_src
);
80 NetState
= NETLOOP_SUCCESS
;
85 NetSetTimeout (10 * SECOND
, PingTimeout
);
86 NetSetHandler (PingHandler
);
91 int do_ping (cmd_tbl_t
*cmdtp
, int argc
, char *argv
[])
96 if (string_to_ip(argv
[1], &NetPingIP
)) {
97 printf ("Usage:\n%s\n", cmdtp
->usage
);
101 if (NetLoop(PING
) < 0) {
102 printf("ping failed; host %s is not alive\n", argv
[1]);
106 printf("host %s is alive\n", argv
[1]);
111 U_BOOT_CMD_START(ping
)
114 .usage
= "send icmp echo_request to network host",