Blame sk.h

Packit 9c3e7e
/**
Packit 9c3e7e
 * @file sk.h
Packit 9c3e7e
 * @brief Implements protocol independent socket methods.
Packit 9c3e7e
 * @note Copyright (C) 2012 Richard Cochran <richardcochran@gmail.com>
Packit 9c3e7e
 *
Packit 9c3e7e
 * This program is free software; you can redistribute it and/or modify
Packit 9c3e7e
 * it under the terms of the GNU General Public License as published by
Packit 9c3e7e
 * the Free Software Foundation; either version 2 of the License, or
Packit 9c3e7e
 * (at your option) any later version.
Packit 9c3e7e
 *
Packit 9c3e7e
 * This program is distributed in the hope that it will be useful,
Packit 9c3e7e
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 9c3e7e
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 9c3e7e
 * GNU General Public License for more details.
Packit 9c3e7e
 *
Packit 9c3e7e
 * You should have received a copy of the GNU General Public License along
Packit 9c3e7e
 * with this program; if not, write to the Free Software Foundation, Inc.,
Packit 9c3e7e
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Packit 9c3e7e
 */
Packit 9c3e7e
#ifndef HAVE_SK_H
Packit 9c3e7e
#define HAVE_SK_H
Packit 9c3e7e
Packit 9c3e7e
#include "address.h"
Packit 9c3e7e
#include "transport.h"
Packit 9c3e7e
Packit 9c3e7e
/**
Packit 9c3e7e
 * Contains timestamping information returned by the GET_TS_INFO ioctl.
Packit 9c3e7e
 * @valid:            set to non-zero when the info struct contains valid data.
Packit 9c3e7e
 * @phc_index:        index of the PHC device.
Packit 9c3e7e
 * @so_timestamping:  supported time stamping modes.
Packit 9c3e7e
 * @tx_types:         driver level transmit options for the HWTSTAMP ioctl.
Packit 9c3e7e
 * @rx_filters:       driver level receive options for the HWTSTAMP ioctl.
Packit 9c3e7e
 */
Packit 9c3e7e
struct sk_ts_info {
Packit 9c3e7e
	int valid;
Packit 9c3e7e
	int phc_index;
Packit 9c3e7e
	unsigned int so_timestamping;
Packit 9c3e7e
	unsigned int tx_types;
Packit 9c3e7e
	unsigned int rx_filters;
Packit 9c3e7e
};
Packit 9c3e7e
Packit 9c3e7e
/**
Packit 9c3e7e
 * Obtains a socket suitable for use with sk_interface_index().
Packit 9c3e7e
 * @return  An open socket on success, -1 otherwise.
Packit 9c3e7e
 */
Packit 9c3e7e
int sk_interface_fd(void);
Packit 9c3e7e
Packit 9c3e7e
/**
Packit 9c3e7e
 * Obtain the numerical index from a network interface by name.
Packit 9c3e7e
 * @param fd      An open socket.
Packit 9c3e7e
 * @param device  The name of the network interface of interest.
Packit 9c3e7e
 * @return        The result from the SIOCGIFINDEX ioctl.
Packit 9c3e7e
 */
Packit 9c3e7e
int sk_interface_index(int fd, const char *device);
Packit 9c3e7e
Packit 9c3e7e
/**
Packit 9c3e7e
 * Prepare a given socket for PTP "general" messages.
Packit 9c3e7e
 * @param fd  An open socket.
Packit 9c3e7e
 * @return    Zero on success, non-zero otherwise.
Packit 9c3e7e
 */
Packit 9c3e7e
int sk_general_init(int fd);
Packit 9c3e7e
Packit 9c3e7e
/**
Packit 9c3e7e
 * Obtain supported timestamping information
Packit 9c3e7e
 * @param name	    The name of the interface
Packit 9c3e7e
 * @param info      Struct containing obtained timestamping information.
Packit 9c3e7e
 * @return          zero on success, negative on failure.
Packit 9c3e7e
 */
