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 void
cleanup(void) cleanup(void)
{ {
#ifndef __APPLE__
if (timestamp) stamptime(); if (timestamp) stamptime();
ssystem("ifconfig %s down", tundev); ssystem("ifconfig %s down", tundev);
#ifndef linux #ifndef linux
@ -557,6 +558,19 @@ cleanup(void)
" | awk '{ if ($2 == \"%s\") print \"route delete -net \"$1; }'" " | awk '{ if ($2 == \"%s\") print \"route delete -net \"$1; }'"
" | sh", " | sh",
tundev); 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 void
@ -642,7 +656,24 @@ ifconf(const char *tundev, const char *ipaddr)
ssystem("ifconfig %s add %s/64", tundev, lladdr); ssystem("ifconfig %s add %s/64", tundev, lladdr);
} }
#endif /* link local */ #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 #else
if (timestamp) stamptime(); if (timestamp) stamptime();
ssystem("ifconfig %s inet `hostname` %s up", tundev, ipaddr); 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,"usage: %s [options] ipaddress\n", prog);
fprintf(stderr,"example: tunslip6 -L -v2 -s ttyUSB1 aaaa::1/64\n"); fprintf(stderr,"example: tunslip6 -L -v2 -s ttyUSB1 aaaa::1/64\n");
fprintf(stderr,"Options are:\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," -H Hardware CTS/RTS flow control (default disabled)\n");
fprintf(stderr," -L Log output format (adds time stamps)\n"); fprintf(stderr," -L Log output format (adds time stamps)\n");
fprintf(stderr," -s siodev Serial device (default /dev/ttyUSB0)\n"); fprintf(stderr," -s siodev Serial device (default /dev/ttyUSB0)\n");
@ -783,12 +818,14 @@ exit(1);
case 230400: case 230400:
b_rate = B230400; b_rate = B230400;
break; break;
#ifndef __APPLE__
case 460800: case 460800:
b_rate = B460800; b_rate = B460800;
break; break;
case 921600: case 921600:
b_rate = B921600; b_rate = B921600;
break; break;
#endif
default: default:
err(1, "unknown baudrate %d", baudrate); err(1, "unknown baudrate %d", baudrate);
break; break;