From 703575d4b45d15996ee2ca0b13d958a22cd78f4f Mon Sep 17 00:00:00 2001 From: Stephane Ouellette Date: Sat, 23 Aug 2003 18:41:47 +0000 Subject: various cosmetic / c99 cleanups (Stephane Ouellette) --- extensions/libip6t_ah.c | 85 +++++++++++++++++++++---------------------------- 1 file changed, 37 insertions(+), 48 deletions(-) (limited to 'extensions/libip6t_ah.c') diff --git a/extensions/libip6t_ah.c b/extensions/libip6t_ah.c index aced51bb..794e02eb 100644 --- a/extensions/libip6t_ah.c +++ b/extensions/libip6t_ah.c @@ -21,10 +21,10 @@ IPTABLES_VERSION); } static struct option opts[] = { - { "ahspi", 1, 0, '1' }, - { "ahlen", 1, 0, '2' }, - { "ahres", 0, 0, '3' }, - {0} + { .name = "ahspi", .has_arg = 1, .flag = 0, .val = '1' }, + { .name = "ahlen", .has_arg = 1, .flag = 0, .val = '2' }, + { .name = "ahres", .has_arg = 0, .flag = 0, .val = '3' }, + { .name = 0 } }; static u_int32_t @@ -33,21 +33,21 @@ parse_ah_spi(const char *spistr, const char *typestr) unsigned long int spi; char* ep; - spi = strtoul(spistr,&ep,0) ; + spi = strtoul(spistr, &ep, 0); - if ( spistr == ep ) { + if ( spistr == ep ) exit_error(PARAMETER_PROBLEM, "AH no valid digits in %s `%s'", typestr, spistr); - } - if ( spi == ULONG_MAX && errno == ERANGE ) { + + if ( spi == ULONG_MAX && errno == ERANGE ) exit_error(PARAMETER_PROBLEM, "%s `%s' specified too big: would overflow", typestr, spistr); - } - if ( *spistr != '\0' && *ep != '\0' ) { + + if ( *spistr != '\0' && *ep != '\0' ) exit_error(PARAMETER_PROBLEM, "AH error parsing %s `%s'", typestr, spistr); - } + return (u_int32_t) spi; } @@ -59,13 +59,13 @@ parse_ah_spis(const char *spistring, u_int32_t *spis) buffer = strdup(spistring); if ((cp = strchr(buffer, ':')) == NULL) - spis[0] = spis[1] = parse_ah_spi(buffer,"spi"); + spis[0] = spis[1] = parse_ah_spi(buffer, "spi"); else { *cp = '\0'; cp++; - spis[0] = buffer[0] ? parse_ah_spi(buffer,"spi") : 0; - spis[1] = cp[0] ? parse_ah_spi(cp,"spi") : 0xFFFFFFFF; + spis[0] = buffer[0] ? parse_ah_spi(buffer, "spi") : 0; + spis[1] = cp[0] ? parse_ah_spi(cp, "spi") : 0xFFFFFFFF; } free(buffer); } @@ -139,17 +139,10 @@ print_spis(const char *name, u_int32_t min, u_int32_t max, const char *inv = invert ? "!" : ""; if (min != 0 || max != 0xFFFFFFFF || invert) { - printf("%s", name); - if (min == max) { - printf(":%s", inv); - printf("%u", min); - } else { - printf("s:%s", inv); - printf("%u",min); - printf(":"); - printf("%u",max); - } - printf(" "); + if (min == max) + printf("%s:%s%u ", name, inv, min); + else + printf("%ss:%s%u:%u ", name, inv, min, max); } } @@ -158,12 +151,8 @@ print_len(const char *name, u_int32_t len, int invert) { const char *inv = invert ? "!" : ""; - if (len != 0 || invert) { - printf("%s", name); - printf(":%s", inv); - printf("%u", len); - printf(" "); - } + if (len != 0 || invert) + printf("%s:%s%u ", name, inv, len); } /* Prints out the union ip6t_matchinfo. */ @@ -178,7 +167,10 @@ print(const struct ip6t_ip6 *ip, ah->invflags & IP6T_AH_INV_SPI); print_len("length", ah->hdrlen, ah->invflags & IP6T_AH_INV_LEN); - if (ah->hdrres) printf("reserved "); + + if (ah->hdrres) + printf("reserved "); + if (ah->invflags & ~IP6T_AH_INV_MASK) printf("Unknown invflags: 0x%X ", ah->invflags & ~IP6T_AH_INV_MASK); @@ -209,26 +201,23 @@ static void save(const struct ip6t_ip6 *ip, const struct ip6t_entry_match *match ahinfo->hdrlen); } - if (ahinfo->hdrres != 0 ) { + if (ahinfo->hdrres != 0 ) printf("--ahres "); - } - } static -struct ip6tables_match ah -= { NULL, - "ah", - IPTABLES_VERSION, - IP6T_ALIGN(sizeof(struct ip6t_ah)), - IP6T_ALIGN(sizeof(struct ip6t_ah)), - &help, - &init, - &parse, - &final_check, - &print, - &save, - opts +struct ip6tables_match ah = { + .name = "ah", + .version = IPTABLES_VERSION, + .size = IP6T_ALIGN(sizeof(struct ip6t_ah)), + .userspacesize = IP6T_ALIGN(sizeof(struct ip6t_ah)), + .help = &help, + .init = &init, + .parse = &parse, + .final_check = &final_check, + .print = &print, + .save = &save, + .extra_opts = opts }; void -- cgit v1.2.3