version 1.35, 2005/09/13 23:40:07 |
version 1.36, 2005/12/06 22:38:27 |
|
|
return port; |
return port; |
} |
} |
|
|
|
int |
|
a2tun(const char *s, int *remote) |
|
{ |
|
const char *errstr = NULL; |
|
char *sp, *ep; |
|
int tun; |
|
|
|
if (remote != NULL) { |
|
*remote = -1; |
|
sp = xstrdup(s); |
|
if ((ep = strchr(sp, ':')) == NULL) { |
|
xfree(sp); |
|
return (a2tun(s, NULL)); |
|
} |
|
ep[0] = '\0'; ep++; |
|
*remote = a2tun(ep, NULL); |
|
tun = a2tun(sp, NULL); |
|
xfree(sp); |
|
return (tun); |
|
} |
|
|
|
if (strcasecmp(s, "any") == 0) |
|
return (-1); |
|
|
|
tun = strtonum(s, 0, INT_MAX, &errstr); |
|
if (errstr != NULL || tun < -1) |
|
return (-2); |
|
|
|
return (tun); |
|
} |
|
|
#define SECONDS 1 |
#define SECONDS 1 |
#define MINUTES (SECONDS * 60) |
#define MINUTES (SECONDS * 60) |
#define HOURS (MINUTES * 60) |
#define HOURS (MINUTES * 60) |
|
|
} |
} |
} |
} |
return -1; |
return -1; |
|
} |
|
|
|
int |
|
tun_open(int tun) |
|
{ |
|
char name[100]; |
|
int i, fd; |
|
|
|
if (tun > -1) { |
|
snprintf(name, sizeof(name), "/dev/tun%d", tun); |
|
if ((fd = open(name, O_RDWR)) >= 0) { |
|
debug("%s: %s: %d", __func__, name, fd); |
|
return (fd); |
|
} |
|
} else { |
|
for (i = 100; i >= 0; i--) { |
|
snprintf(name, sizeof(name), "/dev/tun%d", i); |
|
if ((fd = open(name, O_RDWR)) >= 0) { |
|
debug("%s: %s: %d", __func__, name, fd); |
|
return (fd); |
|
} |
|
} |
|
} |
|
debug("%s: %s failed: %s", __func__, name, strerror(errno)); |
|
return (-1); |
} |
} |
|
|
void |
void |