]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - ip/rtmon.c
Merge branch 'main' into next
[mirror_iproute2.git] / ip / rtmon.c
index 42b24fb5fd385db1a778038c7249bb0fafc1fded..01c19c80a30a60c20b69b4380c9fc4ebd8ef8d87 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <sys/time.h>
 #include <netinet/in.h>
 #include <string.h>
 
-#include "SNAPSHOT.h"
+#include "version.h"
 
 #include "utils.h"
 #include "libnetlink.h"
 
-int resolve_hosts = 0;
 static int init_phase = 1;
 
 static void write_stamp(FILE *fp)
 {
        char buf[128];
-       struct nlmsghdr *n1 = (void*)buf;
+       struct nlmsghdr *n1 = (void *)buf;
        struct timeval tv;
 
        n1->nlmsg_type = NLMSG_TSTAMP;
@@ -40,32 +38,35 @@ static void write_stamp(FILE *fp)
        n1->nlmsg_pid = 0;
        n1->nlmsg_len = NLMSG_LENGTH(4*2);
        gettimeofday(&tv, NULL);
-       ((__u32*)NLMSG_DATA(n1))[0] = tv.tv_sec;
-       ((__u32*)NLMSG_DATA(n1))[1] = tv.tv_usec;
-       fwrite((void*)n1, 1, NLMSG_ALIGN(n1->nlmsg_len), fp);
+       ((__u32 *)NLMSG_DATA(n1))[0] = tv.tv_sec;
+       ((__u32 *)NLMSG_DATA(n1))[1] = tv.tv_usec;
+       fwrite((void *)n1, 1, NLMSG_ALIGN(n1->nlmsg_len), fp);
 }
 
-static int dump_msg(const struct sockaddr_nl *who, struct rtnl_ctrl_data *ctrl,
+static int dump_msg(struct rtnl_ctrl_data *ctrl,
                    struct nlmsghdr *n, void *arg)
 {
-       FILE *fp = (FILE*)arg;
+       FILE *fp = (FILE *)arg;
+
        if (!init_phase)
                write_stamp(fp);
-       fwrite((void*)n, 1, NLMSG_ALIGN(n->nlmsg_len), fp);
+       fwrite((void *)n, 1, NLMSG_ALIGN(n->nlmsg_len), fp);
        fflush(fp);
        return 0;
 }
 
-static int dump_msg2(const struct sockaddr_nl *who,
-                    struct nlmsghdr *n, void *arg)
+static int dump_msg2(struct nlmsghdr *n, void *arg)
 {
-       return dump_msg(who, NULL, n, arg);
+       return dump_msg(NULL, n, arg);
 }
 
 static void usage(void)
 {
-       fprintf(stderr, "Usage: rtmon file FILE [ all | LISTofOBJECTS]\n");
-       fprintf(stderr, "LISTofOBJECTS := [ link ] [ address ] [ route ]\n");
+       fprintf(stderr,
+               "Usage: rtmon [ OPTIONS ] file FILE [ all | LISTofOBJECTS ]\n"
+               "OPTIONS := { -f[amily] { inet | inet6 | link | help } |\n"
+               "            -4 | -6 | -0 | -V[ersion] }\n"
+               "LISTofOBJECTS := [ link ] [ address ] [ route ]\n");
        exit(-1);
 }
 
@@ -75,7 +76,7 @@ main(int argc, char **argv)
        FILE *fp;
        struct rtnl_handle rth;
        int family = AF_UNSPEC;
-       unsigned groups = ~0U;
+       unsigned int groups = ~0U;
        int llink = 0;
        int laddr = 0;
        int lroute = 0;
@@ -106,7 +107,7 @@ main(int argc, char **argv)
                } else if (strcmp(argv[1], "-0") == 0) {
                        family = AF_PACKET;
                } else if (matches(argv[1], "-Version") == 0) {
-                       printf("rtmon utility, iproute2-ss%s\n", SNAPSHOT);
+                       printf("rtmon utility, iproute2-%s\n", version);
                        exit(0);
                } else if (matches(argv[1], "file") == 0) {
                        argc--;
@@ -115,13 +116,13 @@ main(int argc, char **argv)
                                usage();
                        file = argv[1];
                } else if (matches(argv[1], "link") == 0) {
-                       llink=1;
+                       llink = 1;
                        groups = 0;
                } else if (matches(argv[1], "address") == 0) {
-                       laddr=1;
+                       laddr = 1;
                        groups = 0;
                } else if (matches(argv[1], "route") == 0) {
-                       lroute=1;
+                       lroute = 1;
                        groups = 0;
                } else if (strcmp(argv[1], "all") == 0) {
                        groups = ~0U;
@@ -162,7 +163,7 @@ main(int argc, char **argv)
        if (rtnl_open(&rth, groups) < 0)
                exit(1);
 
-       if (rtnl_wilddump_request(&rth, AF_UNSPEC, RTM_GETLINK) < 0) {
+       if (rtnl_linkdump_req(&rth, AF_UNSPEC) < 0) {
                perror("Cannot send dump request");
                exit(1);
        }
@@ -176,7 +177,7 @@ main(int argc, char **argv)
 
        init_phase = 0;
 
-       if (rtnl_listen(&rth, dump_msg, (void*)fp) < 0)
+       if (rtnl_listen(&rth, dump_msg, (void *)fp) < 0)
                exit(2);
 
        exit(0);