defs.c revision 32021
1/*- 2 * Copyright (c) 1997 Brian Somers <brian@Awfulhak.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 * $Id: defs.c,v 1.8 1997/12/24 09:28:56 brian Exp $ 27 */ 28 29#include <sys/param.h> 30#include <netinet/in.h> 31 32#include <errno.h> 33#include <stdio.h> 34#include <stdlib.h> 35#include <string.h> 36#include <time.h> 37#include <unistd.h> 38 39#include "defs.h" 40#include "command.h" 41#include "mbuf.h" 42#include "log.h" 43#include "loadalias.h" 44#include "vars.h" 45 46int mode = MODE_INTER; 47int BGFiledes[2] = { -1, -1 }; 48int modem = -1; 49int tun_in = -1; 50int tun_out = -1; 51int netfd = -1; 52 53static char dstsystem[50]; 54 55void 56SetLabel(const char *label) 57{ 58 if (label) 59 strncpy(dstsystem, label, sizeof dstsystem - 1); 60 else 61 *dstsystem = '\0'; 62} 63 64const char * 65GetLabel() 66{ 67 return *dstsystem ? dstsystem : NULL; 68} 69 70void 71randinit() 72{ 73#ifdef __FreeBSD__ 74 static int initdone; 75 76 if (!initdone) { 77 initdone = 1; 78 srandomdev(); 79 } 80#else 81 srandom(time(NULL)^getpid()); 82#endif 83} 84 85 86int 87GetShortHost() 88{ 89 char *p; 90 91 if (gethostname(VarShortHost, sizeof VarShortHost)) { 92 LogPrintf(LogERROR, "GetShortHost: gethostbyname: %s\n", strerror(errno)); 93 return 0; 94 } 95 96 if ((p = strchr(VarShortHost, '.'))) 97 *p = '\0'; 98 99 return 1; 100} 101 102void 103DropClient(int verbose) 104{ 105 FILE *oVarTerm; 106 107 if (VarTerm && !(mode & MODE_INTER)) { 108 oVarTerm = VarTerm; 109 VarTerm = 0; 110 if (oVarTerm) 111 fclose(oVarTerm); 112 close(netfd); 113 netfd = -1; 114 if (verbose) 115 LogPrintf(LogPHASE, "Client connection dropped.\n"); 116 } 117} 118