Mercurial > hg > anonet-resdb
annotate contrib/whoisd/as.c @ 1148:5c239f21ff7e draft
fixed a bug where I used a literal instead of one of the user defined variables (thx mkz)
author | epoch <epoch@hacking.allowed.org> |
---|---|
date | Mon, 04 Nov 2013 11:56:20 +0000 |
parents | da853b90f62b |
children |
rev | line source |
---|---|
1146
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
1 /* $NetBSD: as.c,v 1.2 2008/04/28 20:24:17 martin Exp $ */ |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
2 |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
3 /* |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
4 * Copyright (c) 2001 The NetBSD Foundation, Inc. |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
5 * All rights reserved. |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
6 * |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
7 * This code is derived from software contributed to The NetBSD Foundation |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
8 * by Andrew Brown. |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
9 * |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
10 * Redistribution and use in source and binary forms, with or without |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
11 * modification, are permitted provided that the following conditions |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
12 * are met: |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
13 * 1. Redistributions of source code must retain the above copyright |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
14 * notice, this list of conditions and the following disclaimer. |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
15 * 2. Redistributions in binary form must reproduce the above copyright |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
16 * notice, this list of conditions and the following disclaimer in the |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
17 * documentation and/or other materials provided with the distribution. |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
18 * |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
29 * POSSIBILITY OF SUCH DAMAGE. |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
30 */ |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
31 |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
32 #include <sys/cdefs.h> |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
33 #include <sys/types.h> |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
34 #include <sys/socket.h> |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
35 #include <netinet/in.h> |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
36 #include <arpa/inet.h> |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
37 #include <netdb.h> |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
38 #include <unistd.h> |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
39 #include <string.h> |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
40 #include <stdlib.h> |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
41 #include <errno.h> |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
42 #include <err.h> |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
43 #include <stdio.h> |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
44 |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
45 #include "as.h" |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
46 |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
47 #define DEFAULT_AS_SERVER "whois.radb.net" |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
48 #undef AS_DEBUG_FILE |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
49 |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
50 struct aslookup { |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
51 FILE *as_f; |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
52 #ifdef AS_DEBUG_FILE |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
53 FILE *as_debug; |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
54 #endif /* AS_DEBUG_FILE */ |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
55 }; |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
56 |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
57 void * |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
58 as_setup(server) |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
59 char *server; |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
60 { |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
61 struct aslookup *asn; |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
62 struct hostent *he = NULL; |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
63 struct servent *se; |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
64 struct sockaddr_in in; |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
65 FILE *f; |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
66 int s; |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
67 |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
68 if (server == NULL) |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
69 server = DEFAULT_AS_SERVER; |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
70 |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
71 (void)memset(&in, 0, sizeof(in)); |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
72 in.sin_family = AF_INET; |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
73 in.sin_len = sizeof(in); |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
74 if ((se = getservbyname("whois", "tcp")) == NULL) { |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
75 warnx("warning: whois/tcp service not found"); |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
76 in.sin_port = ntohs(43); |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
77 } else |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
78 in.sin_port = se->s_port; |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
79 |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
80 if (inet_aton(server, &in.sin_addr) == 0 && |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
81 ((he = gethostbyname(server)) == NULL || |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
82 he->h_addr == NULL)) { |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
83 warnx("%s: %s", server, hstrerror(h_errno)); |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
84 return (NULL); |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
85 } |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
86 |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
87 if ((s = socket(PF_INET, SOCK_STREAM, 0)) == -1) { |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
88 warn("socket"); |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
89 return (NULL); |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
90 } |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
91 |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
92 do { |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
93 if (he != NULL) { |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
94 memcpy(&in.sin_addr, he->h_addr, he->h_length); |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
95 he->h_addr_list++; |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
96 } |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
97 if (connect(s, (struct sockaddr *)&in, sizeof(in)) == 0) |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
98 break; |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
99 if (he == NULL || he->h_addr == NULL) { |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
100 close(s); |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
101 s = -1; |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
102 break; |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
103 } |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
104 } while (1); |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
105 |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
106 if (s == -1) { |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
107 warn("connect"); |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
108 return (NULL); |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
109 } |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
110 |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
111 f = fdopen(s, "r+"); |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
112 (void)fprintf(f, "!!\n"); |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
113 (void)fflush(f); |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
114 |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
115 asn = malloc(sizeof(struct aslookup)); |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
116 if (asn == NULL) |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
117 (void)fclose(f); |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
118 else |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
119 asn->as_f = f; |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
120 |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
121 #ifdef AS_DEBUG_FILE |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
122 asn->as_debug = fopen(AS_DEBUG_FILE, "w"); |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
123 if (asn->as_debug) { |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
124 (void)fprintf(asn->as_debug, ">> !!\n"); |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
125 (void)fflush(asn->as_debug); |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
126 } |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
127 #endif /* AS_DEBUG_FILE */ |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
128 |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
129 return (asn); |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
130 } |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
131 |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
132 int |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
133 as_lookup(_asn, addr) |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
134 void *_asn; |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
135 struct in_addr *addr; |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
136 { |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
137 struct aslookup *asn = _asn; |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
138 char buf[1024]; |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
139 int as, rc, dlen; |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
140 |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
141 as = rc = dlen = 0; |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
142 (void)fprintf(asn->as_f, "!r%s/32,l\n", inet_ntoa(*addr)); |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
143 (void)fflush(asn->as_f); |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
144 |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
145 #ifdef AS_DEBUG_FILE |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
146 if (asn->as_debug) { |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
147 (void)fprintf(asn->as_debug, ">> !r%s/32,l\n", |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
148 inet_ntoa(*addr)); |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
149 (void)fflush(asn->as_debug); |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
150 } |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
151 #endif /* AS_DEBUG_FILE */ |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
152 |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
153 while (fgets(buf, sizeof(buf), asn->as_f) != NULL) { |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
154 buf[sizeof(buf) - 1] = '\0'; |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
155 |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
156 #ifdef AS_DEBUG_FILE |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
157 if (asn->as_debug) { |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
158 (void)fprintf(asn->as_debug, "<< %s", buf); |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
159 (void)fflush(asn->as_debug); |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
160 } |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
161 #endif /* AS_DEBUG_FILE */ |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
162 |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
163 if (rc == 0) { |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
164 rc = buf[0]; |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
165 switch (rc) { |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
166 case 'A': |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
167 /* A - followed by # bytes of answer */ |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
168 sscanf(buf, "A%d\n", &dlen); |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
169 #ifdef AS_DEBUG_FILE |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
170 if (asn->as_debug) { |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
171 (void)fprintf(asn->as_debug, |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
172 "dlen: %d\n", dlen); |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
173 (void)fflush(asn->as_debug); |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
174 } |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
175 #endif /* AS_DEBUG_FILE */ |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
176 break; |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
177 case 'C': |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
178 case 'D': |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
179 case 'E': |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
180 case 'F': |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
181 /* C - no data returned */ |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
182 /* D - key not found */ |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
183 /* E - multiple copies of key */ |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
184 /* F - some other error */ |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
185 break; |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
186 } |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
187 if (rc == 'A') |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
188 /* skip to next input line */ |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
189 continue; |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
190 } |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
191 |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
192 if (dlen == 0) |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
193 /* out of data, next char read is end code */ |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
194 rc = buf[0]; |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
195 if (rc != 'A') |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
196 /* either an error off the bat, or a done code */ |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
197 break; |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
198 |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
199 /* data received, thank you */ |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
200 dlen -= strlen(buf); |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
201 |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
202 /* origin line is the interesting bit */ |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
203 if (as == 0 && strncasecmp(buf, "origin:", 7) == 0) { |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
204 sscanf(buf + 7, " AS%d", &as); |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
205 #ifdef AS_DEBUG_FILE |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
206 if (asn->as_debug) { |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
207 (void)fprintf(asn->as_debug, "as: %d\n", as); |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
208 (void)fflush(asn->as_debug); |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
209 } |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
210 #endif /* AS_DEBUG_FILE */ |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
211 } |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
212 } |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
213 |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
214 return (as); |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
215 } |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
216 |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
217 void |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
218 as_shutdown(_asn) |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
219 void *_asn; |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
220 { |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
221 struct aslookup *asn = _asn; |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
222 |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
223 (void)fprintf(asn->as_f, "!q\n"); |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
224 (void)fclose(asn->as_f); |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
225 |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
226 #ifdef AS_DEBUG_FILE |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
227 if (asn->as_debug) { |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
228 (void)fprintf(asn->as_debug, ">> !q\n"); |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
229 (void)fclose(asn->as_debug); |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
230 } |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
231 #endif /* AS_DEBUG_FILE */ |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
232 |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
233 free(asn); |
da853b90f62b
Added mkz to anonet and as many of the needed files as I could think of.
epoch <epoch@hacking.allowed.org>
parents:
diff
changeset
|
234 } |