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
parent
0b3c045a42
commit
44a469597a
10
sk.c
10
sk.c
|
@ -80,6 +80,16 @@ static int hwts_init(int fd, const char *device, int rx_filter, int one_step)
|
||||||
|
|
||||||
/* public methods */
|
/* 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)
|
int sk_interface_index(int fd, const char *name)
|
||||||
{
|
{
|
||||||
struct ifreq ifreq;
|
struct ifreq ifreq;
|
||||||
|
|
6
sk.h
6
sk.h
|
@ -39,6 +39,12 @@ struct sk_ts_info {
|
||||||
unsigned int rx_filters;
|
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.
|
* Obtain the numerical index from a network interface by name.
|
||||||
* @param fd An open socket.
|
* @param fd An open socket.
|
||||||
|
|
Loading…
Reference in New Issue