From ccc5da470e76032f8e175920553516835efb30f1 Mon Sep 17 00:00:00 2001 From: Elise Lennion Date: Tue, 29 Nov 2016 23:12:37 -0200 Subject: datatype: Replace getnameinfo() by internal lookup table To avoid exceeding the inputs number limit of the flex scanner used, when calling getnameinfo() in inet_service_type_print(). The new symbol_table was associated with inet_service_type, to enable listing all pre-defined services using nft command line tool. The listed services are all well-known and registered ports of my local /etc/services file, from Ubuntu 16.04. Service numbers are converted to respect network byte order. Signed-off-by: Elise Lennion Signed-off-by: Pablo Neira Ayuso --- src/datatype.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) (limited to 'src/datatype.c') diff --git a/src/datatype.c b/src/datatype.c index 1e402879..c92f9276 100644 --- a/src/datatype.c +++ b/src/datatype.c @@ -559,19 +559,7 @@ const struct datatype inet_protocol_type = { static void inet_service_type_print(const struct expr *expr) { - struct sockaddr_in sin = { .sin_family = AF_INET }; - char buf[NI_MAXSERV]; - int err; - - sin.sin_port = mpz_get_be16(expr->value); - err = getnameinfo((struct sockaddr *)&sin, sizeof(sin), NULL, 0, - buf, sizeof(buf), - numeric_output < NUMERIC_PORT ? 0 : NI_NUMERICSERV); - if (err != 0) { - getnameinfo((struct sockaddr *)&sin, sizeof(sin), NULL, - 0, buf, sizeof(buf), NI_NUMERICSERV); - } - printf("%s", buf); + symbolic_constant_print(&inet_service_tbl, expr, false); } static struct error_record *inet_service_type_parse(const struct expr *sym, @@ -615,6 +603,7 @@ const struct datatype inet_service_type = { .basetype = &integer_type, .print = inet_service_type_print, .parse = inet_service_type_parse, + .sym_tbl = &inet_service_tbl, }; #define RT_SYM_TAB_INITIAL_SIZE 16 -- cgit v1.2.3