You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gn...@apache.org on 2020/02/26 13:48:58 UTC

[incubator-nuttx-apps] branch master updated: examples/ipforward: IP Header issue for IPv4 fixed

This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git


The following commit(s) were added to refs/heads/master by this push:
     new ae36b6f  examples/ipforward:  IP Header issue for IPv4 fixed
ae36b6f is described below

commit ae36b6f8a91922ac44f244f939fbbb769daac774
Author: Bhindhiya <56...@users.noreply.github.com>
AuthorDate: Wed Feb 26 11:27:37 2020 +0530

    examples/ipforward:  IP Header issue for IPv4 fixed
    
    Also run modified .c file through tools/nxstyle
---
 examples/ipforward/ipforward.c | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/examples/ipforward/ipforward.c b/examples/ipforward/ipforward.c
index 8baf89a..66875a1 100644
--- a/examples/ipforward/ipforward.c
+++ b/examples/ipforward/ipforward.c
@@ -116,6 +116,7 @@ struct ipfwd_arg_s
 /****************************************************************************
  * Private Data
  ****************************************************************************/
+
 /* Network addresses:
  *
  * g_tun0_laddr is the address assigned to the tun0 device.  g_tun1_laddr
@@ -375,7 +376,8 @@ static uint16_t common_chksum(FAR uint8_t *buffer, uint8_t proto)
 
   /* Sum IP source and destination addresses. */
 
-  sum = chksum(sum, (FAR uint8_t *)&ipv6->srcipaddr, 2 * sizeof(net_ipv6addr_t));
+  sum = chksum(sum, (FAR uint8_t *)&ipv6->srcipaddr,
+               2 * sizeof(net_ipv6addr_t));
 
   /* Sum IP payload data. */
 
@@ -394,6 +396,7 @@ static uint16_t common_chksum(FAR uint8_t *buffer, uint8_t proto)
   upperlen = (((uint16_t)(ipv4->len[0]) << 8) + ipv4->len[1]) - IPv4_HDRLEN;
 
   /* First sum pseudo-header. */
+
   /* IP protocol and length fields. This addition cannot carry. */
 
   sum = upperlen + proto;
@@ -474,7 +477,7 @@ static void ipfwd_dumpbuffer(FAR uint8_t *buffer, size_t buflen)
         }
 
       putchar('\n');
-   }
+    }
 }
 
 static void ipfwd_dumppkt(FAR uint8_t *buffer, size_t buflen)
@@ -559,7 +562,8 @@ static FAR void *ipfwd_receiver(FAR void *arg)
           break;
         }
 
-      printf("Received packet %d: size=%lu\n", i+1, (unsigned long)nread);
+      printf("Received packet %d: size=%lu\n",
+             i + 1, (unsigned long)nread);
       ipfwd_dumppkt(fwd->ia_buffer, nread);
     }
 
@@ -673,8 +677,8 @@ static FAR void *ipfwd_sender(FAR void *arg)
       ipv4->ttl         = IP_TTL;
       ipv4->proto       = proto;
 
-      net_ipv4addr_hdrcopy(ipv4->srcipaddr,  fwd->ia_srcipaddr);
-      net_ipv4addr_hdrcopy(ipv4->destipaddr, fwd->ia_destipaddr);
+      net_ipv4addr_hdrcopy(ipv4->srcipaddr,  &fwd->ia_srcipaddr);
+      net_ipv4addr_hdrcopy(ipv4->destipaddr, &fwd->ia_destipaddr);
 
       /* Calculate IP checksum. */
 
@@ -735,7 +739,8 @@ static FAR void *ipfwd_sender(FAR void *arg)
       sol->chksum   = ~icmpv6_chksum(fwd->ia_buffer);
 #endif
 
-      printf("Sending packet %d: size=%lu\n", i+1, (unsigned long)pktlen);
+      printf("Sending packet %d: size=%lu\n",
+             i + 1, (unsigned long)pktlen);
       ipfwd_dumppkt(fwd->ia_buffer, pktlen);
 
       nwritten = write(fwd->ia_fd, fwd->ia_buffer, pktlen);
@@ -811,7 +816,8 @@ int main(int argc, FAR char *argv[])
   ret = pthread_create(&fwd.if_receiver, NULL, ipfwd_receiver, &tun1arg);
   if (ret != 0)
     {
-      fprintf(stderr, "ERROR: pthread_create() failed for receiver: %d\n", ret);
+      fprintf(stderr, "ERROR: pthread_create() failed for receiver: %d\n",
+              ret);
       errcode = EXIT_FAILURE;
       goto errout_with_tun1;
     }
@@ -825,7 +831,8 @@ int main(int argc, FAR char *argv[])
   ret = pthread_create(&fwd.if_sender, NULL, ipfwd_sender, &tun0arg);
   if (ret != 0)
     {
-      fprintf(stderr, "ERROR: pthread_create() failed for sender: %d\n", ret);
+      fprintf(stderr, "ERROR: pthread_create() failed for sender: %d\n",
+              ret);
       errcode = EXIT_FAILURE;
       goto errout_with_receiver;
     }
@@ -835,17 +842,20 @@ int main(int argc, FAR char *argv[])
   ret = pthread_join(fwd.if_sender, &value);
   if (ret != OK)
     {
-      fprintf(stderr, "ERROR: pthread_join() failed for sender: %d\n", ret);
+      fprintf(stderr, "ERROR: pthread_join() failed for sender: %d\n",
+              ret);
     }
 
 errout_with_receiver:
+
   /* Wait for receiver thread to terminate */
 
   pthread_kill(fwd.if_receiver, 9);
   ret = pthread_join(fwd.if_receiver, &value);
   if (ret != OK)
     {
-      fprintf(stderr, "ERROR: pthread_join() failed for receiver: %d\n", ret);
+      fprintf(stderr, "ERROR: pthread_join() failed for receiver: %d\n",
+              ret);
     }
 
 errout_with_tun1: