IP link state show enhancements
Show operational state (carrier), as well as fixing functions
to be static and use similar API.
diff --git a/ip/ipaddress.c b/ip/ipaddress.c
index 0a34ace..59c71c8 100644
--- a/ip/ipaddress.c
+++ b/ip/ipaddress.c
@@ -20,6 +20,7 @@
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
+#include <sys/errno.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
@@ -114,7 +115,20 @@
fprintf(fp, "> ");
}
-void print_queuelen(char *name)
+static const char *oper_states[] = {
+ "UNKNOWN", "NOTPRESENT", "DOWN", "LOWERLAYERDOWN",
+ "TESTING", "DORMANT", "UP"
+};
+
+static void print_operstate(FILE *f, __u8 state)
+{
+ if (state >= sizeof(oper_states)/sizeof(oper_states[0]))
+ fprintf(f, "state %#x ", state);
+ else
+ fprintf(f, "state %s ", oper_states[state]);
+}
+
+static void print_queuelen(FILE *f, const char *name)
{
struct ifreq ifr;
int s;
@@ -126,14 +140,14 @@
memset(&ifr, 0, sizeof(ifr));
strcpy(ifr.ifr_name, name);
if (ioctl(s, SIOCGIFTXQLEN, &ifr) < 0) {
- perror("SIOCGIFXQLEN");
+ fprintf(f, "ioctl(SIOCGIFXQLEN) failed: %s\n", strerror(errno));
close(s);
return;
}
close(s);
if (ifr.ifr_qlen)
- printf("qlen %d", ifr.ifr_qlen);
+ fprintf(f, "qlen %d", ifr.ifr_qlen);
}
static void print_linktype(FILE *fp, struct rtattr *tb)
@@ -233,8 +247,11 @@
fprintf(fp, "master %s ", ll_idx_n2a(*(int*)RTA_DATA(tb[IFLA_MASTER]), b1));
}
#endif
+ if (tb[IFLA_OPERSTATE])
+ print_operstate(fp, *(__u8 *)RTA_DATA(tb[IFLA_OPERSTATE]));
+
if (filter.showqueue)
- print_queuelen((char*)RTA_DATA(tb[IFLA_IFNAME]));
+ print_queuelen(fp, (char*)RTA_DATA(tb[IFLA_IFNAME]));
if (!filter.family || filter.family == AF_PACKET) {
SPRINT_BUF(b1);
@@ -514,7 +531,7 @@
struct nlmsghdr h;
};
-int print_selected_addrinfo(int ifindex, struct nlmsg_list *ainfo, FILE *fp)
+static int print_selected_addrinfo(int ifindex, struct nlmsg_list *ainfo, FILE *fp)
{
for ( ;ainfo ; ainfo = ainfo->next) {
struct nlmsghdr *n = &ainfo->h;
@@ -557,7 +574,7 @@
return 0;
}
-int ipaddr_list_or_flush(int argc, char **argv, int flush)
+static int ipaddr_list_or_flush(int argc, char **argv, int flush)
{
struct nlmsg_list *linfo = NULL;
struct nlmsg_list *ainfo = NULL;
@@ -795,7 +812,7 @@
filter.oneline = oneline;
}
-int default_scope(inet_prefix *lcl)
+static int default_scope(inet_prefix *lcl)
{
if (lcl->family == AF_INET) {
if (lcl->bytelen >= 1 && *(__u8*)&lcl->data == 127)
@@ -804,7 +821,7 @@
return 0;
}
-int ipaddr_modify(int cmd, int flags, int argc, char **argv)
+static int ipaddr_modify(int cmd, int flags, int argc, char **argv)
{
struct {
struct nlmsghdr n;