Hi, Added -l argument to ifconfig to only print names of interfaces. (Maybe a lame excuse from me for being too lazy but FreeBSD supports it too)
Hope it helps, B.E
>From dc4f0f8d85a9aa2007b47139f6d609c9830bbfc3 Mon Sep 17 00:00:00 2001 From: Bijan Ebrahimi <bijanebrah...@riseup.net> Date: Fri, 19 Jan 2018 18:18:24 +0330 Subject: [PATCH] added printing names of all inetrfaces to ifconfig --- sbin/ifconfig/ifconfig.8 | 7 ++++++- sbin/ifconfig/ifconfig.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git sbin/ifconfig/ifconfig.8 sbin/ifconfig/ifconfig.8 index ef9592cf3..6055fa4aa 100644 --- sbin/ifconfig/ifconfig.8 +++ sbin/ifconfig/ifconfig.8 @@ -39,7 +39,7 @@ .Nd configure network interface parameters .Sh SYNOPSIS .Nm ifconfig -.Op Fl AaC +.Op Fl AaCl .Op Ar interface .Op Ar address_family .Oo @@ -88,6 +88,11 @@ This is the default, if no parameters are given to Print the names of all network pseudo-devices that can be created dynamically at runtime using .Nm Cm create . +.It Fl l +Causes +.Nm +to print names of all existing interfaces. +.Nm . .It Ar interface The .Ar interface diff --git sbin/ifconfig/ifconfig.c sbin/ifconfig/ifconfig.c index 4a0f4d632..c4c9a1527 100644 --- sbin/ifconfig/ifconfig.c +++ sbin/ifconfig/ifconfig.c @@ -232,6 +232,7 @@ void unsettrunkport(const char *, int); void settrunkproto(const char *, int); void trunk_status(void); void list_cloners(void); +void list_names(void); #ifndef SMALL void carp_status(void); @@ -632,6 +633,7 @@ main(int argc, char *argv[]) const struct afswtch *rafp = NULL; int create = 0; int Cflag = 0; + int lflag = 0; int gflag = 0; int i; @@ -659,6 +661,10 @@ main(int argc, char *argv[]) case 'g': gflag = 1; break; + case 'l': + lflag = 1; + nomore = 1; + break; case 'C': Cflag = 1; nomore = 1; @@ -695,6 +701,10 @@ main(int argc, char *argv[]) list_cloners(); return (0); } + if (lflag) { + list_names(); + return (0); + } if (gflag) { if (argc == 0) printgroupattribs(name); @@ -1147,6 +1157,31 @@ list_cloners(void) free(buf); } +void +list_names(void) +{ + int count = 0; + struct ifaddrs *ifap, *ifa; + const char *if_name = NULL; + + if (getifaddrs(&ifap) != 0) + err(1, "getifaddrs"); + + for (ifa = ifap; ifa; ifa = ifa->ifa_next) { + if (if_name == ifa->ifa_name) + continue; + if_name = ifa->ifa_name; + if (count++ > 0) + printf(" "); + printf ("%s", ifa->ifa_name); + } + + if (if_name != NULL) + printf("\n"); + + freeifaddrs(ifap); +} + #define RIDADDR 0 #define ADDR 1 #define MASK 2 -- 2.14.2