Remove building with NOCRYPTO option
[minix3.git] / lib / libwrap / misc.c
blobc3d9016202562108328afcfefe969df8ac8fbf87
1 /* $NetBSD: misc.c,v 1.10 2012/03/21 10:10:37 matt Exp $ */
3 /*
4 * Misc routines that are used by tcpd and by tcpdchk.
5 *
6 * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
7 */
9 #include <sys/cdefs.h>
10 #ifndef lint
11 #if 0
12 static char sccsic[] = "@(#) misc.c 1.2 96/02/11 17:01:29";
13 #else
14 __RCSID("$NetBSD: misc.c,v 1.10 2012/03/21 10:10:37 matt Exp $");
15 #endif
16 #endif
18 #include <sys/types.h>
19 #include <sys/param.h>
20 #include <netinet/in.h>
21 #include <arpa/inet.h>
22 #include <stdio.h>
23 #include <string.h>
25 #include "tcpd.h"
27 /* xgets - fgets() with backslash-newline stripping */
29 char *
30 xgets(char *ptr, int len, FILE *fp)
32 int got;
33 char *start = ptr;
35 while (len > 1 && fgets(ptr, len, fp)) {
36 got = strlen(ptr);
37 if (got >= 1 && ptr[got - 1] == '\n') {
38 tcpd_context.line++;
39 if (got >= 2 && ptr[got - 2] == '\\') {
40 got -= 2;
41 } else {
42 return (start);
45 ptr += got;
46 len -= got;
47 ptr[0] = 0;
49 return (ptr > start ? start : 0);
52 /* split_at - break string at delimiter or return NULL */
54 char *
55 split_at(char *string, int delimiter)
57 char *cp;
58 int bracket;
60 bracket = 0;
61 for (cp = string; cp && *cp; cp++) {
62 switch (*cp) {
63 case '[':
64 bracket++;
65 break;
66 case ']':
67 bracket--;
68 break;
69 default:
70 if (bracket == 0 && *cp == delimiter) {
71 *cp++ = 0;
72 return cp;
74 break;
77 return NULL;
80 /* dot_quad_addr - convert dotted quad to internal form */
82 int
83 dot_quad_addr(char *str, unsigned long *addr)
85 struct in_addr a;
87 if (!inet_aton(str, &a))
88 return -1;
89 if (addr)
90 *addr = a.s_addr;
91 return 0;