* Add 'static' before some functions and global variables.
* Remove cleanup() function.
* Remove useless comments.
* Modify the format of ptab[] and cstab[].
* Some cleanup.

Signed-off-by: Zeng Linggang <zenglg...@cn.fujitsu.com>
---
 testcases/network/lib6/asapi_04.c | 155 ++++++++++++++++----------------------
 1 file changed, 67 insertions(+), 88 deletions(-)

diff --git a/testcases/network/lib6/asapi_04.c 
b/testcases/network/lib6/asapi_04.c
index 76de26b..d7d423b 100644
--- a/testcases/network/lib6/asapi_04.c
+++ b/testcases/network/lib6/asapi_04.c
@@ -1,6 +1,6 @@
 /*
- *
  *   Copyright (c) International Business Machines  Corp., 2001
+ *     04/2005 written by David L Stevens
  *
  *   This program is free software;  you can redistribute it and/or modify
  *   it under the terms of the GNU General Public License as published by
@@ -13,26 +13,14 @@
  *   the GNU General Public License for more details.
  *
  *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
USA
+ *   along with this program;  if not, write to the Free Software Foundation,
+ *   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 /*
- * Test Name: asapi_04
- *
  * Test Description:
  *  Verify that in6 and sockaddr fields are present. Most of these are
  *  "PASS" if they just compile.
- *
- * Usage:  <for command-line>
- *  asapi_04
- *
- * HISTORY
- *     04/2005 written by David L Stevens
- *
- * RESTRICTIONS:
- *  None.
- *
  */
 
 #include <stdio.h>
@@ -51,30 +39,30 @@
 
 char *TCID = "asapi_04";       /* Test program identifier.    */
 
-pid_t pid;
+static pid_t pid;
 
-struct {
+static struct {
        char *prt_name;
        int prt_value;
 } ptab[] = {
-       {
-       "hopopt", 0}, {
-       "ipv6", 41}, {
-       "ipv6-route", 43}, {
-       "ipv6-frag", 44}, {
-       "esp", 50}, {
-       "ah", 51}, {
-       "ipv6-icmp", 58}, {
-       "ipv6-nonxt", 59}, {
-"ipv6-opts", 60},};
-
-#define PTCOUNT        (sizeof(ptab)/sizeof(ptab[0]))
+       {"hopopt", 0},
+       {"ipv6", 41},
+       {"ipv6-route", 43},
+       {"ipv6-frag", 44},
+       {"esp", 50},
+       {"ah", 51},
+       {"ipv6-icmp", 58},
+       {"ipv6-nonxt", 59},
+       {"ipv6-opts", 60},
+};
+
+#define PTCOUNT        ARRAY_SIZE(ptab)
 
 #define READ_TIMEOUT   5       /* secs */
 
-void do_tests(void);
-void setup(void), cleanup(void);
-int csum_test(char *rhost);
+static void do_tests(void);
+static void setup(void);
+static int csum_test(char *rhost);
 
 int main(int argc, char *argv[])
 {
@@ -89,14 +77,12 @@ int main(int argc, char *argv[])
        for (lc = 0; TEST_LOOPING(lc); ++lc)
                do_tests();
 
-       cleanup();
-
        tst_exit();
 }
 
