source: trunk/third/tcp_wrappers/misc.c @ 11717

Revision 11717, 1.6 KB checked in by danw, 26 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r11716, which included commits to RCS files with non-trunk default branches.
Line 
1 /*
2  * Misc routines that are used by tcpd and by tcpdchk.
3  *
4  * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
5  */
6
7#ifndef lint
8static char sccsic[] = "@(#) misc.c 1.2 96/02/11 17:01:29";
9#endif
10
11#include <sys/types.h>
12#include <sys/param.h>
13#include <netinet/in.h>
14#include <arpa/inet.h>
15#include <stdio.h>
16#include <string.h>
17
18#include "tcpd.h"
19
20extern char *fgets();
21
22#ifndef INADDR_NONE
23#define INADDR_NONE     (-1)            /* XXX should be 0xffffffff */
24#endif
25
26/* xgets - fgets() with backslash-newline stripping */
27
28char   *xgets(ptr, len, fp)
29char   *ptr;
30int     len;
31FILE   *fp;
32{
33    int     got;
34    char   *start = ptr;
35
36    while (fgets(ptr, len, fp)) {
37        got = strlen(ptr);
38        if (got >= 1 && ptr[got - 1] == '\n') {
39            tcpd_context.line++;
40            if (got >= 2 && ptr[got - 2] == '\\') {
41                got -= 2;
42            } else {
43                return (start);
44            }
45        }
46        ptr += got;
47        len -= got;
48        ptr[0] = 0;
49    }
50    return (ptr > start ? start : 0);
51}
52
53/* split_at - break string at delimiter or return NULL */
54
55char   *split_at(string, delimiter)
56char   *string;
57int     delimiter;
58{
59    char   *cp;
60
61    if ((cp = strchr(string, delimiter)) != 0)
62        *cp++ = 0;
63    return (cp);
64}
65
66/* dot_quad_addr - convert dotted quad to internal form */
67
68unsigned long dot_quad_addr(str)
69char   *str;
70{
71    int     in_run = 0;
72    int     runs = 0;
73    char   *cp = str;
74
75    /* Count the number of runs of non-dot characters. */
76
77    while (*cp) {
78        if (*cp == '.') {
79            in_run = 0;
80        } else if (in_run == 0) {
81            in_run = 1;
82            runs++;
83        }
84        cp++;
85    }
86    return (runs == 4 ? inet_addr(str) : INADDR_NONE);
87}
Note: See TracBrowser for help on using the repository browser.