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 $
7 * $DragonFly: src/contrib/tcp_wrappers/misc.c,v 1.2 2003/06/17 04:24:06 dillon Exp $
11 static char sccsic
[] = "@(#) misc.c 1.2 96/02/11 17:01:29";
14 #include <sys/types.h>
15 #include <sys/param.h>
16 #include <netinet/in.h>
17 #include <arpa/inet.h>
26 #define INADDR_NONE (-1) /* XXX should be 0xffffffff */
29 /* xgets - fgets() with backslash-newline stripping */
31 char *xgets(ptr
, len
, fp
)
39 while (fgets(ptr
, len
, fp
)) {
41 if (got
>= 1 && ptr
[got
- 1] == '\n') {
43 if (got
>= 2 && ptr
[got
- 2] == '\\') {
53 return (ptr
> start
? start
: 0);
56 /* split_at - break string at delimiter or return NULL */
58 char *split_at(string
, delimiter
)
67 for (cp
= string
; cp
&& *cp
; cp
++) {
76 if (bracket
== 0 && *cp
== delimiter
) {
85 if ((cp
= strchr(string
, delimiter
)) != 0)
91 /* dot_quad_addr - convert dotted quad to internal form */
93 unsigned long dot_quad_addr(str
)
100 /* Count the number of runs of non-dot characters. */
105 } else if (in_run
== 0) {
111 return (runs
== 4 ? inet_addr(str
) : INADDR_NONE
);