Also add a new parameter interface index incase we want to query specific
interface information.

Signed-off-by: Hangbin Liu <liuhang...@gmail.com>
---
 clock.c |  2 +-
 rtnl.c  | 12 +++++++-----
 rtnl.h  |  7 ++++---
 3 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/clock.c b/clock.c
index b6afba9..59b5f0c 100644
--- a/clock.c
+++ b/clock.c
@@ -1165,7 +1165,7 @@ struct clock *clock_create(enum clock_type type, struct 
config *config,
        }
        port_dispatch(c->uds_port, EV_INITIALIZE, 0);
        if (c->pollfd[0].fd >= 0) {
-               rtnl_link_query(c->pollfd[0].fd);
+               rtnl_link_query(c->pollfd[0].fd, 0);
        }
        return c;
 }
diff --git a/rtnl.c b/rtnl.c
index 5cddc4b..39faeb7 100644
--- a/rtnl.c
+++ b/rtnl.c
@@ -42,7 +42,7 @@ int rtnl_close(int fd)
        return close(fd);
 }
 
-int rtnl_link_query(int fd)
+int rtnl_link_query(int fd, unsigned int if_index)
 {
        struct sockaddr_nl sa;
        struct msghdr msg;
@@ -51,19 +51,21 @@ int rtnl_link_query(int fd)
 
        struct {
                struct nlmsghdr hdr;
-               struct rtgenmsg gen;
+               struct ifinfomsg ifm;
        } __attribute__((packed)) request;
 
        memset(&sa, 0, sizeof(sa));
        sa.nl_family = AF_NETLINK;
 
        memset(&request, 0, sizeof(request));
-       request.hdr.nlmsg_len = NLMSG_LENGTH(sizeof(request.gen));
+       request.hdr.nlmsg_len = NLMSG_LENGTH(sizeof(request.ifm));
        request.hdr.nlmsg_type = RTM_GETLINK;
-       request.hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP;
+       request.hdr.nlmsg_flags = NLM_F_REQUEST;
        request.hdr.nlmsg_seq = 1;
        request.hdr.nlmsg_pid = 0;
-       request.gen.rtgen_family = AF_UNSPEC;
+       request.ifm.ifi_family = AF_UNSPEC;
+       request.ifm.ifi_index = if_index;
+       request.ifm.ifi_change = 0xffffffff;
 
        iov.iov_base = &request;
        iov.iov_len = sizeof(request);
diff --git a/rtnl.h b/rtnl.h
index f1871f2..bd74cba 100644
--- a/rtnl.h
+++ b/rtnl.h
@@ -31,10 +31,11 @@ int rtnl_close(int fd);
 
 /**
  * Request the link status from the kernel.
- * @param fd  A socket obtained via rtnl_open().
- * @return    Zero on success, non-zero otherwise.
+ * @param fd     A socket obtained via rtnl_open().
+ * @param index  A interface index.
+ * @return       Zero on success, non-zero otherwise.
  */
-int rtnl_link_query(int fd);
+int rtnl_link_query(int fd, unsigned int index);
 
 /**
  * Read kernel messages looking for a link up/down events.
-- 
2.5.5


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to