2002-12-03 01:08:44 +03:00
|
|
|
/* $NetBSD: misc.c,v 1.9 2002/12/02 22:08:44 jdolecek Exp $ */
|
1997-10-10 01:20:16 +04:00
|
|
|
|
1996-11-26 19:48:08 +03:00
|
|
|
/*
|
|
|
|
* Misc routines that are used by tcpd and by tcpdchk.
|
1999-07-03 16:30:16 +04:00
|
|
|
*
|
1996-11-26 19:48:08 +03:00
|
|
|
* Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
|
|
|
|
*/
|
|
|
|
|
1997-10-10 01:20:16 +04:00
|
|
|
#include <sys/cdefs.h>
|
1996-11-26 19:48:08 +03:00
|
|
|
#ifndef lint
|
1997-10-10 01:20:16 +04:00
|
|
|
#if 0
|
1996-11-26 19:48:08 +03:00
|
|
|
static char sccsic[] = "@(#) misc.c 1.2 96/02/11 17:01:29";
|
1997-10-10 01:20:16 +04:00
|
|
|
#else
|
2002-12-03 01:08:44 +03:00
|
|
|
__RCSID("$NetBSD: misc.c,v 1.9 2002/12/02 22:08:44 jdolecek Exp $");
|
1997-10-10 01:20:16 +04:00
|
|
|
#endif
|
1996-11-26 19:48:08 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "tcpd.h"
|
|
|
|
|
|
|
|
/* xgets - fgets() with backslash-newline stripping */
|
|
|
|
|
|
|
|
char *xgets(ptr, len, fp)
|
|
|
|
char *ptr;
|
|
|
|
int len;
|
|
|
|
FILE *fp;
|
|
|
|
{
|
|
|
|
int got;
|
|
|
|
char *start = ptr;
|
|
|
|
|
2002-12-03 01:08:44 +03:00
|
|
|
while (len > 1 && fgets(ptr, len, fp)) {
|
1996-11-26 19:48:08 +03:00
|
|
|
got = strlen(ptr);
|
|
|
|
if (got >= 1 && ptr[got - 1] == '\n') {
|
|
|
|
tcpd_context.line++;
|
|
|
|
if (got >= 2 && ptr[got - 2] == '\\') {
|
|
|
|
got -= 2;
|
|
|
|
} else {
|
|
|
|
return (start);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ptr += got;
|
|
|
|
len -= got;
|
|
|
|
ptr[0] = 0;
|
|
|
|
}
|
|
|
|
return (ptr > start ? start : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* split_at - break string at delimiter or return NULL */
|
|
|
|
|
|
|
|
char *split_at(string, delimiter)
|
|
|
|
char *string;
|
|
|
|
int delimiter;
|
|
|
|
{
|
1999-08-31 17:58:58 +04:00
|
|
|
char *cp;
|
|
|
|
int bracket;
|
|
|
|
|
|
|
|
bracket = 0;
|
|
|
|
for (cp = string; cp && *cp; cp++) {
|
|
|
|
switch (*cp) {
|
|
|
|
case '[':
|
|
|
|
bracket++;
|
|
|
|
break;
|
|
|
|
case ']':
|
|
|
|
bracket--;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (bracket == 0 && *cp == delimiter) {
|
|
|
|
*cp++ = 0;
|
|
|
|
return cp;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
1996-11-26 19:48:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* dot_quad_addr - convert dotted quad to internal form */
|
|
|
|
|
1999-05-09 20:03:10 +04:00
|
|
|
int dot_quad_addr(str, addr)
|
1996-11-26 19:48:08 +03:00
|
|
|
char *str;
|
1999-05-09 20:03:10 +04:00
|
|
|
unsigned long *addr;
|
1996-11-26 19:48:08 +03:00
|
|
|
{
|
1999-05-09 20:03:10 +04:00
|
|
|
struct in_addr a;
|
1996-11-26 19:48:08 +03:00
|
|
|
|
1999-05-09 20:03:10 +04:00
|
|
|
if (!inet_aton(str, &a))
|
|
|
|
return -1;
|
1999-05-09 20:07:56 +04:00
|
|
|
if (addr)
|
|
|
|
*addr = a.s_addr;
|
1999-05-09 20:03:10 +04:00
|
|
|
return 0;
|
1996-11-26 19:48:08 +03:00
|
|
|
}
|