]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
Use one func to print timestamp from nlmsg
authorVadim Kochan <vadim4j@gmail.com>
Tue, 13 Jan 2015 18:14:24 +0000 (20:14 +0200)
committerStephen Hemminger <shemming@brocade.com>
Wed, 14 Jan 2015 01:34:47 +0000 (17:34 -0800)
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
bridge/monitor.c
include/utils.h
ip/ipmonitor.c
lib/utils.c

index f00e0a6b942fb94db3326a55a2d6dcb618468d36..9e1ed48c51419250f300759520aab1fe6f15eb81 100644 (file)
@@ -35,17 +35,6 @@ static void usage(void)
        exit(-1);
 }
 
-static int show_mark(FILE *fp, const struct nlmsghdr *n)
-{
-       char *tstr;
-       time_t secs = ((__u32*)NLMSG_DATA(n))[0];
-       long usecs = ((__u32*)NLMSG_DATA(n))[1];
-       tstr = asctime(localtime(&secs));
-       tstr[strlen(tstr)-1] = 0;
-       fprintf(fp, "Timestamp: %s %lu us\n", tstr, usecs);
-       return 0;
-}
-
 static int accept_msg(const struct sockaddr_nl *who,
                      struct nlmsghdr *n, void *arg)
 {
@@ -75,7 +64,8 @@ static int accept_msg(const struct sockaddr_nl *who,
                return print_mdb(who, n, arg);
 
        case NLMSG_TSTAMP:
-               return show_mark(fp, n);
+               print_nlmsg_timestamp(fp, n);
+               return 0;
 
        default:
                return 0;
index eecbc398b4d87c975cd9140785b5d7d1b873ed4e..e1fe7cfca715daa1cca3f79283662988697de99e 100644 (file)
@@ -148,6 +148,7 @@ static inline __u32 nl_mgrp(__u32 group)
 
 
 int print_timestamp(FILE *fp);
+void print_nlmsg_timestamp(FILE *fp, const struct nlmsghdr *n);
 
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
 
@@ -160,4 +161,5 @@ struct iplink_req;
 int iplink_parse(int argc, char **argv, struct iplink_req *req,
                char **name, char **type, char **link, char **dev,
                int *group, int *index);
+
 #endif /* __UTILS_H__ */
index f40daac0d72fb676231148719f9e87e94e15c768..5ec8f4181222bc4c45a32907a5a3070ee27ba68d 100644 (file)
@@ -126,12 +126,7 @@ static int accept_msg(const struct sockaddr_nl *who,
                return 0;
        }
        if (n->nlmsg_type == NLMSG_TSTAMP) {
-               char *tstr;
-               time_t secs = ((__u32*)NLMSG_DATA(n))[0];
-               long usecs = ((__u32*)NLMSG_DATA(n))[1];
-               tstr = asctime(localtime(&secs));
-               tstr[strlen(tstr)-1] = 0;
-               fprintf(fp, "Timestamp: %s %lu us\n", tstr, usecs);
+               print_nlmsg_timestamp(fp, n);
                return 0;
        }
        if (n->nlmsg_type != NLMSG_ERROR && n->nlmsg_type != NLMSG_NOOP &&
index 64915f3a92bd5f81b8b19ab56feb78c2d3da4ddb..f65ceaaf74032dcdf1fbdbbb1d6f11a0356bffe0 100644 (file)
@@ -868,3 +868,13 @@ int inet_get_addr(const char *src, __u32 *dst, struct in6_addr *dst6)
        else
                return inet_pton(AF_INET, src, dst);
 }
+
+void print_nlmsg_timestamp(FILE *fp, const struct nlmsghdr *n)
+{
+       char *tstr;
+       time_t secs = ((__u32*)NLMSG_DATA(n))[0];
+       long usecs = ((__u32*)NLMSG_DATA(n))[1];
+       tstr = asctime(localtime(&secs));
+       tstr[strlen(tstr)-1] = 0;
+       fprintf(fp, "Timestamp: %s %lu us\n", tstr, usecs);
+}