1997-12-21 12:11:13 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1997 Brian Somers <brian@Awfulhak.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
1997-12-24 09:29:17 +00:00
|
|
|
* $Id: defs.c,v 1.7 1997/12/23 22:38:53 brian Exp $
|
1997-10-26 01:04:02 +00:00
|
|
|
*/
|
|
|
|
|
1997-11-17 00:42:41 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
1997-10-26 01:04:02 +00:00
|
|
|
#include <stdlib.h>
|
1997-11-11 22:58:14 +00:00
|
|
|
#include <string.h>
|
1997-11-22 03:37:54 +00:00
|
|
|
#include <time.h>
|
1997-11-17 00:42:41 +00:00
|
|
|
#include <unistd.h>
|
1997-10-26 01:04:02 +00:00
|
|
|
|
|
|
|
#include "defs.h"
|
1997-11-22 03:37:54 +00:00
|
|
|
#include "command.h"
|
1997-11-17 00:42:41 +00:00
|
|
|
#include "mbuf.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "loadalias.h"
|
|
|
|
#include "vars.h"
|
1997-10-26 01:04:02 +00:00
|
|
|
|
|
|
|
int mode = MODE_INTER;
|
|
|
|
int BGFiledes[2] = { -1, -1 };
|
|
|
|
int modem = -1;
|
|
|
|
int tun_in = -1;
|
|
|
|
int tun_out = -1;
|
|
|
|
int netfd = -1;
|
1997-11-11 22:58:14 +00:00
|
|
|
|
|
|
|
static char dstsystem[50];
|
|
|
|
|
|
|
|
void
|
|
|
|
SetLabel(const char *label)
|
|
|
|
{
|
|
|
|
if (label)
|
1997-12-24 09:29:17 +00:00
|
|
|
strncpy(dstsystem, label, sizeof dstsystem - 1);
|
1997-11-11 22:58:14 +00:00
|
|
|
else
|
|
|
|
*dstsystem = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
GetLabel()
|
|
|
|
{
|
|
|
|
return *dstsystem ? dstsystem : NULL;
|
|
|
|
}
|
1997-10-26 01:04:02 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
randinit()
|
|
|
|
{
|
1997-11-22 03:37:54 +00:00
|
|
|
#ifdef __FreeBSD__
|
1997-10-26 01:04:02 +00:00
|
|
|
static int initdone;
|
|
|
|
|
|
|
|
if (!initdone) {
|
|
|
|
initdone = 1;
|
|
|
|
srandomdev();
|
|
|
|
}
|
1997-11-22 03:37:54 +00:00
|
|
|
#else
|
|
|
|
srandom(time(NULL)^getpid());
|
|
|
|
#endif
|
1997-10-26 01:04:02 +00:00
|
|
|
}
|
1997-11-17 00:42:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
GetShortHost()
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
|
1997-12-24 09:29:17 +00:00
|
|
|
if (gethostname(VarShortHost, sizeof VarShortHost)) {
|
1997-11-17 00:42:41 +00:00
|
|
|
LogPrintf(LogERROR, "GetShortHost: gethostbyname: %s\n", strerror(errno));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((p = strchr(VarShortHost, '.')))
|
|
|
|
*p = '\0';
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
1997-11-18 00:19:34 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
DropClient()
|
|
|
|
{
|
|
|
|
FILE *oVarTerm;
|
|
|
|
|
|
|
|
if (VarTerm && !(mode & MODE_INTER)) {
|
|
|
|
oVarTerm = VarTerm;
|
|
|
|
VarTerm = 0;
|
|
|
|
if (oVarTerm)
|
|
|
|
fclose(oVarTerm);
|
|
|
|
close(netfd);
|
|
|
|
netfd = -1;
|
|
|
|
LogPrintf(LogPHASE, "Client connection closed.\n");
|
|
|
|
}
|
|
|
|
}
|