diff options
author | remi <remi@cvs.openbsd.org> | 2019-05-16 21:07:34 +0000 |
---|---|---|
committer | remi <remi@cvs.openbsd.org> | 2019-05-16 21:07:34 +0000 |
commit | 41713fd159d8883f70d6cca61869e3e9001ff659 (patch) | |
tree | 93cf870c841c461b45be9ace7b46d5ed2073f529 /usr.sbin | |
parent | 3a3278fcca5cae5ef3a477ca88e4649a1d2e7745 (diff) |
Accept address and number format for "ospfctl show database area XXX".
OK denis@ benno@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/ospfctl/parser.c | 44 | ||||
-rw-r--r-- | usr.sbin/ospfctl/parser.h | 3 |
2 files changed, 43 insertions, 4 deletions
diff --git a/usr.sbin/ospfctl/parser.c b/usr.sbin/ospfctl/parser.c index d7be6d19d81..4370e2d787b 100644 --- a/usr.sbin/ospfctl/parser.c +++ b/usr.sbin/ospfctl/parser.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.c,v 1.20 2011/05/09 12:25:35 claudio Exp $ */ +/* $OpenBSD: parser.c,v 1.21 2019/05/16 21:07:33 remi Exp $ */ /* * Copyright (c) 2004 Esben Norby <norby@openbsd.org> @@ -39,7 +39,8 @@ enum token_type { ADDRESS, FLAG, PREFIX, - IFNAME + IFNAME, + AREA }; struct token { @@ -107,7 +108,7 @@ static const struct token t_show_db[] = { }; static const struct token t_show_area[] = { - {ADDRESS, "", NONE, NULL}, + {AREA, "", NONE, NULL}, {ENDTOKEN, "", NONE, NULL} }; @@ -218,6 +219,14 @@ match_token(const char *word, const struct token *table, res->action = t->value; } break; + case AREA: + if (parse_area(word, &res->addr)) { + match++; + t = &table[i]; + if (t->value) + res->action = t->value; + } + break; case PREFIX: if (parse_prefix(word, &res->addr, &res->prefixlen)) { match++; @@ -274,6 +283,9 @@ show_valid_args(const struct token *table) case ADDRESS: fprintf(stderr, " <address>\n"); break; + case AREA: + fprintf(stderr, " <area>\n"); + break; case PREFIX: fprintf(stderr, " <address>[/<len>]\n"); break; @@ -306,6 +318,32 @@ parse_addr(const char *word, struct in_addr *addr) } int +parse_area(const char *word, struct in_addr *addr) +{ + struct in_addr ina; + const char *errstr; + + if (word == NULL) + return (0); + + bzero(addr, sizeof(struct in_addr)); + bzero(&ina, sizeof(ina)); + + if (inet_pton(AF_INET, word, &ina)) { + addr->s_addr = ina.s_addr; + return (1); + } + + ina.s_addr = htonl(strtonum(word, 0, 0xffffffff, &errstr)); + if (errstr == NULL) { + addr->s_addr = ina.s_addr; + return (1); + } + + return (0); +} + +int parse_prefix(const char *word, struct in_addr *addr, u_int8_t *prefixlen) { struct in_addr ina; diff --git a/usr.sbin/ospfctl/parser.h b/usr.sbin/ospfctl/parser.h index 46612eab0c2..384be42b2b5 100644 --- a/usr.sbin/ospfctl/parser.h +++ b/usr.sbin/ospfctl/parser.h @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.h,v 1.13 2011/05/09 12:25:35 claudio Exp $ */ +/* $OpenBSD: parser.h,v 1.14 2019/05/16 21:07:33 remi Exp $ */ /* * Copyright (c) 2004 Esben Norby <norby@openbsd.org> @@ -64,6 +64,7 @@ struct parse_result { struct parse_result *parse(int, char *[]); int parse_addr(const char *, struct in_addr *); +int parse_area(const char *, struct in_addr *); int parse_prefix(const char *, struct in_addr *, u_int8_t *); |