diff --git a/include/utils.h b/include/utils.h index 2c690417b721..31c9e792f8bd 100644 --- a/include/utils.h +++ b/include/utils.h @@ -26,6 +26,7 @@ extern const char * _SL_; extern int max_flush_loops; extern int batch_mode; extern bool do_all; +extern int numeric; #ifndef IPPROTO_ESP #define IPPROTO_ESP 50 diff --git a/ip/ip.c b/ip/ip.c index eea00b822088..995c2daed965 100644 --- a/ip/ip.c +++ b/ip/ip.c @@ -39,6 +39,7 @@ int force; int max_flush_loops = 10; int batch_mode; bool do_all; +int numeric; struct rtnl_handle rth = { .fd = -1 }; @@ -236,10 +237,8 @@ int main(int argc, char **argv) } else if (matches(opt, "-tshort") == 0) { ++timestamp; ++timestamp_short; -#if 0 } else if (matches(opt, "-numeric") == 0) { - rtnl_names_numeric++; -#endif + numeric++; } else if (matches(opt, "-Version") == 0) { printf("ip utility, iproute2-ss%s\n", SNAPSHOT); exit(0); diff --git a/lib/rt_names.c b/lib/rt_names.c index f68e91d6d046..86066ec2df2c 100644 --- a/lib/rt_names.c +++ b/lib/rt_names.c @@ -21,6 +21,7 @@ #include #include +#include #include "rt_names.h" @@ -151,7 +152,7 @@ static void rtnl_rtprot_initialize(void) const char * rtnl_rtprot_n2a(int id, char *buf, int len) { - if (id<0 || id>=256) { + if (id<0 || id>=256 || numeric) { snprintf(buf, len, "%u", id); return buf; } @@ -216,7 +217,7 @@ static void rtnl_rtscope_initialize(void) const char *rtnl_rtscope_n2a(int id, char *buf, int len) { - if (id<0 || id>=256) { + if (id<0 || id>=256 || numeric) { snprintf(buf, len, "%d", id); return buf; } @@ -278,7 +279,7 @@ static void rtnl_rtrealm_initialize(void) const char *rtnl_rtrealm_n2a(int id, char *buf, int len) { - if (id<0 || id>=256) { + if (id<0 || id>=256 || numeric) { snprintf(buf, len, "%d", id); return buf; } @@ -380,7 +381,7 @@ const char * rtnl_rttable_n2a(__u32 id, char *buf, int len) { struct rtnl_hash_entry *entry; - if (id > RT_TABLE_MAX) { + if (id > RT_TABLE_MAX || numeric) { snprintf(buf, len, "%u", id); return buf; } @@ -446,7 +447,7 @@ static void rtnl_rtdsfield_initialize(void) const char *rtnl_dsfield_n2a(int id, char *buf, int len) { - if (id<0 || id>=256) { + if (id<0 || id>=256 || numeric) { snprintf(buf, len, "%d", id); return buf; } @@ -549,6 +550,11 @@ const char *rtnl_group_n2a(int id, char *buf, int len) struct rtnl_hash_entry *entry; int i; + if (numeric) { + snprintf(buf, len, "%d", id); + return buf; + } + if (!rtnl_group_init) rtnl_group_initialize(); @@ -598,7 +604,7 @@ static void nl_proto_initialize(void) const char *nl_proto_n2a(int id, char *buf, int len) { - if (id < 0 || id >= 256) { + if (id < 0 || id >= 256 || numeric) { snprintf(buf, len, "%u", id); return buf; } diff --git a/misc/rtacct.c b/misc/rtacct.c index bb8c90f98f5a..acecce0c3ecc 100644 --- a/misc/rtacct.c +++ b/misc/rtacct.c @@ -42,6 +42,7 @@ int time_constant = 0; int dump_zeros = 0; unsigned long magic_number = 0; double W; +int numeric; static int generic_proc_open(const char *env, const char *name) { diff --git a/misc/ss.c b/misc/ss.c index eca4aa35facc..c6428cc2f19b 100644 --- a/misc/ss.c +++ b/misc/ss.c @@ -87,7 +87,6 @@ static int security_get_initial_context(char *name, char **context) #endif int resolve_hosts = 0; -int resolve_services = 1; int preferred_family = AF_UNSPEC; int show_options = 0; int show_details = 0; @@ -100,6 +99,7 @@ int show_sock_ctx = 0; /* If show_users & show_proc_ctx only do user_ent_hash_build() once */ int user_ent_hash_build_init = 0; int follow_events = 0; +int numeric; int netid_width; int state_width; @@ -963,7 +963,7 @@ static const char *resolve_service(int port) return buf; } - if (!resolve_services) + if (numeric) goto do_numeric; if (dg_proto == RAW_PROTO) @@ -3076,14 +3076,11 @@ static int netlink_show_one(struct filter *f, sock_state_print(&st, "nl"); - if (resolve_services) - prot_name = nl_proto_n2a(prot, prot_buf, sizeof(prot_buf)); - else - prot_name = int_to_str(prot, prot_buf); + prot_name = nl_proto_n2a(prot, prot_buf, sizeof(prot_buf)); if (pid == -1) { procname[0] = '*'; - } else if (resolve_services) { + } else if (!numeric) { int done = 0; if (!pid) { done = 1; @@ -3592,7 +3589,7 @@ int main(int argc, char *argv[]) long_opts, NULL)) != EOF) { switch(ch) { case 'n': - resolve_services = 0; + numeric = 1; break; case 'r': resolve_hosts = 1; @@ -3814,7 +3811,7 @@ int main(int argc, char *argv[]) filter_states_set(¤t_filter, state_filter); filter_merge_defaults(¤t_filter); - if (resolve_services && resolve_hosts && + if (!numeric && resolve_hosts && (current_filter.dbs&(UNIX_DBM|(1<