defs.c revision 31203
1/* 2 * $Id: defs.c,v 1.3 1997/11/17 00:42:38 brian Exp $ 3 */ 4 5#include <sys/param.h> 6#include <netinet/in.h> 7 8#include <errno.h> 9#include <stdio.h> 10#include <stdlib.h> 11#include <string.h> 12#include <unistd.h> 13 14#include "defs.h" 15#include "mbuf.h" 16#include "log.h" 17#include "loadalias.h" 18#include "command.h" 19#include "vars.h" 20 21int mode = MODE_INTER; 22int BGFiledes[2] = { -1, -1 }; 23int modem = -1; 24int tun_in = -1; 25int tun_out = -1; 26int netfd = -1; 27 28static char dstsystem[50]; 29 30void 31SetLabel(const char *label) 32{ 33 if (label) 34 strncpy(dstsystem, label, sizeof dstsystem); 35 else 36 *dstsystem = '\0'; 37} 38 39const char * 40GetLabel() 41{ 42 return *dstsystem ? dstsystem : NULL; 43} 44 45void 46randinit() 47{ 48 static int initdone; 49 50 if (!initdone) { 51 initdone = 1; 52 srandomdev(); 53 } 54} 55 56 57int 58GetShortHost() 59{ 60 char *p; 61 62 if (gethostname(VarShortHost, sizeof(VarShortHost))) { 63 LogPrintf(LogERROR, "GetShortHost: gethostbyname: %s\n", strerror(errno)); 64 return 0; 65 } 66 67 if ((p = strchr(VarShortHost, '.'))) 68 *p = '\0'; 69 70 return 1; 71} 72 73void 74DropClient() 75{ 76 FILE *oVarTerm; 77 78 if (VarTerm && !(mode & MODE_INTER)) { 79 oVarTerm = VarTerm; 80 VarTerm = 0; 81 if (oVarTerm) 82 fclose(oVarTerm); 83 close(netfd); 84 netfd = -1; 85 LogPrintf(LogPHASE, "Client connection closed.\n"); 86 } 87} 88