struct sockaddr_in *addr = (struct sockaddr_in *) &route.rt_gateway;
addr->sin_family = AF_INET;
addr->sin_addr.s_addr = inet_addr (local_address);
- if (addr->sin_addr.s_addr == INADDR_NONE) {
- VERBOSE (mapec, ERROR, PRINTF ("can't find host '%s'\n", local_address));
- errno = EHOSTUNREACH;
- return -1;
- }
+ /* no check needed */
addr = (struct sockaddr_in *) &route.rt_dst;
addr->sin_family = AF_INET;
addr->sin_addr.s_addr = inet_addr (remote_address);
return -1;
}
- int fid;
+ int fid = -1;
switch (mapec.type) {
case MAPEC_udp_e:
fid = connect_udp (&mapec, arg1 + rc, (arg2) ? arg2 + rc : NULL);
case MAPEC_tun_e:
fid = connect_tun (&mapec, arg1 + rc, (arg2) ? arg2 + rc : NULL, (arg3) ? arg3 + rc : NULL);
break;
-
- default:
- fid = -1;
+ case MAPEC_error_e:
}
if (fid >= 0) {
VERBOSE (mapec, TRACE, PRINTF ("MAPEC_Close\n"));
- if ((fid < 0) || (fid >= MAX_MAPEC_NUMBER)) {
- return;
+ if ((fid >= 0) || (fid < MAX_MAPEC_NUMBER)) {
+ close (fid);
}
- close (fid);
-
free (MAPEC_list[fid]);
MAPEC_list[fid] = NULL;
}
int rc = read (fid, buffer, maxlen);
- if ((rc < 0) && (errno == EAGAIN)) {
- rc = 0;
- }
-
- return rc;
+ return ((rc < 0) && (errno == EAGAIN)) ? 0 : rc;
}
/* vim: set ts=4 sw=4 si et: */
VERBOSE (ulvpn, DEBUG, PRINTF ("sent to tun %d bytes\n", r));
}
}
- } else {
- VERBOSE (ulvpn, ERROR, PRINTF ("select error\n"));
- break;
}
rc = 0;
/* test: ulvpn.exe -v 2>&1 | grep 'verbose level not specified' */
/* test: ulvpn.exe -V 2>&1 | grep 'verbose level not specified' */
+/* test: sudo `awk -F: '/sh$/ && $3 != 0 {print $1; exit}' /etc/passwd` ulvpn.exe; test $? -ne 0 */
+
/* test: ulvpn.exe -d tun://tun0:-1; test $? -ne 0 */
+/* test: ulvpn.exe -d tun://tun1; test $? -ne 0 */
+/* test: ulvpn.exe -d tun://foo0; test $? -ne 0 */
+/* test: ulvpn.exe -d tun://tun0:100000; test $? -ne 0 */
/* test: ulvpn.exe -l udp://localhost:1234; test $? -ne 0 */
/* test: ulvpn.exe -l tun://nohost.nowhere; test $? -ne 0 */
/* test: ulvpn.exe -r udp://localhost:1234; test $? -ne 0 */
-/* test: ulvpn.exe -t tun://nohost.nowhere; test $? -ne 0 */
+/* test: ulvpn.exe -r tun://nohost.nowhere:1234; test $? -ne 0 */
+/* test: ulvpn.exe -t tun://localhost:; test $? -ne 0 */
/* test: ulvpn.exe -t udp://nohost.nowhere:1234; test $? -ne 0 */
+/* test: ulvpn.exe -t udp://localhost; test $? -ne 0 */
+/* test: ulvpn.exe -t udp://:1234; test $? -ne 0 */
/* test: ulvpn.exe -t udp://localhost:-1; test $? -ne 0 */
/* test: ulvpn.exe -u tun://localhost; test $? -ne 0 */
/* test: ulvpn.exe -u udp://nohost.nowhere:1235; test $? -ne 0 */
/* test: ulvpn.exe -u udp://localhost:-1; test $? -ne 0 */
-/* test: ulvpn.exe -v 5 & pid=$!; sleep 1; ip route list dev tun0; rc=$?; sleep 1; kill -TERM $pid; test $rc -eq 0 */
-
-/* test: ulvpn.exe -v 5 -V 5 -d tun://tun0:1496 & pid=$!; sleep 1; ping -c 1 -W 1 10.2.1.1; kill -TERM $pid */
+/* test: ulvpn.exe -v 5 -V 5 & pid=$!; sleep 1; ip route list dev tun0; rc=$?; sleep 1; kill -INT $pid; test $rc -eq 0 */
-/* test: ulvpn.exe -v 5 -t udp://localhost:1234 -u udp://localhost:1235 & pid1=$!; sleep 1; nc -ul 1235 > pcap & pid2=$!; sleep 1; echo TEST | nc -Nuq0 10.2.1.1 3000; sleep 1; kill -TERM $pid1 $pid2; strings pcap | grep -q TEST */
+/* test: ulvpn.exe -v 5 -t udp://\*:1234 -u udp://localhost:1235 & pid1=$!; sleep 1; nc -ul 1235 > pcap & pid2=$!; sleep 1; echo TEST | nc -Nuq0 10.2.1.1 3000; sleep 1; kill -TERM $pid1 $pid2; strings pcap | grep -q TEST */
/* test: ulvpn.exe -v 5 -l tun://10.2.1.1 -r tun://10.2.0.0 -t udp://localhost:1234 -u udp://localhost:1235 & pid1=$!; sleep 1; nc -ul 3000 > text & pid2=$!; sleep 1; cat pcap | nc -4Nuq0 -p 1235 localhost 1234; sleep 1; kill -TERM $pid1 $pid2; test "$(cat text)" = TEST */
/* test: rm -f pcap text */