From 44a469597a70ca9135d400d6bcb958572c269d41 Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Fri, 29 Jul 2016 21:54:44 +0200 Subject: [PATCH] sk: Add a method to obtain a socket for utility purposes. 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 --- 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 @@ -39,6 +39,12 @@ struct sk_ts_info { unsigned int rx_filters; }; +/** + * 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.