Files | |
file | cb_ethernet.h |
Bindings to POSIX network functions. | |
Data Structures | |
struct | cb_rawsock_ovip_para_t |
parameters to open the over IP mode raw socket, the values are in host order More... | |
struct | cb_rawsock_paras_t |
raw socket parameters.to open or create raw socket this structure must be filled. More... | |
Functions | |
int | cb_get_mac_bydev (CB_SOCKET_T sfd, const char *dev, ub_macaddr_t bmac) |
get mac address from device name like 'eth0' More... | |
int | cb_get_ip_bydev (CB_SOCKET_T sfd, const char *dev, CB_IN_ADDR_T *inp) |
get ip address from device name like 'eth0' More... | |
int | cb_get_brdip_bydev (CB_SOCKET_T sfd, const char *dev, CB_IN_ADDR_T *inp) |
get broadcast ip address from device name like 'eth0' More... | |
int | cb_rawsock_open (cb_rawsock_paras_t *llrawp, CB_SOCKET_T *fd, CB_SOCKADDR_LL_T *addr, int *mtusize, ub_macaddr_t bmac) |
generic raw ethernet open More... | |
int | cb_rawsock_close (CB_SOCKET_T fd) |
close the socket opened by cb_rawsock_open More... | |
int | cb_sock_set_priority (CB_SOCKET_T fd, int priority) |
set socket priority More... | |
int | cb_expand_mtusize (CB_SOCKET_T fd, const char *dev, int *mtusize) |
expand mtusize More... | |
int | cb_set_promiscuous_mode (CB_SOCKET_T sfd, const char *dev, bool enable) |
set the promiscuous mode on the socket More... | |
int | cb_reg_multicast_address (CB_SOCKET_T fd, const char *dev, const unsigned char *mcastmac, int del) |
register/deregister multicast address to receive More... | |
int | cb_get_all_netdevs (int maxdevnum, netdevname_t *netdevs) |
get all network devices name availble in systems. More... | |
int | cb_get_ethtool_linkstate (CB_SOCKET_T cfd, const char *dev, uint32_t *linkstate) |
get ethtool link state from device name like 'eth0' More... | |
int | cb_get_ethtool_info (CB_SOCKET_T cfd, const char *dev, uint32_t *speed, uint32_t *duplex) |
get ethtool info(speed and duplex) from device name like 'eth0' More... | |
int | cb_get_netdev_from_ptpdev (char *ptpdev, char *netdev) |
find network device name from ptp device name More... | |
int | cb_get_ptpdev_from_netdev (char *netdev, char *ptpdev) |
find ptp device name from network device name More... | |
Typedefs | |
typedef char | ptpdevname_t[MAX_PTPDEV_NAME] |
ptpdevice name. More... | |
typedef char | netdevname_t[CB_MAX_NETDEVNAME] |
network device name. More... | |
Enumerations | |
enum | cb_rawsock_rw_t { CB_RAWSOCK_RDWR = 0, CB_RAWSOCK_RDONLY, CB_RAWSOCK_WRONLY } |
this enumeration defines permission for raw socket. More... | |
enum | cb_sock_mode_t { CB_SOCK_MODE_OVIP = -1, CB_SOCK_MODE_NORMAL } |
Macros | |
#define | CB_MAX_NETDEVNAME IFNAMSIZ |
#define | CB_SOCKET_T int |
#define | CB_SOCKET_VALID(x) ((x)>=0) |
#define | CB_SOCKET_INVALID_VALUE -1 |
#define | CB_ETHHDR_T struct ethhdr |
#define | CB_SOCKLEN_T socklen_t |
#define | CB_SOCKADDR_T struct sockaddr |
#define | CB_SOCKADDR_LL_T struct sockaddr_ll |
#define | CB_SOCKADDR_IN_T struct sockaddr_in |
#define | CB_SOCKADDR_IN6_T struct sockaddr_in6 |
#define | CB_SOCKADDR_STORAGE_T struct sockaddr_storage |
#define | CB_IN_ADDR_T struct in_addr |
#define | CB_IN6_ADDR_T struct in6_addr |
#define | CB_IFREQ_T struct ifreq |
#define | CB_OPEN open |
#define | CB_CLOSE close |
#define | CB_WRITE write |
#define | CB_SOCKET socket |
#define | CB_IF_NAMETOINDEX if_nametoindex |
#define | CB_SOCK_BIND bind |
#define | CB_SOCK_IOCTL ioctl |
#define | CB_SOCK_CLOSE close |
#define | CB_SETSOCKOPT setsockopt |
#define | CB_SOCK_SENDTO sendto |
#define | CB_SELECT select |
#define | CB_SOCK_RECVFROM recvfrom |
#define | CB_SOCK_RECVMSG recvmsg |
#define | CB_SOCK_WRITE write |
#define | CB_SOCK_CONNECT connect |
#define | CB_FCNTL fcntl |
#define | CB_FD_SET_T fd_set |
#define | CB_FDSET FD_SET |
#define | CB_FDCLR FD_CLR |
#define | CB_FDISSET FD_ISSET |
#define | CB_FDZERO FD_ZERO |
#define | CB_VIRTUAL_ETHDEV_PREFIX "cbeth" |
prefix of virtual network device, which supports raw ethernet packet over udp More... | |
#define | CB_VIRTUAL_PTPDEV_PREFIX "cbptp" |
prefix of virtual ptp device. the suffix must be common with the virtual network device. More... | |
#define | CB_VIRTUAL_ETHDEV_MACU32 {0x02,0x01,0x45,0x10} |
virtual MAC address of the virtual network device. the lower 2 bytes are calculated from the suffix More... | |
#define | H_SOURCE h_source |
#define | H_DEST h_dest |
#define | H_PROTO h_proto |
#define | PTP_HEAD_MSGTYPE(x) ((*(uint8_t *) (&((uint8_t *)(x))[0])) & 0x0F) |
forms ptp header msgtype. More... | |
#define | PTP_HEAD_SEQID(x) ((((uint8_t *)(x))[30]<<8u)|(((uint8_t *)(x))[31])) |
macro which is used to form ptp header sequence id. More... | |
#define | PTP_HEAD_DOMAIN_NUMBER(x) (*(uint8_t *)(&((uint8_t *)(x))[4])) |
macro used to form ptp header domain number. More... | |
#define | MAX_PTPDEV_NAME 32 |
maximum character number of ptp device name More... | |
#define CB_MAX_NETDEVNAME IFNAMSIZ |
#define CB_SOCKET_T int |
#define CB_SOCKET_VALID | ( | x | ) | ((x)>=0) |
#define CB_SOCKET_INVALID_VALUE -1 |
#define CB_ETHHDR_T struct ethhdr |
#define CB_SOCKLEN_T socklen_t |
#define CB_SOCKADDR_T struct sockaddr |
#define CB_SOCKADDR_LL_T struct sockaddr_ll |
#define CB_SOCKADDR_IN_T struct sockaddr_in |
#define CB_SOCKADDR_IN6_T struct sockaddr_in6 |
#define CB_SOCKADDR_STORAGE_T struct sockaddr_storage |
#define CB_IN_ADDR_T struct in_addr |
#define CB_IN6_ADDR_T struct in6_addr |
#define CB_IFREQ_T struct ifreq |
#define CB_OPEN open |
#define CB_CLOSE close |
#define CB_WRITE write |
#define CB_SOCKET socket |
#define CB_IF_NAMETOINDEX if_nametoindex |
#define CB_SOCK_BIND bind |
#define CB_SOCK_IOCTL ioctl |
#define CB_SOCK_CLOSE close |
#define CB_SETSOCKOPT setsockopt |
#define CB_SOCK_SENDTO sendto |
#define CB_SELECT select |
#define CB_SOCK_RECVFROM recvfrom |
#define CB_SOCK_RECVMSG recvmsg |
#define CB_SOCK_WRITE write |
#define CB_SOCK_CONNECT connect |
#define CB_FCNTL fcntl |
#define CB_FD_SET_T fd_set |
#define CB_FDSET FD_SET |
#define CB_FDCLR FD_CLR |
#define CB_FDISSET FD_ISSET |
#define CB_FDZERO FD_ZERO |
#define CB_VIRTUAL_ETHDEV_PREFIX "cbeth" |
prefix of virtual network device, which supports raw ethernet packet over udp
#define CB_VIRTUAL_PTPDEV_PREFIX "cbptp" |
prefix of virtual ptp device. the suffix must be common with the virtual network device.
#define CB_VIRTUAL_ETHDEV_MACU32 {0x02,0x01,0x45,0x10} |
virtual MAC address of the virtual network device. the lower 2 bytes are calculated from the suffix
#define H_SOURCE h_source |
#define H_DEST h_dest |
#define H_PROTO h_proto |
#define PTP_HEAD_MSGTYPE | ( | x | ) | ((*(uint8_t *) (&((uint8_t *)(x))[0])) & 0x0F) |
forms ptp header msgtype.
#define PTP_HEAD_SEQID | ( | x | ) | ((((uint8_t *)(x))[30]<<8u)|(((uint8_t *)(x))[31])) |
macro which is used to form ptp header sequence id.
#define PTP_HEAD_DOMAIN_NUMBER | ( | x | ) | (*(uint8_t *)(&((uint8_t *)(x))[4])) |
macro used to form ptp header domain number.
#define MAX_PTPDEV_NAME 32 |
maximum character number of ptp device name
typedef char ptpdevname_t[MAX_PTPDEV_NAME] |
ptpdevice name.
typedef char netdevname_t[CB_MAX_NETDEVNAME] |
network device name.
enum cb_rawsock_rw_t |
enum cb_sock_mode_t |
int cb_get_mac_bydev | ( | CB_SOCKET_T | sfd, |
const char * | dev, | ||
ub_macaddr_t | bmac | ||
) |
get mac address from device name like 'eth0'
sfd | if sfd!=-1, pre-opened socket is used to get the mac. if sfd==-1, a newly opened udp socket is used to get the mac Address. |
dev | ethernet device name like 'eth0' |
bmac | refernce to buffer which is used to store mac address of ethernet device. |
int cb_get_ip_bydev | ( | CB_SOCKET_T | sfd, |
const char * | dev, | ||
CB_IN_ADDR_T * | inp | ||
) |
get ip address from device name like 'eth0'
sfd | if sfd!=-1, pre-opened socket is used to get the mac. if sfd==-1, a newly opened udp socket is used to get the MAC Address. |
dev | ethenert device name like 'eth0' |
inp | reference to 'CB_IN_ADDR_T' where IP address is saved |
int cb_get_brdip_bydev | ( | CB_SOCKET_T | sfd, |
const char * | dev, | ||
CB_IN_ADDR_T * | inp | ||
) |
get broadcast ip address from device name like 'eth0'
sfd | if sfd!=-1, pre-opened socket is used to get the mac. if sfd==-1, a newly opened udp socket is used. |
dev | ethenert device name like 'eth0' |
inp | reference to 'CB_IN_ADDR_T' where IP address is saved |
int cb_rawsock_open | ( | cb_rawsock_paras_t * | llrawp, |
CB_SOCKET_T * | fd, | ||
CB_SOCKADDR_LL_T * | addr, | ||
int * | mtusize, | ||
ub_macaddr_t | bmac | ||
) |
generic raw ethernet open
llrawp | cb_rawsock_paras_t -> raw socket open parameters, this parameter is passed as refernce to cb_rawsock_paras_t. |
fd | return a descriptor of opened socket |
addr | return sockaddr information which is used to open the socket |
mtusize | MTU size including ETH header size. if *mtusize>default size, try to resize MTU size. |
bmac | the mac address of 'dev' is returned in 'bmac' |
cb_rawsock_paras_t
int cb_rawsock_close | ( | CB_SOCKET_T | fd | ) |
close the socket opened by cb_rawsock_open
fd | descriptor of the opened socket |
int cb_sock_set_priority | ( | CB_SOCKET_T | fd, |
int | priority | ||
) |
set socket priority
fd | descriptor of the opened socket |
priority | priority number |
int cb_expand_mtusize | ( | CB_SOCKET_T | fd, |
const char * | dev, | ||
int * | mtusize | ||
) |
expand mtusize
fd | descriptor of the opened socket |
dev | ethernet device name like eth0 |
mtusize | new mtusize, return a new mtu size in *mtusize |
int cb_set_promiscuous_mode | ( | CB_SOCKET_T | sfd, |
const char * | dev, | ||
bool | enable | ||
) |
set the promiscuous mode on the socket
sfd | descriptor of the socket |
dev | ethernet device name like eth0 |
enable | true:enable, false:disable |
int cb_reg_multicast_address | ( | CB_SOCKET_T | fd, |
const char * | dev, | ||
const unsigned char * | mcastmac, | ||
int | del | ||
) |
register/deregister multicast address to receive
fd | descriptor of the socket |
dev | ethernet device name like eth0 |
mcastmac | multicast address |
del | 0:register 1:deregister |
int cb_get_all_netdevs | ( | int | maxdevnum, |
netdevname_t * | netdevs | ||
) |
get all network devices name availble in systems.
maxdevnum | number of devices presents in systems. |
netdevs | reference to netdevname_t which stores net devices name. |
int cb_get_ethtool_linkstate | ( | CB_SOCKET_T | cfd, |
const char * | dev, | ||
uint32_t * | linkstate | ||
) |
get ethtool link state from device name like 'eth0'
cfd | if cfd!=-1, pre-opened socket is used to get the ethtool info. if cfd==-1, a newly opened udp socket is used. |
dev | ethernet device name like 'eth0' |
linkstate | to store link state value (0:down, 1:up) |
int cb_get_ethtool_info | ( | CB_SOCKET_T | cfd, |
const char * | dev, | ||
uint32_t * | speed, | ||
uint32_t * | duplex | ||
) |
get ethtool info(speed and duplex) from device name like 'eth0'
cfd | if cfd!=-1, pre-opened socket is used to get the ethtool info. if cfd==-1, a newly opened udp socket is used. |
dev | ethenert device name like 'eth0' |
speed | to store speed value(0:unknow, 10:10Mbps, 100:100Mbps, 1000:1Gbps) |
duplex | to store duplex value(0:unknow, 1:Full, 2:Half) |
int cb_get_netdev_from_ptpdev | ( | char * | ptpdev, |
char * | netdev | ||
) |
find network device name from ptp device name
ptpdev | ptpdevice name(either format of '/dev/ptp0' or 'ptp0') |
netdev | the result of network device name, must have enough space |
int cb_get_ptpdev_from_netdev | ( | char * | netdev, |
char * | ptpdev | ||
) |
find ptp device name from network device name
netdev | network device name (like 'eth0') |
ptpdev | the result of ptpdevice name(like 'ptp0', no preceding '/dev/'), must have enough space. |