1515#include <stdio.h>
1616#include <unistd.h>
1717#include <string.h>
18+ #include <errno.h>
1819#include <sys/ioctl.h>
1920#include <sys/socket.h>
2021#include <sys/types.h>
3132#include "os.h"
3233#include "netlink.h"
3334
35+ #ifndef HAVE_STRLCPY
36+ size_t strlcpy (char * __restrict dest ,
37+ const char * __restrict src , size_t destsize );
38+ #endif
39+
3440static int nhrp_socket_fd = -1 ;
3541
3642int os_socket (void )
@@ -42,7 +48,7 @@ int os_socket(void)
4248}
4349
4450int os_sendmsg (const uint8_t * buf , size_t len , int ifindex , const uint8_t * addr ,
45- size_t addrlen )
51+ size_t addrlen , uint16_t protocol )
4652{
4753 struct sockaddr_ll lladdr ;
4854 struct iovec iov = {
@@ -61,16 +67,16 @@ int os_sendmsg(const uint8_t *buf, size_t len, int ifindex, const uint8_t *addr,
6167
6268 memset (& lladdr , 0 , sizeof (lladdr ));
6369 lladdr .sll_family = AF_PACKET ;
64- lladdr .sll_protocol = htons (ETH_P_NHRP );
70+ lladdr .sll_protocol = htons (protocol );
6571 lladdr .sll_ifindex = ifindex ;
6672 lladdr .sll_halen = addrlen ;
6773 memcpy (lladdr .sll_addr , addr , addrlen );
6874
69- status = sendmsg (nhrp_socket_fd , & msg , 0 );
75+ status = sendmsg (os_socket () , & msg , 0 );
7076 if (status < 0 )
71- return -1 ;
77+ return - errno ;
7278
73- return 0 ;
79+ return status ;
7480}
7581
7682int os_recvmsg (uint8_t * buf , size_t * len , int * ifindex , uint8_t * addr ,
@@ -111,7 +117,7 @@ static int linux_configure_arp(const char *iface, int on)
111117{
112118 struct ifreq ifr ;
113119
114- strncpy (ifr .ifr_name , iface , IFNAMSIZ - 1 );
120+ strlcpy (ifr .ifr_name , iface , IFNAMSIZ );
115121 if (ioctl (nhrp_socket_fd , SIOCGIFFLAGS , & ifr ))
116122 return -1 ;
117123
0 commit comments