Fix for baudrate and ifconfig on MacOS X

This commit is contained in:
Laurent Deru 2012-04-04 10:17:29 +02:00 committed by Niclas Finne
parent 40595ad5c7
commit d40b1116f8

View file

@ -546,6 +546,7 @@ tun_alloc(char *dev, int tap)
void
cleanup(void)
{
#ifndef __APPLE__
if (timestamp) stamptime();
ssystem("ifconfig %s down", tundev);
#ifndef linux
@ -557,6 +558,19 @@ cleanup(void)
" | awk '{ if ($2 == \"%s\") print \"route delete -net \"$1; }'"
" | sh",
tundev);
#else
{
char * itfaddr = strdup(ipaddr);
char * prefix = index(itfaddr, '/');
if (timestamp) stamptime();
ssystem("ifconfig %s inet6 %s remove", tundev, ipaddr);
if (timestamp) stamptime();
ssystem("ifconfig %s down", tundev);
if ( prefix != NULL ) *prefix = '\0';
ssystem("route delete -inet6 %s", itfaddr);
free(itfaddr);
}
#endif
}
void
@ -642,7 +656,24 @@ ifconf(const char *tundev, const char *ipaddr)
ssystem("ifconfig %s add %s/64", tundev, lladdr);
}
#endif /* link local */
#elif defined(__APPLE__)
{
char * itfaddr = strdup(ipaddr);
char * prefix = index(itfaddr, '/');
if ( prefix != NULL ) {
*prefix = '\0';
prefix++;
} else {
prefix = "64";
}
if (timestamp) stamptime();
ssystem("ifconfig %s inet6 up", tundev );
if (timestamp) stamptime();
ssystem("ifconfig %s inet6 %s add", tundev, ipaddr );
if (timestamp) stamptime();
ssystem("sysctl -w net.inet6.ip6.forwarding=1");
free(itfaddr);
}
#else
if (timestamp) stamptime();
ssystem("ifconfig %s inet `hostname` %s up", tundev, ipaddr);
@ -731,7 +762,11 @@ main(int argc, char **argv)
fprintf(stderr,"usage: %s [options] ipaddress\n", prog);
fprintf(stderr,"example: tunslip6 -L -v2 -s ttyUSB1 aaaa::1/64\n");
fprintf(stderr,"Options are:\n");
fprintf(stderr," -B baudrate 9600,19200,38400,57600,115200 default),230400,460800,921600\n");
#ifndef __APPLE__
fprintf(stderr," -B baudrate 9600,19200,38400,57600,115200 (default),230400,460800,921600\n");
#else
fprintf(stderr," -B baudrate 9600,19200,38400,57600,115200 (default),230400\n");
#endif
fprintf(stderr," -H Hardware CTS/RTS flow control (default disabled)\n");
fprintf(stderr," -L Log output format (adds time stamps)\n");
fprintf(stderr," -s siodev Serial device (default /dev/ttyUSB0)\n");
@ -783,12 +818,14 @@ exit(1);
case 230400:
b_rate = B230400;
break;
#ifndef __APPLE__
case 460800:
b_rate = B460800;
break;
case 921600:
b_rate = B921600;
break;
#endif
default:
err(1, "unknown baudrate %d", baudrate);
break;