diff options
author | fnm3 <fnm3> | 2002-12-11 10:52:18 +0000 |
---|---|---|
committer | fnm3 <fnm3> | 2002-12-11 10:52:18 +0000 |
commit | c376369b69abdbfcbbc728ee7ef8750642a3254e (patch) | |
tree | 4a1be9a878b20f7427a81699c3cc9ecdbdcb9a8b /userspace/ebtables2 | |
parent | fbb9bc55986b5dfb45933b4b0f195200fa99f383 (diff) |
Added getprotobyname() for --ip-proto parameter
Diffstat (limited to 'userspace/ebtables2')
-rw-r--r-- | userspace/ebtables2/extensions/ebt_ip.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/userspace/ebtables2/extensions/ebt_ip.c b/userspace/ebtables2/extensions/ebt_ip.c index 7a054ce..916d7af 100644 --- a/userspace/ebtables2/extensions/ebt_ip.c +++ b/userspace/ebtables2/extensions/ebt_ip.c @@ -57,6 +57,8 @@ static struct option opts[] = { 0 } }; +struct protoent *pe; + // put the ip string into 4 bytes static int undot_ip(char *ip, unsigned char *ip2) { @@ -313,10 +315,17 @@ static int parse(int c, char **argv, int argc, const struct ebt_u_entry *entry, ipinfo->invflags |= EBT_IP_PROTO; if (optind > argc) print_error("Missing IP protocol argument"); - i = strtol(argv[optind - 1], &end, 10); - if (i < 0 || i > 255 || *end != '\0') - print_error("Problem with specified IP protocol"); - ipinfo->protocol = i; + (unsigned char) i = strtoul(argv[optind - 1], &end, 10); + if (*end != '\0') { + pe = getprotobyname(argv[optind - 1]); + if (pe == NULL) + print_error + ("Unknown specified IP protocol - %s", + argv[optind - 1]); + ipinfo->protocol = pe->p_proto; + } else { + ipinfo->protocol = (unsigned char) i; + } ipinfo->bitmask |= EBT_IP_PROTO; break; default: @@ -378,7 +387,12 @@ static void print(const struct ebt_u_entry *entry, printf("--ip-proto "); if (ipinfo->invflags & EBT_IP_PROTO) printf("! "); - printf("%d ", ipinfo->protocol); + pe = getprotobynumber(ipinfo->protocol); + if (pe == NULL) { + printf("%d ", ipinfo->protocol); + } else { + printf("%s ", pe->p_name); + } } if (ipinfo->bitmask & EBT_IP_SPORT) { printf("--ip-sport "); |