Skip to content
Snippets Groups Projects
Commit cb339590 authored by f4grx's avatar f4grx
Browse files

fix tun initialization

parent bd9ebb86
No related branches found
No related tags found
No related merge requests found
......@@ -39,7 +39,9 @@
#include <stdint.h>
#include <stdbool.h>
int hn70ap_tun_init(void);
#include <net/if.h>
int hn70ap_tun_init(char ifname[IFNAMSIZ]);
#endif /* HN70AP_SYSTEM_H */
......@@ -36,7 +36,7 @@
-include $(TOPDIR)/Make.defs
ASRCS =
CSRCS = eeprom.c leds.c lcd.c timer.c system.c radio.c
CSRCS = eeprom.c leds.c lcd.c timer.c system.c radio.c tun.c
CSRCS += tlv.c crc.c sha256.c hdlc.c
CSRCS += update.c
......
......@@ -43,6 +43,7 @@
#include <hn70ap/eeprom.h>
#include <hn70ap/timer.h>
#include <hn70ap/leds.h>
#include <hn70ap/lcd.h>
#include <hn70ap/radio.h>
#include <hn70ap/tun.h>
......@@ -52,6 +53,7 @@ int hn70ap_system_init(void)
{
int ret;
bool defaults;
char tunname[IFNAMSIZ];
if(hn70ap_system_initialized)
{
......@@ -103,7 +105,8 @@ int hn70ap_system_init(void)
syslog(LOG_ERR, "WARNING: Failed to initialize Radios\n");
}
ret = hn70ap_tun_init();
strcpy(tunname, "uhf%d");
ret = hn70ap_tun_init(tunname);
if(ret != 0)
{
syslog(LOG_ERR, "WARNING: Failed to initialize TUN interface\n");
......
......@@ -35,16 +35,41 @@
#include <nuttx/config.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
int hn70ap_tun_init(void)
#include <sys/ioctl.h>
#include <nuttx/net/tun.h>
#include <hn70ap/tun.h>
int hn70ap_tun_init(char ifname[IFNAMSIZ])
{
struct ifreq ifr;
int errcode;
int fd;
fd = open("/dev/tun", O_RDWR);
if ((fd = open("/dev/tun", O_RDWR)) < 0)
{
return fd;
}
memset(&ifr, 0, sizeof(ifr));
ifr.ifr_flags = IFF_TUN;
if (ifname[0])
{
strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
}
if ((errcode = ioctl(fd, TUNSETIFF, (unsigned long)&ifr)) < 0)
{
close(fd);
return errcode;
}
close(fd);
return 0;
return fd;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment