X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fraw_socket_device.c;h=1c455e6a748412b705ae748fef05ca7b8b251354;hb=9e7b3e5dd0d950790c1cc44be8e4716a7ed2e8f2;hp=0ac970cf4cae56641c651cfd80eabde2130c3d8a;hpb=f6e87ab476a0faf8b124ecaaa27f967d825e6457;p=tinc diff --git a/src/raw_socket_device.c b/src/raw_socket_device.c index 0ac970cf..1c455e6a 100644 --- a/src/raw_socket_device.c +++ b/src/raw_socket_device.c @@ -28,40 +28,35 @@ #include "device.h" #include "net.h" #include "logger.h" -#include "utils.h" -#include "route.h" #include "xalloc.h" #if defined(PF_PACKET) && defined(ETH_P_ALL) && defined(AF_PACKET) && defined(SIOCGIFINDEX) -static char *device_info; +static const char *device_info = "raw_socket"; static bool setup_device(void) { - struct ifreq ifr; - struct sockaddr_ll sa; + struct ifreq ifr = {0}; + struct sockaddr_ll sa = {0}; - if(!get_config_string(lookup_config(config_tree, "Interface"), &iface)) { + if(!get_config_string(lookup_config(&config_tree, "Interface"), &iface)) { iface = xstrdup("eth0"); } - if(!get_config_string(lookup_config(config_tree, "Device"), &device)) { + if(!get_config_string(lookup_config(&config_tree, "Device"), &device)) { device = xstrdup(iface); } - device_info = "raw socket"; - if((device_fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL))) < 0) { logger(DEBUG_ALWAYS, LOG_ERR, "Could not open %s: %s", device_info, strerror(errno)); return false; } - memset(&ifr, 0, sizeof(ifr)); - #ifdef FD_CLOEXEC fcntl(device_fd, F_SETFD, FD_CLOEXEC); #endif strncpy(ifr.ifr_ifrn.ifrn_name, iface, IFNAMSIZ); + ifr.ifr_ifrn.ifrn_name[IFNAMSIZ - 1] = 0; if(ioctl(device_fd, SIOCGIFINDEX, &ifr)) { close(device_fd); @@ -70,7 +65,6 @@ static bool setup_device(void) { return false; } - memset(&sa, '0', sizeof(sa)); sa.sll_family = AF_PACKET; sa.sll_protocol = htons(ETH_P_ALL); sa.sll_ifindex = ifr.ifr_ifindex; @@ -97,7 +91,7 @@ static void close_device(void) { } static bool read_packet(vpn_packet_t *packet) { - int inlen; + ssize_t inlen; if((inlen = read(device_fd, DATA(packet), MTU)) <= 0) { logger(DEBUG_ALWAYS, LOG_ERR, "Error while reading from %s %s: %s", device_info,