]>
Commit | Line | Data |
---|---|---|
1d12ab62 | 1 | diff -urN eggdrop1.6.19/config.h.in eggdrop1.6.19-ipv6/config.h.in |
2 | --- config.h.in 2006-11-20 12:38:25.000000000 +0100 | |
3 | +++ config.h.in 2008-07-27 22:13:41.000000000 +0200 | |
4 | @@ -372,6 +372,9 @@ | |
5 | /* Define to `unsigned' if <sys/types.h> does not define. */ | |
6 | #undef size_t | |
7 | ||
8 | +/* Define if there is IPV6 */ | |
9 | +#define IPV6 | |
10 | + | |
11 | /* Define to empty if the keyword `volatile' does not work. Warning: valid | |
12 | code using `volatile' can become incorrect without. Disable with care. */ | |
13 | #undef volatile | |
14 | diff -urN eggdrop1.6.19/eggdrop.conf eggdrop1.6.19-ipv6/eggdrop.conf | |
15 | --- eggdrop.conf 2008-02-16 21:15:30.000000000 +0100 | |
16 | +++ eggdrop.conf 2008-07-27 22:13:43.000000000 +0200 | |
17 | @@ -56,7 +56,9 @@ | |
18 | # by hostname or by IP. You may also want to set the hostname here if | |
19 | # Eggdrop has trouble detecting it when it starts up. | |
20 | #set my-hostname "virtual.host.com" | |
21 | -#set my-ip "99.99.0.0" | |
22 | +#set my-ip "98.76.54.32" | |
23 | +#set my-hostname6 "virtual.host6.com" | |
24 | +#set my-ip6 "2002:624c:3620::1" | |
25 | ||
26 | # If you want to have your Eggdrop messages displayed in a language other | |
27 | # than English, change this setting to match your preference. An alternative | |
28 | diff -urN eggdrop1.6.19/src/botnet.c eggdrop1.6.19-ipv6/src/botnet.c | |
29 | --- src/botnet.c 2008-02-16 22:41:03.000000000 +0100 | |
30 | +++ src/botnet.c 2008-07-27 22:13:40.000000000 +0200 | |
31 | @@ -1063,7 +1063,7 @@ | |
32 | strcpy(dcc[i].u.bot->version, "(primitive bot)"); | |
33 | dcc[i].u.bot->numver = idx; | |
34 | dcc[i].u.bot->port = dcc[i].port; /* Remember where i started */ | |
35 | - dcc[i].sock = getsock(SOCK_STRONGCONN); | |
36 | + dcc[i].sock = getsock(SOCK_STRONGCONN,getprotocol(dcc[i].host)); | |
37 | nfree(linker); | |
38 | if (dcc[i].sock < 0 || | |
39 | open_telnet_raw(dcc[i].sock, iptostr(htonl(dcc[i].addr)), | |
40 | @@ -1099,7 +1099,7 @@ | |
41 | return; | |
42 | } | |
43 | killsock(dcc[idx].sock); | |
44 | - dcc[idx].sock = getsock(SOCK_STRONGCONN); | |
45 | + dcc[idx].sock = getsock(SOCK_STRONGCONN,getprotocol(dcc[idx].host)); | |
46 | dcc[uidx].u.relay->sock = dcc[idx].sock; | |
47 | dcc[idx].port++; | |
48 | dcc[idx].timeval = now; | |
49 | @@ -1145,7 +1145,7 @@ | |
50 | return; | |
51 | } | |
52 | ||
53 | - dcc[i].sock = getsock(SOCK_STRONGCONN | SOCK_VIRTUAL); | |
54 | + dcc[i].sock = getsock(SOCK_STRONGCONN | SOCK_VIRTUAL,getprotocol(bi->address)); | |
55 | if (dcc[i].sock < 0) { | |
56 | lostdcc(i); | |
57 | dprintf(idx, "%s\n", MISC_NOFREESOCK); | |
58 | diff -urN eggdrop1.6.19/src/chanprog.c eggdrop1.6.19-ipv6/src/chanprog.c | |
59 | --- src/chanprog.c 2008-02-16 22:41:03.000000000 +0100 | |
60 | +++ src/chanprog.c 2008-07-27 22:13:41.000000000 +0200 | |
61 | @@ -294,6 +294,8 @@ | |
62 | botnetnick, ver, i, i == 1 ? "" : "s", | |
63 | (int) (expected_memory() / 1024)); | |
64 | ||
65 | + dprintf(idx, "Unofficial IPv6 patch for v1.6.19 based on the v1.6.18 IPv6 patch \n"); | |
66 | + | |
67 | s[0] = 0; | |
68 | if (now2 > 86400) { | |
69 | /* days */ | |
70 | diff -urN eggdrop1.6.19/src/dcc.c eggdrop1.6.19-ipv6/src/dcc.c | |
71 | --- src/dcc.c 2008-02-16 22:41:03.000000000 +0100 | |
72 | +++ src/dcc.c 2008-07-27 22:13:42.000000000 +0200 | |
73 | @@ -234,7 +234,7 @@ | |
74 | ||
75 | /* Try next port */ | |
76 | killsock(dcc[idx].sock); | |
77 | - dcc[idx].sock = getsock(SOCK_STRONGCONN); | |
78 | + dcc[idx].sock = getsock(SOCK_STRONGCONN,getprotocol(dcc[idx].host)); | |
79 | dcc[idx].port++; | |
80 | dcc[idx].timeval = now; | |
81 | if (dcc[idx].sock < 0 || | |
82 | @@ -1174,7 +1174,8 @@ | |
83 | changeover_dcc(i, &DCC_IDENTWAIT, 0); | |
84 | dcc[i].timeval = now; | |
85 | dcc[i].u.ident_sock = dcc[idx].sock; | |
86 | - sock = open_telnet(iptostr(htonl(dcc[i].addr)), 113); | |
87 | + // sock = open_telnet(iptostr(htonl(dcc[i].addr)), 113); | |
88 | + sock = open_telnet(dcc[i].host, 113); | |
89 | putlog(LOG_MISC, "*", DCC_TELCONN, dcc[i].host, dcc[i].port); | |
90 | s[0] = 0; | |
91 | if (sock < 0) { | |
92 | diff -urN eggdrop1.6.19/src/main.c eggdrop1.6.19-ipv6/src/main.c | |
93 | --- src/main.c 2008-02-16 22:41:03.000000000 +0100 | |
94 | +++ src/main.c 2008-07-28 18:35:52.000000000 +0200 | |
95 | @@ -90,8 +90,8 @@ | |
96 | * modified versions of this bot. | |
97 | */ | |
98 | ||
99 | -char egg_version[1024] = "1.6.19"; | |
100 | -int egg_numver = 1061800; | |
101 | +char egg_version[1024] = "1.6.19"; | |
102 | +int egg_numver = 1061900; | |
103 | ||
104 | char notify_new[121] = ""; /* Person to send a note to for new users */ | |
105 | int default_flags = 0; /* Default user flags */ | |
106 | @@ -239,7 +239,7 @@ | |
107 | * _not_ safe <cybah> | |
108 | */ | |
109 | x = creat("DEBUG.DEBUG", 0644); | |
110 | - setsock(x, SOCK_NONSOCK); | |
111 | + setsock(x, SOCK_NONSOCK,AF_INET); | |
112 | if (x >= 0) { | |
113 | strncpyz(s, ctime(&now), sizeof s); | |
114 | dprintf(-x, "Debug (%s) written %s\n", ver, s); | |
115 | @@ -264,7 +264,7 @@ | |
116 | putlog(LOG_MISC, "*", "* Please REPORT this BUG!"); | |
117 | putlog(LOG_MISC, "*", "* Check doc/BUG-REPORT on how to do so."); | |
118 | x = creat("DEBUG", 0644); | |
119 | - setsock(x, SOCK_NONSOCK); | |
120 | + setsock(x, SOCK_NONSOCK,AF_INET); | |
121 | if (x < 0) { | |
122 | putlog(LOG_MISC, "*", "* Failed to write DEBUG"); | |
123 | } else { | |
124 | @@ -906,7 +906,7 @@ | |
125 | userlist = adduser(userlist, dcc[n].nick, "none", "-", USER_PARTY); | |
126 | dcc[n].user = get_user_by_handle(userlist, dcc[n].nick); | |
127 | } | |
128 | - setsock(STDOUT, 0); /* Entry in net table */ | |
129 | + setsock(STDOUT, 0,AF_INET); /* Entry in net table */ | |
130 | dprintf(n, "\n### ENTERING DCC CHAT SIMULATION ###\n\n"); | |
131 | dcc_chatter(n); | |
132 | } | |
133 | diff -urN eggdrop1.6.19/src/mod/filesys.mod/filesys.c eggdrop1.6.19-ipv6/src/mod/filesys.mod/filesys.c | |
134 | --- src/mod/filesys.mod/filesys.c 2008-02-16 22:41:09.000000000 +0100 | |
135 | +++ src/mod/filesys.mod/filesys.c 2008-07-27 22:13:44.000000000 +0200 | |
136 | @@ -820,7 +820,7 @@ | |
137 | lostdcc(i); | |
138 | } else { | |
139 | dcc[i].timeval = now; | |
140 | - dcc[i].sock = getsock(SOCK_BINARY); | |
141 | + dcc[i].sock = getsock(SOCK_BINARY,getprotocol(ip)); | |
142 | if (dcc[i].sock < 0 || open_telnet_dcc(dcc[i].sock, ip, prt) < 0) | |
143 | dcc[i].type->eof(i); | |
144 | } | |
145 | @@ -865,7 +865,7 @@ | |
146 | } else { | |
147 | ip = newsplit(&msg); | |
148 | prt = newsplit(&msg); | |
149 | - sock = getsock(0); | |
150 | + sock = getsock(0,getprotocol(ip)); | |
151 | if (sock < 0 || open_telnet_dcc(sock, ip, prt) < 0) { | |
152 | neterror(buf); | |
153 | if (!quiet_reject) | |
154 | diff -urN eggdrop1.6.19/src/mod/module.h eggdrop1.6.19-ipv6/src/mod/module.h | |
155 | --- src/mod/module.h 2008-02-16 22:41:06.000000000 +0100 | |
156 | +++ src/mod/module.h 2008-07-27 22:13:45.000000000 +0200 | |
157 | @@ -198,7 +198,8 @@ | |
158 | /* 80 - 83 */ | |
159 | #define new_dcc ((int (*) (struct dcc_table *, int))global[80]) | |
160 | #define lostdcc ((void (*) (int))global[81]) | |
161 | -#define getsock ((int (*) (int))global[82]) | |
162 | +/* #define getsock ((int (*) (int))global[82]) */ | |
163 | +#define getsock ((int (*) (int,int))global[82]) | |
164 | #define killsock ((void (*) (int))global[83]) | |
165 | /* 84 - 87 */ | |
166 | #define open_listen ((int (*) (int *))global[84]) | |
167 | @@ -469,6 +470,7 @@ | |
168 | #define quiet_reject (*(int *)(global[284])) | |
169 | #define file_readable ((int (*) (char *))global[285]) | |
170 | /* IPv6 leftovers: 286 */ | |
171 | +#define getprotocol ((int (*)(char *))global[286]) /* get protocol */ | |
172 | /* IPv6 leftovers: 287 */ | |
173 | /* 288 - 291 */ | |
174 | /* IPv6 leftovers: 288 */ | |
175 | diff -urN eggdrop1.6.19/src/mod/server.mod/server.c eggdrop1.6.19-ipv6/src/mod/server.mod/server.c | |
176 | --- src/mod/server.mod/server.c 2008-02-16 22:41:10.000000000 +0100 | |
177 | +++ src/mod/server.mod/server.c 2008-07-27 22:13:47.000000000 +0200 | |
178 | @@ -1517,7 +1517,7 @@ | |
179 | return; | |
180 | } | |
181 | egg_snprintf(ip, sizeof ip, "%lu", iptolong(htonl(dcc[i].addr))); | |
182 | - dcc[i].sock = getsock(0); | |
183 | + dcc[i].sock = getsock(0,getprotocol(ip)); | |
184 | if (dcc[i].sock < 0 || open_telnet_dcc(dcc[i].sock, ip, buf) < 0) { | |
185 | neterror(buf); | |
186 | if (!quiet_reject) | |
187 | diff -urN eggdrop1.6.19/src/mod/server.mod/servmsg.c eggdrop1.6.19-ipv6/src/mod/server.mod/servmsg.c | |
188 | --- src/mod/server.mod/servmsg.c 2008-02-16 22:41:10.000000000 +0100 | |
189 | +++ src/mod/server.mod/servmsg.c 2008-07-27 22:13:47.000000000 +0200 | |
190 | @@ -1261,7 +1261,9 @@ | |
191 | /* I'm resolving... don't start another server connect request */ | |
192 | resolvserv = 1; | |
193 | /* Resolve the hostname. */ | |
194 | - dcc_dnsipbyhost(dcc[servidx].host); | |
195 | + // dcc_dnsipbyhost(dcc[servidx].host); | |
196 | + server_resolve_success(servidx); | |
197 | + | |
198 | } | |
199 | } | |
200 | ||
201 | @@ -1283,7 +1285,9 @@ | |
202 | dcc[servidx].addr = dcc[servidx].u.dns->ip; | |
203 | strcpy(pass, dcc[servidx].u.dns->cbuf); | |
204 | changeover_dcc(servidx, &SERVER_SOCKET, 0); | |
205 | - serv = open_telnet(iptostr(htonl(dcc[servidx].addr)), dcc[servidx].port); | |
206 | + //serv = open_telnet(iptostr(htonl(dcc[servidx].addr)), dcc[servidx].port); | |
207 | + serv = open_telnet(dcc[servidx].host, dcc[servidx].port); | |
208 | + | |
209 | if (serv < 0) { | |
210 | neterror(s); | |
211 | putlog(LOG_SERV, "*", "%s %s (%s)", IRC_FAILEDCONNECT, dcc[servidx].host, | |
212 | diff -urN eggdrop1.6.19/src/mod/share.mod/share.c eggdrop1.6.19-ipv6/src/mod/share.mod/share.c | |
213 | --- src/mod/share.mod/share.c 2008-02-16 22:41:11.000000000 +0100 | |
214 | +++ src/mod/share.mod/share.c 2008-07-27 22:13:48.000000000 +0200 | |
215 | @@ -1137,7 +1137,7 @@ | |
216 | } else { | |
217 | ip = newsplit(&par); | |
218 | port = newsplit(&par); | |
219 | - sock = getsock(SOCK_BINARY); /* Don't buffer this -> mark binary. */ | |
220 | + sock = getsock(SOCK_BINARY,getprotocol(ip)); /* Don't buffer this -> mark binary. */ | |
221 | if (sock < 0 || open_telnet_dcc(sock, ip, port) < 0) { | |
222 | killsock(sock); | |
223 | putlog(LOG_BOTS, "*", "Asynchronous connection failed!"); | |
224 | diff -urN eggdrop1.6.19/src/modules.c eggdrop1.6.19-ipv6/src/modules.c | |
225 | --- src/modules.c 2008-02-16 22:41:04.000000000 +0100 | |
226 | +++ src/modules.c 2008-07-27 22:13:45.000000000 +0200 | |
227 | @@ -99,6 +99,7 @@ | |
228 | extern tand_t *tandbot; | |
229 | extern Tcl_Interp *interp; | |
230 | extern sock_list *socklist; | |
231 | +extern int getprotocol(char *); | |
232 | ||
233 | int cmd_die(); | |
234 | int xtra_kill(); | |
235 | @@ -561,7 +562,7 @@ | |
236 | /* 284 - 287 */ | |
237 | (Function) & quiet_reject, /* int */ | |
238 | (Function) file_readable, | |
239 | - (Function) 0, /* IPv6 leftovers: 286 */ | |
240 | + (Function) getprotocol, /* IPv6 leftovers: 286 */ | |
241 | (Function) 0, /* IPv6 leftovers: 287 */ | |
242 | /* 288 - 291 */ | |
243 | (Function) 0, /* IPv6 leftovers: 288 */ | |
244 | diff -urN eggdrop1.6.19/src/net.c eggdrop1.6.19-ipv6/src/net.c | |
245 | --- src/net.c 2008-02-16 22:41:04.000000000 +0100 | |
246 | +++ src/net.c 2008-07-27 22:13:46.000000000 +0200 | |
247 | @@ -60,6 +60,9 @@ | |
248 | ||
249 | char hostname[121] = ""; /* Hostname can be specified in the config file.*/ | |
250 | char myip[121] = ""; /* IP can be specified in the config file. */ | |
251 | +char myip6[121] = ""; /* IPV6 can be specified in the config file. */ | |
252 | +char hostname6[121] = ""; /* Hostname6 can be specified in the config file*/ | |
253 | + | |
254 | char firewall[121] = ""; /* Socks server for firewall. */ | |
255 | int firewallport = 1080; /* Default port of socks 4/5 firewalls. */ | |
256 | char botuser[21] = "eggdrop"; /* Username of the user running the bot. */ | |
257 | @@ -88,6 +91,28 @@ | |
258 | return ret; | |
259 | } | |
260 | ||
261 | +/* define the protocol based on a given host */ | |
262 | +int getprotocol(char *host) | |
263 | +{ | |
264 | +#ifndef IPV6 | |
265 | + return AF_INET; | |
266 | +#else | |
267 | + struct hostent *he; | |
268 | + if (!setjmp(alarmret)) { | |
269 | + alarm(resolve_timeout); | |
270 | + he = gethostbyname2(host,AF_INET6); | |
271 | + alarm(0); | |
272 | + } else | |
273 | + he = NULL; | |
274 | + | |
275 | + if(!he) | |
276 | + { | |
277 | + return AF_INET; // we check no resolve on IPv4 and assume it, if IPv6 does not works | |
278 | + } | |
279 | + return AF_INET6; | |
280 | +#endif | |
281 | +} | |
282 | + | |
283 | /* Initialize the socklist | |
284 | */ | |
285 | void init_net() | |
286 | @@ -114,6 +139,9 @@ | |
287 | return tot; | |
288 | } | |
289 | ||
290 | +struct hostent *myipv6he; | |
291 | +char myipv6host[120]; | |
292 | + | |
293 | /* Get my ip number | |
294 | */ | |
295 | IP getmyip() | |
296 | @@ -122,6 +150,25 @@ | |
297 | char s[121]; | |
298 | IP ip; | |
299 | struct in_addr *in; | |
300 | + | |
301 | + myipv6he = NULL; | |
302 | + | |
303 | + #ifdef IPV6 | |
304 | + if (myip[0]) { | |
305 | + myipv6he = gethostbyname2(myip6,AF_INET6); | |
306 | + if (myipv6he==NULL) | |
307 | + fatal("Hostname IPV6 self-lookup failed.",0); | |
308 | + } | |
309 | + if (hostname6[0]) { | |
310 | + myipv6he = gethostbyname2(hostname6,AF_INET6); | |
311 | + if (myipv6he==NULL) | |
312 | + fatal("Hostname IPV6 self-lookup failed.",0); | |
313 | + } | |
314 | + if(myipv6he!=NULL) | |
315 | + { | |
316 | + inet_ntop(AF_INET6,&myipv6he,myipv6host,119); | |
317 | + } | |
318 | + #endif | |
319 | if (myip[0]) { | |
320 | if ((myip[strlen(myip) - 1] >= '0') && (myip[strlen(myip) - 1] <= '9')) | |
321 | return (IP) inet_addr(myip); | |
322 | @@ -133,9 +180,10 @@ | |
323 | gethostname(s, 120); | |
324 | hp = gethostbyname(s); | |
325 | } | |
326 | - if (hp == NULL) | |
327 | + if (hp == NULL && myipv6he==NULL) | |
328 | fatal("Hostname self-lookup failed. Please set 'my-ip' in the config " | |
329 | "file.", 0); | |
330 | + if (hp == NULL) return 0; | |
331 | in = (struct in_addr *) (hp->h_addr_list[0]); | |
332 | ip = (IP) (in->s_addr); | |
333 | return ip; | |
334 | @@ -244,7 +292,7 @@ | |
335 | ||
336 | /* Return a free entry in the socket entry | |
337 | */ | |
338 | -int allocsock(int sock, int options) | |
339 | +int allocsock(int sock, int options, int af_ty) | |
340 | { | |
341 | int i; | |
342 | ||
343 | @@ -255,6 +303,7 @@ | |
344 | socklist[i].inbuflen = socklist[i].outbuflen = 0; | |
345 | socklist[i].flags = options; | |
346 | socklist[i].sock = sock; | |
347 | + socklist[i].af = af_ty; | |
348 | return i; | |
349 | } | |
350 | } | |
351 | @@ -264,9 +313,9 @@ | |
352 | ||
353 | /* Request a normal socket for i/o | |
354 | */ | |
355 | -void setsock(int sock, int options) | |
356 | +void setsock(int sock, int options, int af_ty) | |
357 | { | |
358 | - int i = allocsock(sock, options), parm; | |
359 | + int i = allocsock(sock, options, af_ty), parm; | |
360 | ||
361 | if (((sock != STDOUT) || backgrd) && !(socklist[i].flags & SOCK_NONSOCK)) { | |
362 | parm = 1; | |
363 | @@ -284,12 +333,12 @@ | |
364 | fcntl(sock, F_SETFL, O_NONBLOCK); | |
365 | } | |
366 | ||
367 | -int getsock(int options) | |
368 | +int getsock(int options, int AF_DEF) | |
369 | { | |
370 | - int sock = socket(AF_INET, SOCK_STREAM, 0); | |
371 | + int sock = socket(AF_DEF, SOCK_STREAM, 0); | |
372 | ||
373 | if (sock >= 0) | |
374 | - setsock(sock, options); | |
375 | + setsock(sock, options, AF_DEF); | |
376 | else | |
377 | putlog(LOG_MISC, "*", "Warning: Can't create new socket!"); | |
378 | return sock; | |
379 | @@ -328,23 +377,39 @@ | |
380 | */ | |
381 | static int proxy_connect(int sock, char *host, int port, int proxy) | |
382 | { | |
383 | + #ifdef IPV6 | |
384 | + unsigned char x[32]; | |
385 | +#else | |
386 | unsigned char x[10]; | |
387 | +#endif | |
388 | + | |
389 | struct hostent *hp; | |
390 | char s[256]; | |
391 | + int af_ty; | |
392 | int i; | |
393 | + af_ty=getprotocol(host); | |
394 | ||
395 | /* socks proxy */ | |
396 | if (proxy == PROXY_SOCKS) { | |
397 | /* numeric IP? */ | |
398 | - if (host[strlen(host) - 1] >= '0' && host[strlen(host) - 1] <= '9') { | |
399 | + if ((host[strlen(host) - 1] >= '0' && host[strlen(host) - 1] <= '9') && af_ty!=AF_INET6) { | |
400 | IP ip = ((IP) inet_addr(host)); | |
401 | egg_memcpy(x, &ip, 4); | |
402 | } else { | |
403 | /* no, must be host.domain */ | |
404 | if (!sigsetjmp(alarmret, 1)) { | |
405 | + #ifdef IPV6 | |
406 | alarm(resolve_timeout); | |
407 | + if (af_ty==AF_INET6) | |
408 | + { | |
409 | + hp = gethostbyname(host); | |
410 | + } else { | |
411 | + #endif | |
412 | hp = gethostbyname(host); | |
413 | + #ifdef IPV6 | |
414 | + } | |
415 | alarm(0); | |
416 | + #endif | |
417 | } else | |
418 | hp = NULL; | |
419 | if (hp == NULL) { | |
420 | @@ -356,6 +421,17 @@ | |
421 | for (i = 0; i < MAXSOCKS; i++) | |
422 | if (!(socklist[i].flags & SOCK_UNUSED) && socklist[i].sock == sock) | |
423 | socklist[i].flags |= SOCK_PROXYWAIT; /* drummer */ | |
424 | + | |
425 | + #ifdef IPV6 | |
426 | + if (af_ty==AF_INET6) | |
427 | + egg_snprintf(s, sizeof s,"\004\001%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%s", (port >> 8) % 256, (port % 256), | |
428 | + x[0], x[1], x[2], x[3], | |
429 | + x[4], x[5], x[6], x[7], | |
430 | + x[8], x[9], x[10], x[11], | |
431 | + x[12], x[13], x[14], x[15], | |
432 | + botuser); | |
433 | + else | |
434 | + #endif | |
435 | egg_snprintf(s, sizeof s, "\004\001%c%c%c%c%c%c%s", (port >> 8) % 256, | |
436 | (port % 256), x[0], x[1], x[2], x[3], botuser); | |
437 | tputs(sock, s, strlen(botuser) + 9); /* drummer */ | |
438 | @@ -366,6 +442,19 @@ | |
439 | return sock; | |
440 | } | |
441 | ||
442 | +/* | |
443 | + * Return protocol of socket | |
444 | + */ | |
445 | +int getsockproto(int sock) | |
446 | +{ | |
447 | + int i; | |
448 | + for (i = 0 ; i < MAXSOCKS ; i++) { | |
449 | + if (socklist[i].sock == sock) | |
450 | + return socklist[i].af; | |
451 | + } | |
452 | + return AF_INET; // default | |
453 | +} | |
454 | + | |
455 | /* Starts a connection attempt to a socket | |
456 | * | |
457 | * If given a normal hostname, this will be resolved to the corresponding | |
458 | @@ -379,9 +468,15 @@ | |
459 | int open_telnet_raw(int sock, char *server, int sport) | |
460 | { | |
461 | struct sockaddr_in name; | |
462 | +#ifdef IPV6 | |
463 | + struct sockaddr_in6 name6; | |
464 | + unsigned long succ; | |
465 | +#endif | |
466 | + int rc; | |
467 | struct hostent *hp; | |
468 | char host[121]; | |
469 | - int i, port, rc; | |
470 | + int i, port; | |
471 | + int af_ty; | |
472 | volatile int proxy; | |
473 | ||
474 | /* firewall? use socks */ | |
475 | @@ -399,6 +494,43 @@ | |
476 | strcpy(host, server); | |
477 | port = sport; | |
478 | } | |
479 | +#ifdef IPV6 | |
480 | + af_ty = getprotocol(host); | |
481 | + if(af_ty==AF_INET6) | |
482 | + { | |
483 | + succ=getmyip(); | |
484 | + bzero((char *) &name6, sizeof(struct sockaddr_in6)); | |
485 | + | |
486 | + name6.sin6_family = AF_INET6; | |
487 | + if (myip[0]) | |
488 | + { | |
489 | + if (myipv6he==NULL) | |
490 | + { | |
491 | + memcpy(&name6.sin6_addr,&in6addr_any,16); | |
492 | + } else { | |
493 | + memcpy(&name6.sin6_addr,myipv6he->h_addr,myipv6he->h_length); | |
494 | + } | |
495 | + } else { | |
496 | + | |
497 | + } | |
498 | + if (bind(sock, (struct sockaddr *) &name6, sizeof(name6)) < 0) { | |
499 | + killsock(sock); | |
500 | + return -1; | |
501 | + } | |
502 | + bzero((char *) &name6, sizeof(struct sockaddr_in6)); | |
503 | + name6.sin6_family = AF_INET6; | |
504 | + name6.sin6_port = htons(port); | |
505 | + if (!setjmp(alarmret)) { | |
506 | + alarm(resolve_timeout); | |
507 | + hp = gethostbyname2(host,AF_INET6); | |
508 | + alarm(0) ; | |
509 | + } else { | |
510 | + hp = NULL ; | |
511 | + } | |
512 | + egg_memcpy((char *) &name6.sin6_addr, hp->h_addr, hp->h_length); | |
513 | + name6.sin6_family = hp->h_addrtype; | |
514 | + } else { | |
515 | +#endif | |
516 | egg_bzero((char *) &name, sizeof(struct sockaddr_in)); | |
517 | ||
518 | name.sin_family = AF_INET; | |
519 | @@ -428,11 +560,20 @@ | |
520 | egg_memcpy(&name.sin_addr, hp->h_addr, hp->h_length); | |
521 | name.sin_family = hp->h_addrtype; | |
522 | } | |
523 | +#ifdef IPV6 | |
524 | + } | |
525 | +#endif | |
526 | for (i = 0; i < MAXSOCKS; i++) { | |
527 | if (!(socklist[i].flags & SOCK_UNUSED) && (socklist[i].sock == sock)) | |
528 | socklist[i].flags = (socklist[i].flags & ~SOCK_VIRTUAL) | SOCK_CONNECT; | |
529 | } | |
530 | - rc = connect(sock, (struct sockaddr *) &name, sizeof(struct sockaddr_in)); | |
531 | + //rc = connect(sock, (struct sockaddr *) &name, sizeof(struct sockaddr_in)); | |
532 | +#ifdef IPV6 | |
533 | + if (af_ty == AF_INET6) | |
534 | + rc = connect(sock, (struct sockaddr *) &name6, sizeof(struct sockaddr_in6)); | |
535 | + else | |
536 | +#endif | |
537 | + rc = connect(sock, (struct sockaddr *) &name, sizeof(struct sockaddr_in)) ; | |
538 | if (rc < 0) { | |
539 | if (errno == EINPROGRESS) { | |
540 | /* Firewall? announce connect attempt to proxy */ | |
541 | @@ -451,8 +592,12 @@ | |
542 | /* Ordinary non-binary connection attempt */ | |
543 | int open_telnet(char *server, int port) | |
544 | { | |
545 | - int sock = getsock(0), ret = open_telnet_raw(sock, server, port); | |
546 | + int sock = getsock(0,getprotocol(server)), ret = open_telnet_raw(sock, server, port); | |
547 | + | |
548 | + putlog(LOG_DEBUG, "*", "net.c / open_telnet"); | |
549 | ||
550 | + if (ret < 0) | |
551 | + killsock(sock); | |
552 | return ret; | |
553 | } | |
554 | ||
555 | @@ -462,7 +607,12 @@ | |
556 | int open_address_listen(IP addr, int *port) | |
557 | { | |
558 | int sock = 0; | |
559 | + int af_def; | |
560 | + unsigned long ipp; | |
561 | socklen_t addrlen; | |
562 | +#ifdef IPV6 | |
563 | + struct sockaddr_in6 name6; | |
564 | +#endif | |
565 | struct sockaddr_in name; | |
566 | ||
567 | if (firewall[0]) { | |
568 | @@ -473,7 +623,8 @@ | |
569 | } | |
570 | ||
571 | if (getmyip() > 0) { | |
572 | - sock = getsock(SOCK_LISTEN); | |
573 | + af_def=AF_INET; | |
574 | + sock = getsock(SOCK_LISTEN,af_def); | |
575 | if (sock < 1) | |
576 | return -1; | |
577 | ||
578 | @@ -483,7 +634,7 @@ | |
579 | name.sin_addr.s_addr = addr; | |
580 | if (bind(sock, (struct sockaddr *) &name, sizeof(name)) < 0) { | |
581 | killsock(sock); | |
582 | - return -1; | |
583 | + goto tryv6; | |
584 | } | |
585 | /* what port are we on? */ | |
586 | addrlen = sizeof(name); | |
587 | @@ -494,9 +645,37 @@ | |
588 | *port = ntohs(name.sin_port); | |
589 | if (listen(sock, 1) < 0) { | |
590 | killsock(sock); | |
591 | + goto tryv6; | |
592 | + } | |
593 | + return sock; | |
594 | + } | |
595 | + tryv6: | |
596 | +#ifdef IPV6 | |
597 | + ipp=getmyip(); | |
598 | + af_def=AF_INET6; | |
599 | + if(af_def==AF_INET6 && myipv6he!=NULL) | |
600 | + { | |
601 | + sock = getsock(SOCK_LISTEN,af_def); | |
602 | + bzero((char *) &name6,sizeof(name6)); | |
603 | + name6.sin6_family=af_def; | |
604 | + name6.sin6_port=htons(*port); | |
605 | + memcpy(&name6.sin6_addr,myipv6he->h_addr,myipv6he->h_length); | |
606 | + if (bind(sock, (struct sockaddr *) &name6, sizeof(name6)) < 0) { | |
607 | + killsock(sock); | |
608 | + return -1; | |
609 | + } | |
610 | + addrlen = sizeof(name6); | |
611 | + if (getsockname(sock, (struct sockaddr *) &name6, &addrlen) < 0) { | |
612 | + killsock(sock); | |
613 | + return -1; | |
614 | + } | |
615 | + *port = ntohs(name6.sin6_port); | |
616 | + if (listen(sock, 1) < 0) { | |
617 | + killsock(sock); | |
618 | return -1; | |
619 | } | |
620 | } | |
621 | +#endif | |
622 | ||
623 | return sock; | |
624 | } | |
625 | @@ -520,6 +699,9 @@ | |
626 | return inet_ntoa(a); | |
627 | } | |
628 | ||
629 | +unsigned long notalloc=0; | |
630 | + | |
631 | + | |
632 | /* Short routine to answer a connect received on a socket made previously | |
633 | * by open_listen ... returns hostname of the caller & the new socket | |
634 | * does NOT dispose of old "public" socket! | |
635 | @@ -529,23 +711,57 @@ | |
636 | { | |
637 | int new_sock; | |
638 | socklen_t addrlen; | |
639 | + int af_ty; | |
640 | +#ifdef IPV6 | |
641 | + struct sockaddr_in6 from6; | |
642 | +#endif | |
643 | struct sockaddr_in from; | |
644 | + af_ty=getsockproto(sock); | |
645 | ||
646 | addrlen = sizeof(struct sockaddr); | |
647 | +#ifdef IPV6 | |
648 | + if (af_ty==AF_INET6) | |
649 | + { | |
650 | + addrlen = sizeof(from6); | |
651 | + new_sock = accept(sock, (struct sockaddr *) &from6, &addrlen); | |
652 | + } else { | |
653 | +#endif | |
654 | + addrlen = sizeof(struct sockaddr); | |
655 | new_sock = accept(sock, (struct sockaddr *) &from, &addrlen); | |
656 | +#ifdef IPV6 | |
657 | + } | |
658 | +#endif | |
659 | ||
660 | if (new_sock < 0) | |
661 | return -1; | |
662 | if (ip != NULL) { | |
663 | +#ifdef IPV6 | |
664 | + if (af_ty==AF_INET6) | |
665 | + { | |
666 | + *ip=notalloc; | |
667 | + inet_ntop(AF_INET6,&from6,caller,119); | |
668 | + caller[120]=0; | |
669 | + } else { | |
670 | +#endif | |
671 | *ip = from.sin_addr.s_addr; | |
672 | /* DNS is now done asynchronously. We now only provide the IP address. */ | |
673 | strncpyz(caller, iptostr(*ip), 121); | |
674 | *ip = ntohl(*ip); | |
675 | +#ifdef IPV6 | |
676 | + } | |
677 | +#endif | |
678 | } | |
679 | if (port != NULL) | |
680 | + { | |
681 | +#ifdef IPV6 | |
682 | + if (af_ty==AF_INET6) | |
683 | + *port = ntohs(from6.sin6_port); | |
684 | + else | |
685 | +#endif | |
686 | *port = ntohs(from.sin_port); | |
687 | + } | |
688 | /* Set up all the normal socket crap */ | |
689 | - setsock(new_sock, (binary ? SOCK_BINARY : 0)); | |
690 | + setsock(new_sock, (binary ? SOCK_BINARY : 0),af_ty); | |
691 | return new_sock; | |
692 | } | |
693 | ||
694 | @@ -562,6 +778,14 @@ | |
695 | p = atoi(port); | |
696 | else | |
697 | p = 2000; | |
698 | +#ifdef IPV6 | |
699 | + if(getprotocol(server)==AF_INET6) | |
700 | + { | |
701 | + server[0]=0; | |
702 | + if(strlen(server)<500) | |
703 | + strcpy(sv,server); | |
704 | + } else { | |
705 | +#endif | |
706 | if (server != NULL) | |
707 | addr = my_atoul(server); | |
708 | else | |
709 | @@ -573,6 +797,9 @@ | |
710 | c[2] = (addr >> 8) & 0xff; | |
711 | c[3] = addr & 0xff; | |
712 | sprintf(sv, "%u.%u.%u.%u", c[0], c[1], c[2], c[3]); | |
713 | +#ifdef IPV6 | |
714 | + } | |
715 | +#endif | |
716 | p = open_telnet_raw(sock, sv, p); | |
717 | return p; | |
718 | } | |
719 | @@ -1112,6 +1339,14 @@ | |
720 | if (!dcc_sanitycheck) | |
721 | return 1; | |
722 | ||
723 | +#ifdef IPV6 | |
724 | + if(getprotocol(ipaddy)==AF_INET6) | |
725 | + { | |
726 | + return 1; | |
727 | + } | |
728 | +#endif | |
729 | + | |
730 | + | |
731 | if (prt < 1) { | |
732 | putlog(LOG_MISC, "*", "ALERT: (%s!%s) specified an impossible port of %u!", | |
733 | nick, from, prt); | |
734 | diff -urN eggdrop1.6.19/src/proto.h eggdrop1.6.19-ipv6/src/proto.h | |
735 | --- src/proto.h 2008-02-16 22:41:04.000000000 +0100 | |
736 | +++ src/proto.h 2008-07-27 22:13:46.000000000 +0200 | |
737 | @@ -245,9 +245,11 @@ | |
738 | unsigned long iptolong(IP); | |
739 | IP getmyip(); | |
740 | void neterror(char *); | |
741 | -void setsock(int, int); | |
742 | -int allocsock(int, int); | |
743 | -int getsock(int); | |
744 | +void setsock(int, int, int); | |
745 | +int allocsock(int, int, int); | |
746 | +int getsock(int, int); | |
747 | +int getprotocol(char *); | |
748 | +char *hostnamefromip(unsigned long); | |
749 | void killsock(int); | |
750 | int answer(int, char *, unsigned long *, unsigned short *, int); | |
751 | inline int open_listen(int *); | |
752 | diff -urN eggdrop1.6.19/src/tcl.c eggdrop1.6.19-ipv6/src/tcl.c | |
753 | --- src/tcl.c 2008-02-16 22:41:04.000000000 +0100 | |
754 | +++ src/tcl.c 2008-07-27 22:13:49.000000000 +0200 | |
755 | @@ -46,7 +46,7 @@ | |
756 | extern time_t online_since; | |
757 | ||
758 | extern char origbotname[], botuser[], motdfile[], admin[], userfile[], | |
759 | - firewall[], helpdir[], notify_new[], hostname[], myip[], moddir[], | |
760 | + firewall[], helpdir[], notify_new[], hostname[], hostname6[], myip[], myip6[], moddir[], | |
761 | tempdir[], owner[], network[], botnetnick[], bannerfile[], | |
762 | egg_version[], natip[], configfile[], logfile_suffix[], textdir[], | |
763 | pid_file[]; | |
764 | @@ -461,6 +461,8 @@ | |
765 | {"owner", owner, 120, STR_PROTECT}, | |
766 | {"my-ip", myip, 120, 0}, | |
767 | {"my-hostname", hostname, 120, 0}, | |
768 | + {"my-ip6", myip6, 120, 0}, | |
769 | + {"my-hostname6", hostname6, 120, 0}, | |
770 | {"network", network, 40, 0}, | |
771 | {"whois-fields", whois_fields, 1024, 0}, | |
772 | {"nat-ip", natip, 120, 0}, | |
773 | diff -urN eggdrop1.6.19/src/tcldcc.c eggdrop1.6.19-ipv6/src/tcldcc.c | |
774 | --- src/tcldcc.c 2008-02-16 22:41:04.000000000 +0100 | |
775 | +++ src/tcldcc.c 2008-07-27 22:13:50.000000000 +0200 | |
776 | @@ -850,7 +850,7 @@ | |
777 | Tcl_AppendResult(irp, "out of dcc table space", NULL); | |
778 | return TCL_ERROR; | |
779 | } | |
780 | - sock = getsock(0); | |
781 | + sock = getsock(0,getprotocol(argv[1])); | |
782 | ||
783 | if (sock < 0) { | |
784 | Tcl_AppendResult(irp, MISC_NOFREESOCK, NULL); | |
785 | diff -urN eggdrop1.6.19/src/tclmisc.c eggdrop1.6.19-ipv6/src/tclmisc.c | |
786 | --- src/tclmisc.c 2008-02-16 22:41:04.000000000 +0100 | |
787 | +++ src/tclmisc.c 2008-07-27 22:13:50.000000000 +0200 | |
788 | @@ -428,6 +428,21 @@ | |
789 | return TCL_OK; | |
790 | } | |
791 | ||
792 | +extern char myipv6host[120]; | |
793 | + | |
794 | +static int tcl_myip6 STDVAR | |
795 | +{ | |
796 | + char s[120]; | |
797 | + getmyip(); | |
798 | + | |
799 | + BADARGS(1, 1, ""); | |
800 | + s[0]=0; | |
801 | + if (strlen(myipv6host)<120) | |
802 | + strcpy(s,myipv6host); | |
803 | + Tcl_AppendResult(irp, s, NULL); | |
804 | + return TCL_OK; | |
805 | +} | |
806 | + | |
807 | static int tcl_rand STDVAR | |
808 | { | |
809 | unsigned long x;*** eggdrop1.6.19/src/net.h.org Thu Feb 5 23:55:45 2009 | |
810 | --- src/net.h.org 2009-02-05 23:59:43.000000000 +0100 | |
811 | +++ src/net.h 2009-02-05 23:59:52.000000000 +0100 | |
812 | @@ -22,9 +22,7 @@ | |
813 | char *outbuf; | |
814 | unsigned long outbuflen; /* Outbuf could be binary data */ | |
815 | unsigned long inbuflen; /* Inbuf could be binary data */ | |
816 | -#ifdef USE_IPV6 | |
817 | unsigned int af; | |
818 | -#endif /* USE_IPV6 */ | |
819 | } sock_list; | |
820 | ||
821 | #endif /* _EGG_NET_H */ |