aboutsummaryrefslogtreecommitdiff
path: root/nuttx/net/uip/uip_icmpping.c
diff options
context:
space:
mode:
Diffstat (limited to 'nuttx/net/uip/uip_icmpping.c')
-rw-r--r--nuttx/net/uip/uip_icmpping.c157
1 files changed, 82 insertions, 75 deletions
diff --git a/nuttx/net/uip/uip_icmpping.c b/nuttx/net/uip/uip_icmpping.c
index 356187d09..e3ebf7252 100644
--- a/nuttx/net/uip/uip_icmpping.c
+++ b/nuttx/net/uip/uip_icmpping.c
@@ -148,122 +148,129 @@ static inline int ping_timeout(struct icmp_ping_s *pstate)
****************************************************************************/
static uint16_t ping_interrupt(struct uip_driver_s *dev, void *conn,
- void *pvpriv, uint16_t flags)
+ void *pvpriv, uint16_t flags)
{
struct icmp_ping_s *pstate = (struct icmp_ping_s *)pvpriv;
uint8_t *ptr;
- int failcode = -ETIMEDOUT;
int i;
nllvdbg("flags: %04x\n", flags);
if (pstate)
{
- /* Check if this device is on the same network as the destination device. */
-
- if (!uip_ipaddr_maskcmp(pstate->png_addr, dev->d_ipaddr, dev->d_netmask))
- {
- /* Destination address was not on the local network served by this
- * device. If a timeout occurs, then the most likely reason is
- * that the destination address is not reachable.
- */
+ /* Check if this is a ICMP ECHO reply. If so, return the sequence
+ * number to the caller. NOTE: We may not even have sent the
+ * requested ECHO request; this could have been the delayed ECHO
+ * response from a previous ping.
+ */
- nllvdbg("Not reachable\n");
- failcode = -ENETUNREACH;
- }
- else
+ if ((flags & UIP_ECHOREPLY) != 0 && conn != NULL)
{
- /* Check if this is a ICMP ECHO reply. If so, return the sequence
- * number to the caller. NOTE: We may not even have sent the
- * requested ECHO request; this could have been the delayed ECHO
- * response from a previous ping.
- */
+ struct uip_icmpip_hdr *icmp = (struct uip_icmpip_hdr *)conn;
+ nlldbg("ECHO reply: id=%d seqno=%d\n",
+ ntohs(icmp->id), ntohs(icmp->seqno));
- if ((flags & UIP_ECHOREPLY) != 0 && conn != NULL)
+ if (ntohs(icmp->id) == pstate->png_id)
{
- struct uip_icmpip_hdr *icmp = (struct uip_icmpip_hdr *)conn;
- nlldbg("ECHO reply: id=%d seqno=%d\n", ntohs(icmp->id), ntohs(icmp->seqno));
+ /* Consume the ECHOREPLY */
- if (ntohs(icmp->id) == pstate->png_id)
- {
- /* Consume the ECHOREPLY */
+ flags &= ~UIP_ECHOREPLY;
+ dev->d_len = 0;
- flags &= ~UIP_ECHOREPLY;
- dev->d_len = 0;
+ /* Return the result to the caller */
- /* Return the result to the caller */
-
- pstate->png_result = OK;
- pstate->png_seqno = ntohs(icmp->seqno);
- goto end_wait;
- }
+ pstate->png_result = OK;
+ pstate->png_seqno = ntohs(icmp->seqno);
+ goto end_wait;
}
+ }
- /* Check:
- * If the outgoing packet is available (it may have been claimed
- * by a sendto interrupt serving a different thread
- * -OR-
- * If the output buffer currently contains unprocessed incoming
- * data.
- * -OR-
- * If we have alread sent the ECHO request
- *
- * In the first two cases, we will just have to wait for the next
- * polling cycle.
- */
+ /* Check:
+ * If the outgoing packet is available (it may have been claimed
+ * by a sendto interrupt serving a different thread)
+ * -OR-
+ * If the output buffer currently contains unprocessed incoming
+ * data.
+ * -OR-
+ * If we have alread sent the ECHO request
+ *
+ * In the first two cases, we will just have to wait for the next
+ * polling cycle.
+ */
- if (dev->d_sndlen <= 0 && /* Packet available */
- (flags & UIP_NEWDATA) == 0 && /* No incoming data */
- !pstate->png_sent) /* Request not sent */
- {
- struct uip_icmpip_hdr *picmp = ICMPBUF;
+ if (dev->d_sndlen <= 0 && /* Packet available */
+ (flags & UIP_NEWDATA) == 0 && /* No incoming data */
+ !pstate->png_sent) /* Request not sent */
+ {
+ struct uip_icmpip_hdr *picmp = ICMPBUF;
- /* We can send the ECHO request now.
- *
- * Format the ICMP ECHO request packet
- */
+ /* We can send the ECHO request now.
+ *
+ * Format the ICMP ECHO request packet
+ */
- picmp->type = ICMP_ECHO_REQUEST;
- picmp->icode = 0;
+ picmp->type = ICMP_ECHO_REQUEST;
+ picmp->icode = 0;
#ifndef CONFIG_NET_IPv6
- picmp->id = htons(pstate->png_id);
- picmp->seqno = htons(pstate->png_seqno);
+ picmp->id = htons(pstate->png_id);
+ picmp->seqno = htons(pstate->png_seqno);
#else
# error "IPv6 ECHO Request not implemented"
#endif
- /* Add some easily verifiable data */
+ /* Add some easily verifiable data */
- for (i = 0, ptr = ICMPDAT; i < pstate->png_datlen; i++)
- {
- *ptr++ = i;
- }
+ for (i = 0, ptr = ICMPDAT; i < pstate->png_datlen; i++)
+ {
+ *ptr++ = i;
+ }
- /* Send the ICMP echo request. Note that d_sndlen is set to
- * the size of the ICMP payload and does not include the size
- * of the ICMP header.
- */
+ /* Send the ICMP echo request. Note that d_sndlen is set to
+ * the size of the ICMP payload and does not include the size
+ * of the ICMP header.
+ */
- nlldbg("Send ECHO request: seqno=%d\n", pstate->png_seqno);
+ nlldbg("Send ECHO request: seqno=%d\n", pstate->png_seqno);
- dev->d_sndlen = pstate->png_datlen + 4;
- uip_icmpsend(dev, &pstate->png_addr);
- pstate->png_sent = true;
- return flags;
- }
+ dev->d_sndlen = pstate->png_datlen + 4;
+ uip_icmpsend(dev, &pstate->png_addr);
+ pstate->png_sent = true;
+ return flags;
}
/* Check if the selected timeout has elapsed */
if (ping_timeout(pstate))
{
- /* Yes.. report the timeout */
+ int failcode;
+
+ /* Check if this device is on the same network as the destination
+ * device.
+ */
+
+ if (!uip_ipaddr_maskcmp(pstate->png_addr, dev->d_ipaddr, dev->d_netmask))
+ {
+ /* Destination address was not on the local network served by this
+ * device. If a timeout occurs, then the most likely reason is
+ * that the destination address is not reachable.
+ */
+
+ nlldbg("Not reachable\n");
+ failcode = -ENETUNREACH;
+ }
+ else
+ {
+ nlldbg("Ping timeout\n");
+ failcode = -ETIMEDOUT;
+ }
+
+ /* Report the failure */
- nlldbg("Ping timeout\n");
pstate->png_result = failcode;
goto end_wait;
}
/* Continue waiting */
}
+
return flags;
end_wait: