From ad8d1ab2e36be7100afaf6fabfe3049423e51cce Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Thu, 4 Sep 2003 21:55:10 +0000 Subject: 1- Fix preprocessor directive usage, 2- Redefine UNAME and LNAME macros such that their value is determined at compile-time, not at run-time, 3- Modify all printf() calls that use LNAME and UNAME to take advantage of the compile-time macro definitions, 4- More indentation fixes. (Stephane Ouellette) --- extensions/libip6t_dst.c | 109 +++++++++++++++++++++++------------------------ 1 file changed, 54 insertions(+), 55 deletions(-) (limited to 'extensions') diff --git a/extensions/libip6t_dst.c b/extensions/libip6t_dst.c index 7eb64cd7..19ca23c0 100644 --- a/extensions/libip6t_dst.c +++ b/extensions/libip6t_dst.c @@ -6,44 +6,37 @@ #include #include #include -/*#include */ #include #include #include #include - -#define DEBUG 0 -#define HOPBYHOP 0 -#define UNAME (HOPBYHOP ? "HBH" : "DST") -#define LNAME (HOPBYHOP ? "hbh" : "dst") + +#ifdef HOPBYHOP +#define UNAME "HBH" +#define LNAME "hbh" +#else +#define UNAME "DST" +#define LNAME "dst" +#endif /* Function which prints out usage message. */ static void help(void) { printf( -"%s v%s options:\n" -" --%s-len [!] length total length of this header\n" -" --%s-opts TYPE[:LEN][,TYPE[:LEN]...] \n" +UNAME " v%s options:\n" +" --" LNAME "-len [!] length total length of this header\n" +" --" LNAME "-opts TYPE[:LEN][,TYPE[:LEN]...] \n" " Options and its length (list, max: %d)\n", -UNAME , IPTABLES_VERSION, LNAME, LNAME, IP6T_OPTS_OPTSNR); +IPTABLES_VERSION, IP6T_OPTS_OPTSNR); } -#if HOPBYHOP static struct option opts[] = { - { .name = "hbh-len", .has_arg = 1, .flag = 0, .val = '1' }, - { .name = "hbh-opts", .has_arg = 1, .flag = 0, .val = '2' }, - { .name = "hbh-not-strict", .has_arg = 1, .flag = 0, .val = '3' }, + { .name = LNAME "-len", .has_arg = 1, .flag = 0, .val = '1' }, + { .name = LNAME "-opts", .has_arg = 1, .flag = 0, .val = '2' }, + { .name = LNAME "-not-strict", .has_arg = 1, .flag = 0, .val = '3' }, { .name = 0 } }; -#else -static struct option opts[] = { - { .name = "dst-len", .has_arg = 1, .flag = 0, .val = '1' }, - { .name = "dst-opts", .has_arg = 1, .flag = 0, .val = '2' }, - { .name = "dst-not-strict", .has_arg = 1, .flag = 0, .val = '3' }, - { .name = 0 } -}; -#endif static u_int32_t parse_opts_num(const char *idstr, const char *typestr) @@ -55,16 +48,16 @@ parse_opts_num(const char *idstr, const char *typestr) if ( idstr == ep ) { exit_error(PARAMETER_PROBLEM, - "%s no valid digits in %s `%s'", UNAME, typestr, idstr); + UNAME " no valid digits in %s `%s'", typestr, idstr); } if ( id == ULONG_MAX && errno == ERANGE ) { exit_error(PARAMETER_PROBLEM, "%s `%s' specified too big: would overflow", typestr, idstr); - } + } if ( *idstr != '\0' && *ep != '\0' ) { exit_error(PARAMETER_PROBLEM, - "%s error parsing %s `%s'", UNAME, typestr, idstr); + UNAME " error parsing %s `%s'", typestr, idstr); } return (u_int32_t) id; } @@ -76,39 +69,47 @@ parse_options(const char *optsstr, u_int16_t *opts) unsigned int i; buffer = strdup(optsstr); - if (!buffer) exit_error(OTHER_PROBLEM, "strdup failed"); + if (!buffer) + exit_error(OTHER_PROBLEM, "strdup failed"); - for (cp=buffer, i=0; cp && ihdrlen = parse_opts_num(argv[optind-1], "length"); if (invert) @@ -152,11 +153,11 @@ parse(int c, char **argv, int invert, unsigned int *flags, case '2': if (*flags & IP6T_OPTS_OPTS) exit_error(PARAMETER_PROBLEM, - "Only one `--%s-opts' allowed", LNAME); + "Only one `--" LNAME "-opts' allowed"); check_inverse(optarg, &invert, &optind, 0); if (invert) exit_error(PARAMETER_PROBLEM, - " '!' not allowed with `--%s-opts'", LNAME); + " '!' not allowed with `--" LNAME "-opts'"); optinfo->optsnr = parse_options(argv[optind-1], optinfo->opts); optinfo->flags |= IP6T_OPTS_OPTS; *flags |= IP6T_OPTS_OPTS; @@ -164,10 +165,11 @@ parse(int c, char **argv, int invert, unsigned int *flags, case '3': if (*flags & IP6T_OPTS_NSTRICT) exit_error(PARAMETER_PROBLEM, - "Only one `--%s-not-strict' allowed", LNAME); + "Only one `--" LNAME "-not-strict' allowed"); if ( !(*flags & IP6T_OPTS_OPTS) ) exit_error(PARAMETER_PROBLEM, - "`--%s-opts ...' required before `--%s-not-strict'", LNAME, LNAME); + "`--" LNAME "-opts ...' required before `--" + LNAME "-not-strict'"); optinfo->flags |= IP6T_OPTS_NSTRICT; *flags |= IP6T_OPTS_NSTRICT; break; @@ -189,12 +191,13 @@ print_options(int optsnr, u_int16_t *optsp) { unsigned int i; - for(i=0; i>8); - if ((optsp[i] & 0x00FF) != 0x00FF){ + for(i = 0; i < optsnr; i++) { + printf("%d", (optsp[i] & 0xFF00) >> 8); + + if ((optsp[i] & 0x00FF) != 0x00FF) printf(":%d", (optsp[i] & 0x00FF)); - } - printf("%c", (i!=optsnr-1)?',':' '); + + printf("%c", (i != optsnr - 1) ? ',' : ' '); } } @@ -205,7 +208,7 @@ print(const struct ip6t_ip6 *ip, { const struct ip6t_opts *optinfo = (struct ip6t_opts *)match->data; - printf("%s ", LNAME); + printf(LNAME " "); if (optinfo->flags & IP6T_OPTS_LEN) printf("length:%s%u ", optinfo->invflags & IP6T_OPTS_INV_LEN ? "!" : "", @@ -230,34 +233,30 @@ static void save(const struct ip6t_ip6 *ip, const struct ip6t_entry_match *match const struct ip6t_opts *optinfo = (struct ip6t_opts *)match->data; if (optinfo->flags & IP6T_OPTS_LEN) { - printf("--%s-len %s%u ", LNAME, + printf("--" LNAME "-len %s%u ", (optinfo->invflags & IP6T_OPTS_INV_LEN) ? "! " : "", optinfo->hdrlen); } if (optinfo->flags & IP6T_OPTS_OPTS) - printf("--%s-opts ", LNAME); + printf("--" LNAME "-opts "); print_options(optinfo->optsnr, (u_int16_t *)optinfo->opts); if (optinfo->flags & IP6T_OPTS_NSTRICT) - printf("--%s-not-strict ", LNAME); + printf("--" LNAME "-not-strict "); } static struct ip6tables_match optstruct = { -#if HOPBYHOP - .name = "hbh", -#else - .name = "dst", -#endif + .name = LNAME, .version = IPTABLES_VERSION, .size = IP6T_ALIGN(sizeof(struct ip6t_opts)), .userspacesize = IP6T_ALIGN(sizeof(struct ip6t_opts)), .help = &help, .init = &init, .parse = &parse, - .final = &final_check, + .final_check = &final_check, .print = &print, .save = &save, .extra_opts = opts -- cgit v1.2.3