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 <richardcochran@gmail.com>
master
Richard Cochran 2016-07-29 21:54:44 +02:00
parent 0b3c045a42
commit 44a469597a
2 changed files with 16 additions and 0 deletions

10
sk.c
View File

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

6
sk.h
View File

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