Packit 9c3e7e
int sk_get_ts_info(const char *name, struct sk_ts_info *sk_info);
Packit 9c3e7e
Packit 9c3e7e
/**
Packit 9c3e7e
 * Obtain the MAC address of a network interface.
Packit 9c3e7e
 * @param name  The name of the interface
Packit 9c3e7e
 * @param mac   Buffer to hold the result
Packit 9c3e7e
 * @return      Zero on success, non-zero otherwise.
Packit 9c3e7e
 */
Packit 9c3e7e
int sk_interface_macaddr(const char *name, struct address *mac);
Packit 9c3e7e
Packit 9c3e7e
/**
Packit 9c3e7e
 * Obtains the first IP address assigned to a network interface.
Packit 9c3e7e
 * @param name   The name of the interface
Packit 9c3e7e
 * @param family The family of the address to get: AF_INET or AF_INET6
Packit 9c3e7e
 * @param addr   Buffer to hold the result
Packit 9c3e7e
 * @return       The number of bytes written to addr on success, -1 otherwise.
Packit 9c3e7e
 */
Packit 9c3e7e
int sk_interface_addr(const char *name, int family, struct address *addr);
Packit 9c3e7e
Packit 9c3e7e
/**
Packit 9c3e7e
 * Read a message from a socket.
Packit 9c3e7e
 * @param fd      An open socket.
Packit 9c3e7e
 * @param buf     Buffer to receive the message.
Packit 9c3e7e
 * @param buflen  Size of 'buf' in bytes.
Packit 9c3e7e
 * @param addr    Pointer to a buffer to receive the message's source
Packit 9c3e7e
 *                address. May be NULL.
Packit 9c3e7e
 * @param hwts    Pointer to a buffer to receive the message's time stamp.
Packit 9c3e7e
 * @param flags   Flags to pass to RECV(2).
Packit 9c3e7e
 * @return
Packit 9c3e7e
 */
Packit 9c3e7e
int sk_receive(int fd, void *buf, int buflen,
Packit 9c3e7e
	       struct address *addr, struct hw_timestamp *hwts, int flags);
Packit 9c3e7e
Packit 9c3e7e
/**
Packit 9c3e7e
 * Set DSCP value for socket.
Packit 9c3e7e
 * @param fd    An open socket.
Packit 9c3e7e
 * @param dscp  The desired DSCP code.
Packit 9c3e7e
 * @return Zero on success, negative on failure
Packit 9c3e7e
 */
Packit 9c3e7e
int sk_set_priority(int fd, uint8_t dscp);
Packit 9c3e7e
Packit 9c3e7e
/**
Packit 9c3e7e
 * Enable time stamping on a given network interface.
Packit 9c3e7e
 * @param fd          An open socket.
Packit 9c3e7e
 * @param device      The name of the network interface to configure.
Packit 9c3e7e
 * @param type        The requested flavor of time stamping.
Packit 9c3e7e
 * @param transport   The type of transport used.
Packit 9c3e7e
 * @return            Zero on success, non-zero otherwise.
Packit 9c3e7e
 */
Packit 9c3e7e
int sk_timestamping_init(int fd, const char *device, enum timestamp_type type,
Packit 9c3e7e
			 enum transport_type transport);
Packit 9c3e7e
Packit 9c3e7e
/**
Packit 9c3e7e
 * Limits the time that RECVMSG(2) will poll while waiting for the tx timestamp
Packit 9c3e7e
 * if MSG_ERRQUEUE is set. Specified in milliseconds.
Packit 9c3e7e
 */
Packit 9c3e7e
extern int sk_tx_timeout;
Packit 9c3e7e
Packit 9c3e7e
/**
Packit 9c3e7e
 * Enables the SO_TIMESTAMPNS socket option on the both the event and
Packit 9c3e7e
 * general sockets in order to test the order of paired sync and
Packit 9c3e7e
 * follow up messages using their network stack receipt time stamps.
Packit 9c3e7e
 */
Packit 9c3e7e
extern int sk_check_fupsync;
Packit 9c3e7e
Packit 9c3e7e
#endif