Unverified Commit cbeac323 authored by Simon Duquennoy's avatar Simon Duquennoy Committed by GitHub
Browse files

Merge pull request #148 from nfi/contrib/native-tun

Platform native: Avoid trying to use the tun when the tun is not available.
parents 77f4e75a 5c6117e6
......@@ -70,7 +70,7 @@ static char config_tundev[64] = "tun0";
#ifndef __CYGWIN__
static int tunfd;
static int tunfd = -1;
static int set_fd(fd_set *rset, fd_set *wset);
static void handle_fd(fd_set *rset, fd_set *wset);
......@@ -234,7 +234,7 @@ static int
tun_output(uint8_t *data, int len)
{
/* fprintf(stderr, "*** Writing to tun...%d\n", len); */
if(write(tunfd, data, len) != len) {
if(tunfd != -1 && write(tunfd, data, len) != len) {
err(1, "serial_to_tun: write");
return -1;
}
......@@ -245,8 +245,15 @@ static int
tun_input(unsigned char *data, int maxlen)
{
int size;
if((size = read(tunfd, data, maxlen)) == -1)
if(tunfd == -1) {
/* tun is not open */
return 0;
}
if((size = read(tunfd, data, maxlen)) == -1) {
err(1, "tun_input: read");
}
return size;
}
......@@ -267,6 +274,10 @@ output(const linkaddr_t *localdest)
static int
set_fd(fd_set *rset, fd_set *wset)
{
if(tunfd == -1) {
return 0;
}
FD_SET(tunfd, rset);
return 1;
}
......@@ -278,6 +289,11 @@ handle_fd(fd_set *rset, fd_set *wset)
{
int size;
if(tunfd == -1) {
/* tun is not open */
return;
}
LOG_INFO("Tun6-handle FD\n");
if(FD_ISSET(tunfd, rset)) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment