Zap any addresses on the network side of the `tun' as soon

as we've successfully opened the /dev side.
This commit is contained in:
brian 1998-01-08 23:47:57 +00:00
parent bcae2312af
commit b4fb282bcf
3 changed files with 40 additions and 3 deletions

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: main.c,v 1.114 1997/12/28 21:55:04 brian Exp $
* $Id: main.c,v 1.115 1997/12/30 23:22:29 brian Exp $
*
* TODO:
* o Add commands for traffic summary, version display, etc.
@ -428,6 +428,7 @@ main(int argc, char **argv)
LogPrintf(LogWARN, "OpenTunnel: %s\n", strerror(errno));
return EX_START;
}
CleanInterface(IfDevName);
if (mode & MODE_INTER)
fprintf(VarTerm, "Interactive mode\n");
else if ((mode & MODE_OUTGOING_DAEMON) && !(mode & MODE_DEDICATED))

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: os.c,v 1.37 1997/12/13 02:37:27 brian Exp $
* $Id: os.c,v 1.38 1997/12/24 09:29:09 brian Exp $
*
*/
#include <sys/param.h>
@ -170,6 +170,41 @@ SetIpDevice(struct in_addr myaddr,
return (0);
}
int
CleanInterface(const char *name)
{
int s;
s = ID0socket(AF_INET, SOCK_DGRAM, 0);
if (s < 0) {
LogPrintf(LogERROR, "SetIpDevice: socket(): %s\n", strerror(errno));
return (-1);
}
strncpy(ifrq.ifr_name, name, sizeof ifrq.ifr_name - 1);
ifrq.ifr_name[sizeof ifrq.ifr_name - 1] = '\0';
while (ID0ioctl(s, SIOCGIFADDR, &ifrq) == 0) {
memset(&ifra.ifra_mask, '\0', sizeof ifra.ifra_mask);
ifra.ifra_addr = ifrq.ifr_addr;
if (ID0ioctl(s, SIOCGIFDSTADDR, &ifrq) < 0) {
if (ifra.ifra_addr.sa_family == AF_INET)
LogPrintf(LogERROR, "tun_configure: Can't get dst for %s on %s !\n",
inet_ntoa(((struct sockaddr_in *)&ifra.ifra_addr)->sin_addr),
name);
return 0;
}
ifra.ifra_broadaddr = ifrq.ifr_dstaddr;
if (ID0ioctl(s, SIOCDIFADDR, &ifra) < 0) {
if (ifra.ifra_addr.sa_family == AF_INET)
LogPrintf(LogERROR, "tun_configure: Can't delete %s address on %s !\n",
inet_ntoa(((struct sockaddr_in *)&ifra.ifra_addr)->sin_addr),
name);
return 0;
}
}
return 1;
}
int
OsTrySetIpaddress(struct in_addr myaddr, struct in_addr hisaddr)
{

View File

@ -15,7 +15,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: os.h,v 1.12 1997/11/22 03:37:42 brian Exp $
* $Id: os.h,v 1.13 1997/12/13 02:37:30 brian Exp $
*
* TODO:
*/
@ -29,3 +29,4 @@ extern int OpenTunnel(int *);
extern void OsLinkup(void);
extern int OsLinkIsUp(void);
extern void OsLinkdown(void);
extern int CleanInterface(const char *);