X-Git-Url: https://tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Ffd_device.c;h=afe59bc2744b52356b8258c52e42c670b7030362;hp=67e0cb7809becb3302084f387a99bdb469825632;hb=de7d5a03c2b956ab5753faf63b8148a279a71f29;hpb=7a54fe5e884e98ade91af527c67f9c5df1452a50 diff --git a/src/fd_device.c b/src/fd_device.c index 67e0cb78..afe59bc2 100644 --- a/src/fd_device.c +++ b/src/fd_device.c @@ -64,7 +64,7 @@ static void close_device(void) { } static inline uint16_t get_ip_ethertype(vpn_packet_t *packet) { - switch (DATA(packet)[ETH_HLEN] >> 4) { + switch(DATA(packet)[ETH_HLEN] >> 4) { case 4: return ETH_P_IP; @@ -85,12 +85,14 @@ static inline void set_etherheader(vpn_packet_t *packet, uint16_t ethertype) { static bool read_packet(vpn_packet_t *packet) { int lenin = read(device_fd, DATA(packet) + ETH_HLEN, MTU - ETH_HLEN); + if(lenin <= 0) { logger(DEBUG_ALWAYS, LOG_ERR, "Error while reading from fd/%d: %s!", device_fd, strerror(errno)); return false; } uint16_t ethertype = get_ip_ethertype(packet); + if(ethertype == ETH_P_MAX) { logger(DEBUG_TRAFFIC, LOG_ERR, "Unknown IP version while reading packet from fd/%d!", device_fd); return false;