59 #ifndef CB_ETHERNET_H_ 60 #define CB_ETHERNET_H_ 62 #ifdef CB_ETHERNET_NON_POSIX_H 66 #include CB_ETHERNET_NON_POSIX_H 69 #include <sys/socket.h> 70 #include <sys/ioctl.h> 71 #include <netinet/in.h> 73 #include <net/if_arp.h> 76 #include <netpacket/packet.h> 77 #include <net/ethernet.h> 79 #define CB_MAX_NETDEVNAME IFNAMSIZ 80 #define CB_SOCKET_T int 81 #define CB_SOCKET_VALID(x) ((x)>=0) 82 #define CB_SOCKET_INVALID_VALUE -1 83 #define CB_ETHHDR_T struct ethhdr 84 #define CB_SOCKLEN_T socklen_t 85 #define CB_SOCKADDR_T struct sockaddr 86 #define CB_SOCKADDR_LL_T struct sockaddr_ll 87 #define CB_SOCKADDR_IN_T struct sockaddr_in 88 #define CB_SOCKADDR_IN6_T struct sockaddr_in6 89 #define CB_SOCKADDR_STORAGE_T struct sockaddr_storage 90 #define CB_IN_ADDR_T struct in_addr 91 #define CB_IN6_ADDR_T struct in6_addr 92 #define CB_IFREQ_T struct ifreq 95 #define CB_CLOSE close 96 #define CB_SOCKET socket 97 #define CB_IF_NAMETOINDEX if_nametoindex 98 #define CB_SOCK_BIND bind 99 #define CB_SOCK_IOCTL ioctl 100 #define CB_SOCK_CLOSE close 101 #define CB_SETSOCKOPT setsockopt 102 #define CB_SOCK_SENDTO sendto 103 #define CB_SOCK_RECVFROM recvfrom 104 #define CB_SOCK_RECVMSG recvmsg 105 #define CB_SOCK_WRITE write 106 #define CB_SOCK_CONNECT connect 108 #define CB_FCNTL fcntl 109 #define CB_FD_SET_T fd_set 110 #define CB_FDSET FD_SET 111 #define CB_FDCLR FD_CLR 112 #define CB_FDISSET FD_ISSET 113 #define CB_FDZERO FD_ZERO 115 #endif // CB_ETHERNET_NON_POSIX_H 123 #define CB_VIRTUAL_ETHDEV_PREFIX "cbeth" 129 #define CB_VIRTUAL_PTPDEV_PREFIX "cbptp" 135 #define CB_VIRTUAL_ETHDEV_MACU32 {0x02,0x01,0x45,0x10} 139 #define H_SOURCE h_source 143 #define H_DEST h_dest 147 #define H_PROTO h_proto 156 #define PTP_HEAD_MSGTYPE(x) ((*(uint8_t *) (&((uint8_t *)(x))[0])) & 0x0F) 161 #define PTP_HEAD_SEQID(x) ((((uint8_t *)(x))[30]<<8u)|(((uint8_t *)(x))[31])) 166 #define PTP_HEAD_DOMAIN_NUMBER(x) (*(uint8_t *)(&((uint8_t *)(x))[4])) 169 #define MAX_PTPDEV_NAME 32 195 typedef struct cb_rawsock_ovip_para {
210 typedef struct cb_rawsock_paras{
323 const unsigned char *mcastmac,
int del);
uint16_t vlanid
vlan identifier
Definition: cb_ethernet.h:218
uint32_t duplex
Definition: gptpipc.h:141
int priority
PCP priority value in VLAN tag.
Definition: cb_ethernet.h:214
cb_rawsock_ovip_para_t * ovipp
over-udp mode parameter
Definition: cb_ethernet.h:217
int cb_get_ptpdev_from_netdev(char *netdev, char *ptpdev)
find ptp device name from network device name
uint32_t rcvbuf
socket receive buffer size, set to 0 to use default value
Definition: cb_ethernet.h:220
uint32_t speed
Definition: gptpipc.h:140
int cb_sock_set_priority(CB_SOCKET_T fd, int priority)
set socket priority
int cb_get_mac_bydev(CB_SOCKET_T sfd, const char *dev, ub_macaddr_t bmac)
get mac address from device name like 'eth0'
int cb_get_all_netdevs(int maxdevnum, netdevname_t *netdevs)
get all network devices name availble in systems.
Definition: cb_ethernet.h:203
Definition: cb_ethernet.h:204
cb_sock_mode_t
Definition: cb_ethernet.h:202
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'
char ptpdevname_t[MAX_PTPDEV_NAME]
ptpdevice name.
Definition: cb_ethernet.h:173
Definition: cb_ethernet.h:189
cb_rawsock_rw_t rw_type
one of RAWSOCK_WRONLY, RAWSOCK_RDONLY, RAWSOCK_RDWR
Definition: cb_ethernet.h:215
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'
const char * dev
ethernet device name
Definition: cb_ethernet.h:211
uint16_t proto
protocol value like ETH_P_1588
Definition: cb_ethernet.h:212
char netdevname_t[CB_MAX_NETDEVNAME]
network device name.
Definition: cb_ethernet.h:226
int cb_expand_mtusize(CB_SOCKET_T fd, const char *dev, int *mtusize)
expand mtusize
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'
int cb_reg_multicast_address(CB_SOCKET_T fd, const char *dev, const unsigned char *mcastmac, int del)
register/deregister multicast address to receive
uint16_t lport
local IP port
Definition: cb_ethernet.h:197
uint32_t sndbuf
socket send buffer size, set to 0 to use default value
Definition: cb_ethernet.h:219
cb_rawsock_rw_t
this enumeration defines permission for raw socket.
Definition: cb_ethernet.h:186
uint32_t daddr
destination IP address
Definition: cb_ethernet.h:198
#define CB_SOCKET_T
Definition: cb_ethernet.h:80
Definition: cb_ethernet.h:187
#define CB_SOCKADDR_LL_T
Definition: cb_ethernet.h:86
uint64_t addr
Definition: csl_udmap_tr.h:216
ub_bytearray6_t ub_macaddr_t
6-byte binary array is used for MAC Address
Definition: ub_strutils.h:67
raw socket parameters.to open or create raw socket this structure must be filled.
Definition: cb_ethernet.h:210
#define CB_IN_ADDR_T
Definition: cb_ethernet.h:90
uint16_t dport
destination IP port
Definition: cb_ethernet.h:199
cb_sock_mode_t sock_mode
-1:raw socket over udp, 0:normal,
Definition: cb_ethernet.h:216
#define MAX_PTPDEV_NAME
maximum character number of ptp device name
Definition: cb_ethernet.h:169
int cb_get_netdev_from_ptpdev(char *ptpdev, char *netdev)
find network device name from ptp device name
#define CB_MAX_NETDEVNAME
Definition: cb_ethernet.h:79
Definition: cb_ethernet.h:188
int cb_rawsock_close(CB_SOCKET_T fd)
close the socket opened by cb_rawsock_open
int cb_get_ethtool_linkstate(CB_SOCKET_T cfd, const char *dev, uint32_t *linkstate)
get ethtool link state from device name like 'eth0'
int cb_set_promiscuous_mode(CB_SOCKET_T sfd, const char *dev, bool enable)
set the promiscuous mode on the socket
uint16_t vlan_proto
protocol value in VLAN tag, not used in non-tagged
Definition: cb_ethernet.h:213
uint32_t laddr
local IP address
Definition: cb_ethernet.h:196
char ptpdev[GPTPIPC_MAX_PTPDEV_NAME]
Definition: gptpipc.h:145
parameters to open the over IP mode raw socket, the values are in host order
Definition: cb_ethernet.h:195
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