NetBSD/lib/libwrap/misc.c

97 lines
1.7 KiB
C
Raw Normal View History

/* $NetBSD: misc.c,v 1.8 2002/05/24 05:38:20 itojun Exp $ */
1996-11-26 19:48:08 +03:00
/*
* Misc routines that are used by tcpd and by tcpdchk.
*
1996-11-26 19:48:08 +03:00
* Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
*/
#include <sys/cdefs.h>
1996-11-26 19:48:08 +03:00
#ifndef lint
#if 0
1996-11-26 19:48:08 +03:00
static char sccsic[] = "@(#) misc.c 1.2 96/02/11 17:01:29";
#else
__RCSID("$NetBSD: misc.c,v 1.8 2002/05/24 05:38:20 itojun Exp $");
#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;
while (fgets(ptr, len, fp)) {
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;
{
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 */
int dot_quad_addr(str, addr)
1996-11-26 19:48:08 +03:00
char *str;
unsigned long *addr;
1996-11-26 19:48:08 +03:00
{
struct in_addr a;
1996-11-26 19:48:08 +03:00
if (!inet_aton(str, &a))
return -1;
1999-05-09 20:07:56 +04:00
if (addr)
*addr = a.s_addr;
return 0;
1996-11-26 19:48:08 +03:00
}