2 * Misc routines that are used by tcpd and by tcpdchk.
4 * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
10 static char sccsic
[] = "@(#) misc.c 1.2 96/02/11 17:01:29";
13 #include <sys/types.h>
14 #include <sys/param.h>
15 #include <netinet/in.h>
16 #include <arpa/inet.h>
25 #define INADDR_NONE (-1) /* XXX should be 0xffffffff */
28 /* xgets - fgets() with backslash-newline stripping */
30 char *xgets(ptr
, len
, fp
)
38 while (fgets(ptr
, len
, fp
)) {
40 if (got
>= 1 && ptr
[got
- 1] == '\n') {
42 if (got
>= 2 && ptr
[got
- 2] == '\\') {
52 return (ptr
> start
? start
: 0);
55 /* split_at - break string at delimiter or return NULL */
57 char *split_at(string
, delimiter
)
66 for (cp
= string
; cp
&& *cp
; cp
++) {
75 if (bracket
== 0 && *cp
== delimiter
) {
84 if ((cp
= strchr(string
, delimiter
)) != 0)
90 /* dot_quad_addr - convert dotted quad to internal form */
92 unsigned long dot_quad_addr(str
)
99 /* Count the number of runs of non-dot characters. */
104 } else if (in_run
== 0) {
110 return (runs
== 4 ? inet_addr(str
) : INADDR_NONE
);