* Add 'static' before some functions and global variables. * Remove cleanup() function. * Remove useless comments. * Modify the format of sotab[] and cmtab[]. * Modify the initialization of sotab[]. * Some cleanup.
Signed-off-by: Zeng Linggang <zenglg...@cn.fujitsu.com> --- testcases/network/lib6/asapi_06.c | 214 ++++++++++++++------------------------ 1 file changed, 80 insertions(+), 134 deletions(-) diff --git a/testcases/network/lib6/asapi_06.c b/testcases/network/lib6/asapi_06.c index 960ebb5..54c1dc7 100644 --- a/testcases/network/lib6/asapi_06.c +++ b/testcases/network/lib6/asapi_06.c @@ -1,6 +1,6 @@ /* - * * Copyright (c) International Business Machines Corp., 2001 + * 05/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,25 +13,13 @@ * 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_06 - * * Test Description: * Tests for RFC 3542 section 4 socket options and ancillary data - * - * Usage: <for command-line> - * asapi_06 - * - * HISTORY - * 05/2005 written by David L Stevens - * - * RESTRICTIONS: - * None. - * */ #include "config.h" @@ -58,24 +46,16 @@ #include "test.h" -char *TCID = "asapi_06"; /* Test program identifier. */ +char *TCID = "asapi_06"; int TST_TOTAL = 1; -pid_t pid; - -struct { - char *prt_name; - int prt_value; -} ptab[] = { -}; - -#define PTCOUNT (sizeof(ptab)/sizeof(ptab[0])) +static pid_t pid; #define READ_TIMEOUT 5 /* secs */ -void do_tests(void); -void setup(void), cleanup(void); +static void do_tests(void); +static void setup(void); int main(int argc, char *argv[]) { @@ -90,47 +70,46 @@ int main(int argc, char *argv[]) for (lc = 0; TEST_LOOPING(lc); ++lc) do_tests(); - cleanup(); tst_exit(); } #define NH_TEST 0x9f #ifndef IPV6_RECVPKTINFO -#define IPV6_RECVPKTINFO -1 +# define IPV6_RECVPKTINFO -1 #endif #ifndef IPV6_RECVHOPLIMIT -#define IPV6_RECVHOPLIMIT -1 +# define IPV6_RECVHOPLIMIT -1 #endif #ifndef IPV6_RECVRTHDR -#define IPV6_RECVRTHDR -1 +# define IPV6_RECVRTHDR -1 #endif #ifndef IPV6_RECVHOPOPTS -#define IPV6_RECVHOPOPTS -1 +# define IPV6_RECVHOPOPTS -1 #endif #ifndef IPV6_RECVDSTOPTS -#define IPV6_RECVDSTOPTS -1 +# define IPV6_RECVDSTOPTS -1 #endif #ifndef IPV6_RECVTCLASS -#define IPV6_RECVTCLASS -1 +# define IPV6_RECVTCLASS -1 #endif #ifndef IPV6_TCLASS -#define IPV6_TCLASS -1 +# define IPV6_TCLASS -1 #endif #ifndef IPV6_2292PKTINFO -#define IPV6_2292PKTINFO -1 +# define IPV6_2292PKTINFO -1 #endif #ifndef IPV6_2292HOPLIMIT -#define IPV6_2292HOPLIMIT -1 +# define IPV6_2292HOPLIMIT -1 #endif #ifndef IPV6_2292RTHDR -#define IPV6_2292RTHDR -1 +# define IPV6_2292RTHDR -1 #endif #ifndef IPV6_2292HOPOPTS -#define IPV6_2292HOPOPTS -1 +# define IPV6_2292HOPOPTS -1 #endif #ifndef IPV6_2292DSTOPTS -#define IPV6_2292DSTOPTS -1 +# define IPV6_2292DSTOPTS -1 #endif union soval { @@ -150,7 +129,7 @@ union soval { #define IN6_ANY {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } /* so_clrval and so_setval members are initilized in the body */ -struct soent { +static struct soent { char *so_tname; int so_opt; int so_dorecv; /* do receive test? */ @@ -160,73 +139,52 @@ struct soent { union soval so_setval; socklen_t so_valsize; } sotab[] = { -/* RFC 3542, Section 4 */ - { - "IPV6_RECVPKTINFO", IPV6_RECVPKTINFO, 1, IPV6_PKTINFO, 1, { { { { { - 0}}}}}, { { { { { - 0}}}}}, sizeof(int)}, { - "IPV6_RECVHOPLIMIT", IPV6_RECVHOPLIMIT, 1, IPV6_HOPLIMIT, 1, { { { { { - 0}}}}}, { { { { { - 0}}}}}, sizeof(int)}, { - "IPV6_RECVRTHDR", IPV6_RECVRTHDR, 0, IPV6_RTHDR, 1, { { { { { - 0}}}}}, { { { { { - 0}}}}}, sizeof(int)}, { - "IPV6_RECVHOPOPTS", IPV6_RECVHOPOPTS, 0, IPV6_HOPOPTS, 1, { { { { { - 0}}}}}, { { { { { - 0}}}}}, sizeof(int)}, { - "IPV6_RECVDSTOPTS", IPV6_RECVDSTOPTS, 0, IPV6_DSTOPTS, 1, { { { { { - 0}}}}}, { { { { { - 0}}}}}, sizeof(int)}, { - "IPV6_RECVTCLASS", IPV6_RECVTCLASS, 1, IPV6_TCLASS, 1, { { { { { - 0}}}}}, { { { { { - 0}}}}}, sizeof(int)}, -/* make sure TCLASS stays when setting another opt */ - { - "IPV6_RECVTCLASS (2)", IPV6_RECVHOPLIMIT, 1, IPV6_TCLASS, 0, { { { { { - 0}}}}}, { { { { { - 0}}}}}, sizeof(int)}, -/* OLD values */ - { - "IPV6_2292PKTINFO", IPV6_2292PKTINFO, 1, IPV6_2292PKTINFO, 1, { { { { { - 0}}}}}, { { { { { - 0}}}}}, sizeof(int)}, { - "IPV6_2292HOPLIMIT", IPV6_2292HOPLIMIT, 1, IPV6_2292HOPLIMIT, 1, { { { { { - 0}}}}}, { { { { { - 0}}}}}, sizeof(int)}, { - "IPV6_2292RTHDR", IPV6_2292RTHDR, 0, IPV6_2292RTHDR, 1, { { { { { - 0}}}}}, { { { { { - 0}}}}}, sizeof(int)}, { - "IPV6_2292HOPOPTS", IPV6_2292HOPOPTS, 0, IPV6_2292HOPOPTS, 1, { { { { { - 0}}}}}, { { { { { - 0}}}}}, sizeof(int)}, { - "IPV6_2292DSTOPTS", IPV6_2292DSTOPTS, 0, IPV6_2292DSTOPTS, 1, { { { { { - 0}}}}}, { { { { { -0}}}}}, sizeof(int)},}; - -#define SOCOUNT (sizeof(sotab)/sizeof(sotab[0])) + /* RFC 3542, Section 4 */ + {"IPV6_RECVPKTINFO", IPV6_RECVPKTINFO, 1, IPV6_PKTINFO, 1, + {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)}, + {"IPV6_RECVHOPLIMIT", IPV6_RECVHOPLIMIT, 1, IPV6_HOPLIMIT, 1, + {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)}, + {"IPV6_RECVRTHDR", IPV6_RECVRTHDR, 0, IPV6_RTHDR, 1, + {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)}, + {"IPV6_RECVHOPOPTS", IPV6_RECVHOPOPTS, 0, IPV6_HOPOPTS, 1, + {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)}, + {"IPV6_RECVDSTOPTS", IPV6_RECVDSTOPTS, 0, IPV6_DSTOPTS, 1, + {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)}, + {"IPV6_RECVTCLASS", IPV6_RECVTCLASS, 1, IPV6_TCLASS, 1, + {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)}, + /* make sure TCLASS stays when setting another opt */ + {"IPV6_RECVTCLASS (2)", IPV6_RECVHOPLIMIT, 1, IPV6_TCLASS, 0, + {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)}, + /* OLD values */ + {"IPV6_2292PKTINFO", IPV6_2292PKTINFO, 1, IPV6_2292PKTINFO, 1, + {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)}, + {"IPV6_2292HOPLIMIT", IPV6_2292HOPLIMIT, 1, IPV6_2292HOPLIMIT, 1, + {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)}, + {"IPV6_2292RTHDR", IPV6_2292RTHDR, 0, IPV6_2292RTHDR, 1, + {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)}, + {"IPV6_2292HOPOPTS", IPV6_2292HOPOPTS, 0, IPV6_2292HOPOPTS, 1, + {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)}, + {"IPV6_2292DSTOPTS", IPV6_2292DSTOPTS, 0, IPV6_2292DSTOPTS, 1, + {{{{{0} } }, 0} }, {{{{{0} } }, 0} }, sizeof(int)}, +}; + +#define SOCOUNT ARRAY_SIZE(sotab) struct soprot { - int sop_pid; /* sender PID */ - int sop_seq; /* sequence # */ - int sop_dlen; /* tp_dat length */ + int sop_pid; /* sender PID */ + int sop_seq; /* sequence # */ + int sop_dlen; /* tp_dat length */ unsigned char sop_dat[0]; /* user data */ }; -unsigned char tpbuf[sizeof(struct soprot) + 2048]; -unsigned char rpbuf[sizeof(struct soprot) + 2048]; +static unsigned char tpbuf[sizeof(struct soprot) + 2048]; +static unsigned char rpbuf[sizeof(struct soprot) + 2048]; -unsigned char control[2048]; -int clen; +static unsigned char control[2048]; -int seq; +static int seq; -int setupso(void) -{ -/* add routing headers, other ancillary data here */ - return 0; -} - -struct cme { +static struct cme { int cm_len; int cm_level; int cm_type; @@ -235,26 +193,21 @@ struct cme { uint32_t cmu_hops; } cmu; } cmtab[] = { - { - sizeof(uint32_t), SOL_IPV6, IPV6_TCLASS, { - 0x12} - } - , { - sizeof(uint32_t), SOL_IPV6, IPV6_HOPLIMIT, { - 0x21} - } -,}; + {sizeof(uint32_t), SOL_IPV6, IPV6_TCLASS, {0x12} }, + {sizeof(uint32_t), SOL_IPV6, IPV6_HOPLIMIT, {0x21} }, +}; -#define CMCOUNT (sizeof(cmtab)/sizeof(cmtab[0])) +#define CMCOUNT ARRAY_SIZE(cmtab) -ssize_t sendall(int st) +static ssize_t sendall(int st) { struct sockaddr_in6 sin6; struct msghdr msg; struct iovec iov; struct soprot *psop; unsigned char *pd; - int i, ctotal; + unsigned int i; + int ctotal; psop = (struct soprot *)tpbuf; psop->sop_pid = htonl(getpid()); @@ -291,7 +244,7 @@ ssize_t sendall(int st) return sendmsg(st, &msg, 0); } -void so_test(struct soent *psoe) +static void so_test(struct soent *psoe) { struct sockaddr_in6 sin6; union soval sobuf; @@ -409,7 +362,7 @@ void so_test(struct soent *psoe) psoe->so_tname, strerror(errno)); return; } -/* check pid & seq here */ + /* check pid & seq here */ break; } gotone = 0; @@ -429,7 +382,7 @@ void so_test(struct soent *psoe) return; } } -/* check contents here */ + /* check contents here */ if (psoe->so_dorecv) tst_resm(gotone ? TPASS : TFAIL, "%s receive", psoe->so_tname); @@ -451,7 +404,7 @@ static int ipv6_addr_scope(struct in6_addr *pin6) } #endif /* HAVE_IFADDRS_H */ -int getsock(char *tname, struct sockaddr_in6 *psin6_arg, int scope) +static int getsock(char *tname, struct sockaddr_in6 *psin6_arg, int scope) { #ifdef HAVE_IFADDRS_H static struct ifaddrs *pifa_head; @@ -483,8 +436,10 @@ int getsock(char *tname, struct sockaddr_in6 *psin6_arg, int scope) (this_scope > 0 && this_scope != scope))) continue; psin6->sin6_scope_id = if_nametoindex(pifa->ifa_name); - if ((ifindex < 0 && -ifindex == psin6->sin6_scope_id) || - (ifindex > 0 && ifindex != psin6->sin6_scope_id)) + if ((ifindex < 0 && + -(unsigned int)ifindex == psin6->sin6_scope_id) || + (ifindex > 0 && + (unsigned int)ifindex != psin6->sin6_scope_id)) continue; s = socket(PF_INET6, SOCK_DGRAM, 0); if (s < 0) { @@ -548,7 +503,7 @@ int getsock(char *tname, struct sockaddr_in6 *psin6_arg, int scope) * RFC 3542 IPV6_PKTINFO not in mainline yet (as of 2.6.15). The get/set * tests are below, and comments for some further tests to be added later */ -void test_pktinfo(void) +static void test_pktinfo(void) { int s_snd, s_rcv[3] = { -1, -1, -1 }; struct sockaddr_in6 sa_rcv[3]; @@ -615,8 +570,8 @@ void test_pktinfo(void) sizeof(strbuf2)), pi.ipi6_ifindex); } else tst_resm(TPASS, "%s", tname); -/* ancillary data override */ -/* link-local, wrong interface */ + /* ancillary data override */ + /* link-local, wrong interface */ tname = "IPV6_PKTINFO invalid {lladdr, intf}"; pi.ipi6_addr = sa_rcv[1].sin6_addr; pi.ipi6_ifindex = sa_rcv[2].sin6_scope_id; @@ -628,17 +583,12 @@ void test_pktinfo(void) tst_resm(TFAIL, "%s errno %d != %d", tname, TEST_ERRNO, EINVAL); else tst_resm(TPASS, "%s", tname); -/* nonexistent interface */ -/* non-local address */ -/* clear address */ -/* clear interface */ -/* sendmsg() sin6_scope differs with ancillary data interface */ } #endif /* notyet */ -void do_tests(void) +static void do_tests(void) { - int i; + unsigned int i; for (i = 0; i < SOCOUNT; ++i) { sotab[i].so_clrval.sou_bool = 0; @@ -650,11 +600,7 @@ void do_tests(void) #endif /* notyet - see test_pktinfo() comment above */ } -void setup(void) -{ - TEST_PAUSE; /* if -P option specified */ -} - -void cleanup(void) +static void setup(void) { + TEST_PAUSE; } -- 1.9.3 ------------------------------------------------------------------------------ _______________________________________________ Ltp-list mailing list Ltp-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ltp-list