2 * Misc routines that are used by tcpd and by tcpdchk.
4 * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
6 * $FreeBSD: src/contrib/tcp_wrappers/misc.c,v 1.2 2000/02/03 10:26:58 shin Exp $
10 #include <sys/param.h>
11 #include <netinet/in.h>
12 #include <arpa/inet.h>
21 #define INADDR_NONE (-1) /* XXX should be 0xffffffff */
24 /* xgets - fgets() with backslash-newline stripping */
26 char *xgets(ptr
, len
, fp
)
34 while (len
> 1 && fgets(ptr
, len
, fp
)) {
36 if (got
>= 1 && ptr
[got
- 1] == '\n') {
38 if (got
>= 2 && ptr
[got
- 2] == '\\') {
48 return (ptr
> start
? start
: 0);
51 /* split_at - break string at delimiter or return NULL */
53 char *split_at(string
, delimiter
)
62 for (cp
= string
; cp
&& *cp
; cp
++) {
71 if (bracket
== 0 && *cp
== delimiter
) {
80 if ((cp
= strchr(string
, delimiter
)) != 0)
86 /* dot_quad_addr - convert dotted quad to internal form */
88 unsigned long dot_quad_addr(str
)
95 /* Count the number of runs of non-dot characters. */
100 } else if (in_run
== 0) {
106 return (runs
== 4 ? inet_addr(str
) : INADDR_NONE
);