-void do_tests(void)
+static void do_tests(void)
 {
-       int i;
+       unsigned int i;
 
 /* RFC 3542, Section 2.3 */
 #ifndef IN6_ARE_ADDR_EQUAL
@@ -107,27 +93,25 @@ void do_tests(void)
         * in the second address and check for equal. Covers all bits, all
         * combinations.
         */
-       {
-               struct in6_addr a1, a2;
-               int word, bit;
-               int rv = 1;
+       struct in6_addr a1, a2;
+       int word, bit;
+       int rv = 1;
 
-               memset(&a1, 0, sizeof(a1));
-               memset(&a2, 0, sizeof(a2));
+       memset(&a1, 0, sizeof(a1));
+       memset(&a2, 0, sizeof(a2));
 
-               rv = IN6_ARE_ADDR_EQUAL(&a1, &a2);
+       rv = IN6_ARE_ADDR_EQUAL(&a1, &a2);
 
-               for (word = 0; word < 4; ++word)
-                       for (bit = 0; bit < 32; ++bit) {
-                               uint32_t newbit = 1 << bit;
+       for (word = 0; word < 4; ++word)
+               for (bit = 0; bit < 32; ++bit) {
+                       uint32_t newbit = 1 << bit;
 
-                               a1.s6_addr32[word] |= newbit;   /* unequal */
-                               rv &= !IN6_ARE_ADDR_EQUAL(&a1, &a2);
-                               a2.s6_addr32[word] |= newbit;   /* equal */
-                               rv &= IN6_ARE_ADDR_EQUAL(&a1, &a2);
-                       }
-               tst_resm(rv ? TPASS : TFAIL, "IN6_ARE_ADDR_EQUAL");
-       }
+                       a1.s6_addr32[word] |= newbit;   /* unequal */
+                       rv &= !IN6_ARE_ADDR_EQUAL(&a1, &a2);
+                       a2.s6_addr32[word] |= newbit;   /* equal */
+                       rv &= IN6_ARE_ADDR_EQUAL(&a1, &a2);
+               }
+       tst_resm(rv ? TPASS : TFAIL, "IN6_ARE_ADDR_EQUAL");
 #endif /* IN6_ARE_ADDR_EQUAL */
 
 /* RFC 3542, Section 2.4 */
@@ -162,10 +146,10 @@ struct tprot {
        unsigned char tp_dat[0];        /* user data */
 };
 
-unsigned char tpbuf[sizeof(struct tprot) + 2048];
-unsigned char rpbuf[sizeof(struct tprot) + 2048];
+static unsigned char tpbuf[sizeof(struct tprot) + 2048];
+static unsigned char rpbuf[sizeof(struct tprot) + 2048];
 
-struct csent {
+static struct csent {
        int cs_offset;
        int cs_dlen;
        int cs_setresult;       /* setsockopt expected result */
@@ -173,25 +157,22 @@ struct csent {
        int cs_sndresult;       /* send expected result */
        int cs_snderrno;        /* send expected errno */
 } cstab[] = {
-       {
-       0, 5, 0, 0, 0, 0}, {
-       6, 30, 0, 0, 0, 0}, {
-       3, 20, -1, EINVAL, -1, -1},     /* non-aligned offset */
-       {
-       4, 5, 0, 0, -1, EINVAL},        /* not enough space */
-       {
-       50, 5, 0, 0, -1, EINVAL},       /* outside of packet */
-       {
-       22, 30, 0, 0, 0, 0}, {
-       2000, 2004, 0, 0, 0, 0},        /* in a fragment (over Ethernet) */
+       {0, 5, 0, 0, 0, 0},
+       {6, 30, 0, 0, 0, 0},
+       {3, 20, -1, EINVAL, -1, -1},    /* non-aligned offset */
+       {4, 5, 0, 0, -1, EINVAL},       /* not enough space */
+       {50, 5, 0, 0, -1, EINVAL},      /* outside of packet */
+       {22, 30, 0, 0, 0, 0},
+       {2000, 2004, 0, 0, 0, 0},       /* in a fragment (over Ethernet) */
 };
 
-#define CSCOUNT        (sizeof(cstab)/sizeof(cstab[0]))
+#define CSCOUNT        ARRAY_SIZE(cstab)
 
-static int recvtprot(int sd, unsigned char *packet, int psize)
+static int recvtprot(int sd, unsigned char *packet)
 {
        struct tprot *tpt;
-       int cc, total, expected;
+       int cc;
+       unsigned int total, expected;
        int gothead;
 
        tpt = (struct tprot *)packet;
@@ -218,7 +199,8 @@ static int recvtprot(int sd, unsigned char *packet, int 
psize)
        return total;
 }
 
-unsigned short csum(unsigned short partial, unsigned char *packet, int len)
+static unsigned short csum(unsigned short partial, unsigned char *packet,
+                          int len)
 {
        unsigned long sum = partial;
        unsigned short *ps;
@@ -234,7 +216,7 @@ unsigned short csum(unsigned short partial, unsigned char 
*packet, int len)
        return ~sum;
 }
 
-struct ph {
+static struct ph {
        struct in6_addr ph_sa;
        struct in6_addr ph_da;
        uint32_t ph_len;
@@ -242,13 +224,14 @@ struct ph {
        uint8_t ph_nh;
 } ph;
 
-static int client(int prot, int sfd)
+static int client(int sfd)
 {
        struct tprot *pttp = (struct tprot *)tpbuf;
        struct tprot *prtp = (struct tprot *)rpbuf;
        struct sockaddr_in6 rsin6;
        static int seq;
-       int i, sd, cc, cs;
+       unsigned int i;
+       int sd, cc, cs;
 
        memset(&rsin6, 0, sizeof(rsin6));
        rsin6.sin6_family = AF_INET6;
@@ -322,9 +305,9 @@ static int client(int prot, int sfd)
                                 offset, len);
                        continue;
                }
-               while ((cc = recvtprot(sfd, rpbuf, sizeof(rpbuf)))) {
-                       if (htonl(prtp->tp_pid) == pid &&
-                           htonl(prtp->tp_seq) == seq)
+               while ((cc = recvtprot(sfd, rpbuf))) {
+                       if (htonl(prtp->tp_pid) == (uint32_t)pid &&
+                           htonl(prtp->tp_seq) == (uint32_t)seq)
                                break;
                }
                rv = 1;
@@ -334,7 +317,7 @@ static int client(int prot, int sfd)
                                continue;
                        if (*p != 0xa5) {
                                tst_resm(TFAIL, "IPV6_CHECKSUM corrupt data "
-                                        "0x%02x != 0xa5 at offset %d in 
packet",
+                                        "0x%02x != 0xa5 at offset %zd in 
packet",
                                         *p, p - rpbuf);
                                rv = 0;
                                break;
@@ -358,7 +341,7 @@ static int client(int prot, int sfd)
 static int listen_fd, connect_fd;
 sem_t ilsem;
 
-void *ilistener(void *arg)
+static void *ilistener(void *arg __attribute__ ((unused)))
 {
        connect_fd = accept(listen_fd, 0, 0);
        close(listen_fd);
@@ -366,7 +349,7 @@ void *ilistener(void *arg)
        return NULL;
 }
 
-int isocketpair(int pf, int type, int proto, int fd[2])
+static int isocketpair(int pf, int type, int proto, int fd[2])
 {
        pthread_t thid;
        struct sockaddr_in sin4;
@@ -419,10 +402,10 @@ int isocketpair(int pf, int type, int proto, int fd[2])
 }
 
 #ifndef MAX
-#define MAX(a, b) ((a) >= (b) ? (a) : (b))
+# define MAX(a, b) ((a) >= (b) ? (a) : (b))
 #endif /* MAX */
 
-int csum_test(char *rhost)
+static int csum_test(char *rhost)
 {
        fd_set rset, rset_save;
        int csd[2];             /* control sockets */
@@ -466,7 +449,7 @@ int csum_test(char *rhost)
        default:                /* parent */
                close(sd);
                close(csd[1]);
-               return client(pid, csd[0]);
+               return client(csd[0]);
        }
 
        tv.tv_sec = READ_TIMEOUT;
@@ -515,13 +498,9 @@ int csum_test(char *rhost)
        return 0;
 }
 
-void setup(void)
+static void setup(void)
 {
        TEST_PAUSE;             /* if -P option specified */
 }
 
-void cleanup(void)
-{
-}
-
 int TST_TOTAL = PTCOUNT + CSCOUNT;
-- 
1.9.3


------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to