The clock module will want to know the interface indexes, in order to
implement link monitoring.  However, the clock does not open any sockets
directly.  This helper function lets us keep the clock module free of
socket level code.

Signed-off-by: Richard Cochran <richardcoch...@gmail.com>
---
 sk.c | 10 ++++++++++
 sk.h |  6 ++++++
 2 files changed, 16 insertions(+)

diff --git a/sk.c b/sk.c
index ad30f71..63ec206 100644
--- a/sk.c
+++ b/sk.c
@@ -80,6 +80,16 @@ static int hwts_init(int fd, const char *device, int 
rx_filter, int one_step)
 
 /* public methods */
 
+int sk_interface_fd(void)
+{
+       int fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
+       if (fd < 0) {
+               pr_err("socket failed: %m");
+               return -1;
+       }
+       return fd;
+}
+
 int sk_interface_index(int fd, const char *name)
 {
        struct ifreq ifreq;
diff --git a/sk.h b/sk.h
index 31cc88e..d91d5d8 100644
--- a/sk.h
+++ b/sk.h
@@ -40,6 +40,12 @@ struct sk_ts_info {
 };
 
 /**
+ * Obtains a socket suitable for use with sk_interface_index().
+ * @return  An open socket on success, -1 otherwise.
+ */
+int sk_interface_fd(void);
+
+/**
  * Obtain the numerical index from a network interface by name.
  * @param fd      An open socket.
  * @param device  The name of the network interface of interest.
-- 
2.1.4


------------------------------------------------------------------------------
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