/[cvs]/eggdrop1.9/src/net.c
ViewVC logotype

Contents of /eggdrop1.9/src/net.c

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.54 - (show annotations) (download) (as text)
Tue Mar 5 19:53:48 2002 UTC (17 years, 7 months ago) by stdarg
Branch: MAIN
Changes since 1.53: +10 -1 lines
File MIME type: text/x-chdr
* Use strerror() within neterror() if we have it

1 /*
2 * net.c -- handles:
3 * all raw network i/o
4 *
5 * $Id: net.c,v 1.53 2002/01/19 20:08:58 ite Exp $
6 */
7 /*
8 * This is hereby released into the public domain.
9 * Robey Pointer, robey@netcom.com
10 */
11
12 #include <fcntl.h>
13 #include "main.h"
14 #include <limits.h>
15 #include <string.h>
16 #include <netdb.h>
17 #include <sys/socket.h>
18 #if HAVE_SYS_SELECT_H
19 # include <sys/select.h>
20 #endif
21 #include <netinet/in.h>
22 #include <arpa/inet.h>
23 #include <errno.h>
24 #if HAVE_UNISTD_H
25 # include <unistd.h>
26 #endif
27 #include <setjmp.h>
28
29 #include "lib/adns/adns.h"
30 #include "egg_timer.h"
31 #include "logfile.h"
32 #include "dns.h"
33
34 #if !HAVE_GETDTABLESIZE
35 # ifdef FD_SETSIZE
36 # define getdtablesize() FD_SETSIZE
37 # else
38 # define getdtablesize() 200
39 # endif
40 #endif
41
42 #ifndef IN6_IS_ADDR_V4MAPPED
43 # define IN6_IS_ADDR_V4MAPPED(a) \
44 ((((uint32_t *) (a))[0] == 0) && (((uint32_t *) (a))[1] == 0) && \
45 (((uint32_t *) (a))[2] == htonl (0xffff)))
46 #endif
47
48 extern struct dcc_t *dcc;
49 extern int backgrd, use_stderr, resolve_timeout, dcc_total;
50 extern unsigned long otraffic_irc_today, otraffic_bn_today,
51 otraffic_dcc_today, otraffic_filesys_today,
52 otraffic_trans_today, otraffic_unknown_today;
53 extern char natip[];
54
55 char myip[121] = ""; /* IP can be specified in the config file */
56 char myip6[121] = ""; /* IP6 can be specified in the config file */
57 char firewall[121] = ""; /* Socks server for firewall */
58 int firewallport = 1080; /* Default port of Sock4/5 firewalls */
59 char botuser[21] = "eggdrop"; /* Username of the user running the bot */
60 sock_list *socklist = NULL; /* Enough to be safe */
61 int MAXSOCKS = 0;
62 jmp_buf alarmret; /* Env buffer for alarm() returns */
63 IP localipv4addr = 0; /* Cache the local IPv4 address */
64
65 adns_state ads;
66
67 /* Types of proxy */
68 #define PROXY_SOCKS 1
69 #define PROXY_SUN 2
70
71 /* Initialize the socklist
72 */
73 void init_net()
74 {
75 int i;
76 char s[256];
77 struct hostent *hp;
78
79 socklist = (sock_list *)calloc(MAXSOCKS, sizeof(sock_list));
80 for (i = 0; i < MAXSOCKS; i++) {
81 socklist[i].flags = SOCK_UNUSED;
82 }
83
84 gethostname(s, sizeof s);
85 if ((hp = gethostbyname(s)) == NULL)
86 fatal("Hostname self-lookup failed.", 0);
87 localipv4addr = *((IP*) (hp->h_addr_list[0]));
88
89 /* init ADNS */
90 i = adns_init(&ads, adns_if_noautosys, 0);
91 if (i)
92 fatal(adns_strerror(i), 0);
93 }
94
95 /* Get my ip number
96 */
97 IP getmyip()
98 {
99 /* Could be pre-defined */
100 if (myip[0] && (myip[strlen(myip) - 1] >= '0') &&
101 (myip[strlen(myip) - 1] <= '9')) {
102 return (IP) inet_addr(myip);
103 }
104 return localipv4addr;
105 }
106
107 #ifdef IPV6
108 struct in6_addr getmyip6()
109 {
110 struct in6_addr ip;
111
112 /* Could be pre-defined */
113 if (myip6[0])
114 inet_pton(AF_INET6, myip6, &ip);
115 else {
116 /* get system's default IPv6 ip -- FIXME!? */
117 /* is there a know way?! - drummer */
118 ip = in6addr_any;
119 }
120 return ip;
121 }
122
123 struct in6_addr ipv4to6(IP a)
124 {
125 struct in6_addr ip;
126 if (a == INADDR_ANY)
127 return in6addr_any;
128 else {
129 ((uint32_t *)&ip)[0] = 0;
130 ((uint32_t *)&ip)[1] = 0;
131 ((uint16_t *)&ip)[4] = 0;
132 ((uint16_t *)&ip)[5] = 0xffff;
133 ((uint32_t *)&ip)[3] = a;
134 }
135 return ip;
136 }
137
138 #endif
139
140 void neterror(char *s)
141 {
142 #ifdef HAVE_STRERROR
143 int e = errno;
144 char *err = strerror(e);
145
146 /* Calling procs usually use char s[UHOSTLEN] for the error message. */
147 if (err) strncpyz(s, err, UHOSTLEN);
148 else sprintf(s, "Unforeseen error %d", e);
149 #else
150 switch (errno) {
151 case EADDRINUSE:
152 strcpy(s, "Address already in use");
153 break;
154 case EADDRNOTAVAIL:
155 strcpy(s, "Address invalid on remote machine");
156 break;
157 case EAFNOSUPPORT:
158 strcpy(s, "Address family not supported");
159 break;
160 case EALREADY:
161 strcpy(s, "Socket already in use");
162 break;
163 case EBADF:
164 strcpy(s, "Socket descriptor is bad");
165 break;
166 case ECONNREFUSED:
167 strcpy(s, "Connection refused");
168 break;
169 case EFAULT:
170 strcpy(s, "Namespace segment violation");
171 break;
172 case EINPROGRESS:
173 strcpy(s, "Operation in progress");
174 break;
175 case EINTR:
176 strcpy(s, "Timeout");
177 break;
178 case EINVAL:
179 strcpy(s, "Invalid namespace");
180 break;
181 case EISCONN:
182 strcpy(s, "Socket already connected");
183 break;
184 case ENETUNREACH:
185 strcpy(s, "Network unreachable");
186 break;
187 case ENOTSOCK:
188 strcpy(s, "File descriptor, not a socket");
189 break;
190 case ETIMEDOUT:
191 strcpy(s, "Connection timed out");
192 break;
193 case ENOTCONN:
194 strcpy(s, "Socket is not connected");
195 break;
196 case EHOSTUNREACH:
197 strcpy(s, "Host is unreachable");
198 break;
199 case EPIPE:
200 strcpy(s, "Broken pipe");
201 break;
202 #ifdef ECONNRESET
203 case ECONNRESET:
204 strcpy(s, "Connection reset by peer");
205 break;
206 #endif
207 #ifdef EACCES
208 case EACCES:
209 strcpy(s, "Permission denied");
210 break;
211 #endif
212 case 0:
213 strcpy(s, "Error 0");
214 break;
215 default:
216 sprintf(s, "Unforseen error %d", errno);
217 break;
218 }
219 #endif
220 }
221
222 /* Sets/Unsets options for a specific socket.
223 *
224 * Returns: 0 - on success
225 * -1 - socket not found
226 * -2 - illegal operation
227 */
228 int sockoptions(int sock, int operation, int sock_options)
229 {
230 int i;
231
232 for (i = 0; i < MAXSOCKS; i++)
233 if ((socklist[i].sock == sock) && !(socklist[i].flags & SOCK_UNUSED)) {
234 if (operation == EGG_OPTION_SET)
235 socklist[i].flags |= sock_options;
236 else if (operation == EGG_OPTION_UNSET)
237 socklist[i].flags &= ~sock_options;
238 else
239 return -2;
240 return 0;
241 }
242 return -1;
243 }
244
245 /* Return a free entry in the socket entry
246 */
247 int allocsock(int sock, int options)
248 {
249 int i;
250
251 for (i = 0; i < MAXSOCKS; i++) {
252 if (socklist[i].flags & SOCK_UNUSED) break;
253 }
254
255 if (i == MAXSOCKS) {
256 int j;
257
258 /* Expand table by 5 */
259 socklist = (sock_list *)realloc(socklist, (MAXSOCKS+5) * sizeof(sock_list));
260 memset(socklist+MAXSOCKS, 0, 5 * sizeof(sock_list));
261 for (j = 0; j < 5; j++) socklist[MAXSOCKS+j].flags = SOCK_UNUSED;
262 MAXSOCKS += 5;
263 }
264
265 memset(socklist+i, 0, sizeof(sock_list));
266 socklist[i].flags = options;
267 socklist[i].sock = sock;
268 return(i);
269 }
270
271 /* Request a normal socket for i/o
272 */
273 void setsock(int sock, int options)
274 {
275 int i = allocsock(sock, options);
276 int parm;
277
278 if (((sock != STDOUT) || backgrd) &&
279 !(socklist[i].flags & SOCK_NONSOCK)) {
280 parm = 1;
281 setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (void *) &parm, sizeof(int));
282
283 parm = 0;
284 setsockopt(sock, SOL_SOCKET, SO_LINGER, (void *) &parm, sizeof(int));
285 }
286 if (options & SOCK_LISTEN) {
287 /* Tris says this lets us grab the same port again next time */
288 parm = 1;
289 setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *) &parm, sizeof(int));
290 }
291 /* Yay async i/o ! */
292 fcntl(sock, F_SETFL, O_NONBLOCK);
293 }
294
295 int getsock(int options)
296 {
297 #ifdef IPV6
298 int sock = socket(AF_INET6, SOCK_STREAM, 0);
299 #else
300 int sock = socket(AF_INET, SOCK_STREAM, 0);
301 #endif
302
303 if (sock >= 0)
304 setsock(sock, options);
305 else
306 putlog(LOG_MISC, "*", "Warning: Can't create new socket!");
307 return sock;
308 }
309
310 /* Done with a socket
311 */
312 void killsock(register int sock)
313 {
314 register int i;
315
316 /* Ignore invalid sockets. */
317 if (sock < 0)
318 return;
319 for (i = 0; i < MAXSOCKS; i++) {
320 if ((socklist[i].sock == sock) && !(socklist[i].flags & SOCK_UNUSED)) {
321 close(socklist[i].sock);
322 if (socklist[i].inbuf != NULL)
323 free_null(socklist[i].inbuf);
324 if (socklist[i].outbuf != NULL) {
325 free_null(socklist[i].outbuf);
326 socklist[i].outbuflen = 0;
327 }
328 socklist[i].flags = SOCK_UNUSED;
329 return;
330 }
331 }
332 putlog(LOG_MISC, "*", "Attempt to kill un-allocated socket %d !!", sock);
333 }
334
335 /* Send connection request to proxy
336 */
337 static int proxy_connect(int sock, char *host, int port, int proxy)
338 {
339 unsigned char x[10];
340 struct hostent *hp;
341 char s[256];
342 int i;
343
344 /* socks proxy */
345 if (proxy == PROXY_SOCKS) {
346 /* numeric IP? */
347 if (host[strlen(host) - 1] >= '0' && host[strlen(host) - 1] <= '9') {
348 IP ip = ((IP) inet_addr(host)); /* drummer */
349 memcpy(x, &ip, 4); /* Beige@Efnet */
350 } else {
351 /* no, must be host.domain */
352 if (!setjmp(alarmret)) {
353 alarm(resolve_timeout);
354 hp = gethostbyname(host);
355 alarm(0);
356 } else {
357 hp = NULL;
358 }
359 if (hp == NULL) {
360 killsock(sock);
361 return -2;
362 }
363 memcpy(x, hp->h_addr, hp->h_length);
364 }
365 for (i = 0; i < MAXSOCKS; i++)
366 if (!(socklist[i].flags & SOCK_UNUSED) && socklist[i].sock == sock)
367 socklist[i].flags |= SOCK_PROXYWAIT; /* drummer */
368 snprintf(s, sizeof s, "\004\001%c%c%c%c%c%c%s", (port >> 8) % 256,
369 (port % 256), x[0], x[1], x[2], x[3], botuser);
370 tputs(sock, s, strlen(botuser) + 9); /* drummer */
371 } else if (proxy == PROXY_SUN) {
372 snprintf(s, sizeof s, "%s %d\n", host, port);
373 tputs(sock, s, strlen(s)); /* drummer */
374 }
375 return sock;
376 }
377
378 /* Starts a connection attempt to a socket
379 *
380 * If given a normal hostname, this will be resolved to the corresponding
381 * IP address first. PLEASE try to use the non-blocking dns functions
382 * instead and then call this function with the IP address to avoid blocking.
383 *
384 * returns <0 if connection refused:
385 * -1 neterror() type error
386 * -2 can't resolve hostname
387 */
388 int open_telnet_raw(int sock, char *server, int sport)
389 {
390 #ifdef IPV6
391 struct sockaddr_in6 name, vname;
392 #else
393 struct sockaddr_in name, vname;
394 #endif
395 struct hostent *hp;
396 char host[121];
397 int i, port;
398 volatile int proxy;
399
400 debug2("|NET| open_telnet_raw: %s %d", server, sport);
401
402 /* firewall? use socks */
403 if (firewall[0]) {
404 if (firewall[0] == '!') {
405 proxy = PROXY_SUN;
406 strcpy(host, &firewall[1]);
407 } else {
408 proxy = PROXY_SOCKS;
409 strcpy(host, firewall);
410 }
411 port = firewallport;
412 } else {
413 proxy = 0;
414 strcpy(host, server);
415 port = sport;
416 }
417
418 memset((char *) &name, 0, sizeof name);
419 #ifdef IPV6
420 name.sin6_family = AF_INET6;
421 name.sin6_port = htons(port);
422 #else
423 name.sin_family = AF_INET;
424 name.sin_port = htons(port);
425 #endif
426
427 if (!setjmp(alarmret)) {
428 char *p;
429 int type;
430
431 alarm(resolve_timeout);
432
433 if (!strncasecmp("ipv6%", host, 5)) {
434 type = AF_INET6;
435 p = host + 5;
436 debug1("|NET| checking only AAAA record for %s", p);
437 } else if (!strncasecmp("ipv4%", host, 5)) {
438 type = AF_INET;
439 p = host + 5;
440 debug1("|NET| checking only A record for %s", p);
441 } else {
442 type = AF_INET; /* af_preferred */
443 p = host;
444 }
445 alarm(resolve_timeout);
446 #ifndef IPV6
447 hp = gethostbyname(p);
448 #else
449 hp = gethostbyname2(p, type);
450 if (!hp && (p == host))
451 hp = gethostbyname2(p, (type == AF_INET6 ? AF_INET : AF_INET6));
452 #endif
453 alarm(0);
454 } else {
455 hp = NULL;
456 }
457 if (hp == NULL)
458 return -2;
459
460 #ifndef IPV6
461 memcpy(&name.sin_addr, hp->h_addr, hp->h_length);
462 name.sin_family = hp->h_addrtype;
463 #else
464 if (hp->h_addrtype == AF_INET6)
465 memcpy(&name.sin6_addr, hp->h_addr, hp->h_length);
466 else if (hp->h_addrtype == AF_INET)
467 name.sin6_addr = ipv4to6(*((unsigned int*) hp->h_addr));
468 else
469 return -123; /* panic :P */
470 name.sin6_family = AF_INET6;
471 #endif
472
473 memset((char *) &vname, 0, sizeof vname);
474 #ifndef IPV6
475 vname.sin_family = AF_INET;
476 vname.sin_addr.s_addr = (myip[0] ? getmyip() : INADDR_ANY);
477 #else
478 vname.sin6_family = AF_INET6;
479 if (IN6_IS_ADDR_V4MAPPED(&name.sin6_addr))
480 vname.sin6_addr = ipv4to6(myip[0] ? getmyip() : INADDR_ANY);
481 else
482 vname.sin6_addr = (myip6[0] ? getmyip6() : in6addr_any);
483 #endif
484 if (bind(sock, (struct sockaddr *) &vname, sizeof vname) < 0)
485 return -1;
486
487 for (i = 0; i < MAXSOCKS; i++) {
488 if (!(socklist[i].flags & SOCK_UNUSED) && (socklist[i].sock == sock))
489 socklist[i].flags = (socklist[i].flags & ~SOCK_VIRTUAL) | SOCK_CONNECT;
490 }
491 if (connect(sock, (struct sockaddr *) &name, (sizeof name)) < 0) {
492 if (errno == EINPROGRESS) {
493 /* Firewall? announce connect attempt to proxy */
494 if (firewall[0])
495 return proxy_connect(sock, server, sport, proxy);
496 return sock; /* async success! */
497 } else
498 return -1;
499 }
500 /* Synchronous? :/ */
501 if (firewall[0])
502 return proxy_connect(sock, server, sport, proxy);
503 return sock;
504 }
505
506 /* Ordinary non-binary connection attempt */
507 int open_telnet(char *server, int port)
508 {
509 int sock = getsock(0),
510 ret = open_telnet_raw(sock, server, port);
511
512 if (ret < 0)
513 killsock(sock);
514 return ret;
515 }
516
517 /* Returns a socket number for a listening socket that will accept any
518 * connection on a certain address -- port # is returned in port
519 * "" means on any address
520 */
521 int open_address_listen(char *addr, int *port)
522 {
523 int sock;
524 unsigned int addrlen;
525 #ifdef IPV6
526 struct sockaddr_in6 name;
527 #else
528 struct sockaddr_in name;
529 #endif
530
531 if (firewall[0]) {
532 /* FIXME: can't do listen port thru firewall yet */
533 putlog(LOG_MISC, "*", "!! Cant open a listen port (you are using a firewall)");
534 return -1;
535 }
536
537 sock = getsock(SOCK_LISTEN);
538 if (sock < 1)
539 return -1;
540
541 debug2("|NET| open_address_listen(\"%s\", %d)", addr, *port);
542
543 memset((char *) &name, 0, sizeof name);
544 #ifdef IPV6
545 name.sin6_family = AF_INET6;
546 name.sin6_port = htons(*port); /* 0 = just assign us a port */
547 if (!addr[0])
548 name.sin6_addr = in6addr_any;
549 else if (!inet_pton(AF_INET6, addr, &name.sin6_addr)) {
550 struct in_addr a4;
551 if (inet_aton(addr, &a4))
552 name.sin6_addr = ipv4to6(a4.s_addr);
553 else
554 name.sin6_addr = in6addr_any;
555 }
556 #else
557 name.sin_family = AF_INET;
558 name.sin_port = htons(*port); /* 0 = just assign us a port */
559 if (addr[0])
560 inet_aton(addr, &name.sin_addr);
561 else
562 name.sin_addr.s_addr = INADDR_ANY;
563 #endif
564 if (bind(sock, (struct sockaddr *) &name, sizeof name) < 0) {
565 killsock(sock);
566 if (errno == EADDRNOTAVAIL || errno == EAFNOSUPPORT)
567 return -2;
568 else
569 return -1;
570 }
571 /* what port are we on? */
572 addrlen = sizeof name;
573 if (getsockname(sock, (struct sockaddr *) &name, &addrlen) < 0) {
574 killsock(sock);
575 return -1;
576 }
577 #ifdef IPV6
578 *port = ntohs(name.sin6_port);
579 #else
580 *port = ntohs(name.sin_port);
581 #endif
582 if (listen(sock, 1) < 0) {
583 killsock(sock);
584 return -1;
585 }
586 return sock;
587 }
588
589 /* Returns a socket number for a listening socket that will accept any
590 * connection -- port # is returned in port
591 */
592 inline int open_listen(int *port, int af)
593 {
594 if (af == AF_INET)
595 return open_address_listen(myip, port);
596 #ifdef IPV6
597 else if (af == AF_INET6)
598 return open_address_listen(myip6, port);
599 #endif
600 else
601 return -1;
602 }
603
604 /* Returns the given network byte order IP address in the
605 * dotted format - "##.##.##.##"
606 * (it's IPv4 only, and it's okey - drummer)
607 */
608 char *iptostr(IP ip)
609 {
610 struct in_addr a;
611
612 a.s_addr = ip;
613 return inet_ntoa(a);
614 }
615
616 char *getlocaladdr(int sock)
617 {
618 static char buf[ADDRLEN];
619 #ifdef IPV6
620 struct sockaddr_in6 sa;
621 #else
622 struct sockaddr_in sa;
623 #endif
624 int len = sizeof sa;
625
626 if (sock == -1) { /* assuming IPv4... */
627 sprintf(buf, "%lu", (unsigned long int)
628 ntohl(natip[0] ? inet_addr(natip) : getmyip()));
629 return buf;
630 }
631
632 if (getsockname(sock, (struct sockaddr*) &sa, &len) == -1) {
633 debug1("|NET| getsockname() failed for sock %d", sock);
634 return 0;
635 }
636 #ifdef IPV6
637 if (IN6_IS_ADDR_V4MAPPED(&sa.sin6_addr))
638 sprintf(buf, "%lu",
639 (unsigned long int) ntohl(((uint32_t *)&sa.sin6_addr)[3]));
640 else
641 inet_ntop(AF_INET6, &(sa.sin6_addr), buf, sizeof buf);
642 #else
643 sprintf(buf, "%lu", (unsigned long int) ntohl(sa.sin_addr.s_addr));
644 #endif
645 return buf;
646 }
647
648 /* Short routine to answer a connect received on a socket made previously
649 * by open_listen ... returns hostname of the caller & the new socket
650 * does NOT dispose of old "public" socket!
651 */
652 int answer(int sock, char *caller, char *ip, unsigned short *port,
653 int binary)
654 {
655 int new_sock;
656 unsigned int addrlen;
657 #ifdef IPV6
658 struct sockaddr_in6 from;
659 #else
660 struct sockaddr_in from;
661 #endif
662
663 addrlen = sizeof from;
664 new_sock = accept(sock, (struct sockaddr *) &from, &addrlen);
665 if (new_sock < 0)
666 return -1;
667 if (ip != NULL) {
668 #ifdef IPV6
669 if (IN6_IS_ADDR_V4MAPPED(&from.sin6_addr))
670 inet_ntop(AF_INET, &(((uint32_t *)&from.sin6_addr)[3]), ip, ADDRMAX);
671 else
672 inet_ntop(AF_INET6, &(from.sin6_addr), ip, ADDRMAX);
673 #else
674 inet_ntop(AF_INET, &(from.sin_addr.s_addr), ip, ADDRMAX);
675 #endif
676 /* This is now done asynchronously. We now only provide the IP address.
677 */
678 strncpyz(caller, ip, 121);
679 }
680 if (port != NULL)
681 #ifdef IPV6
682 *port = ntohs(from.sin6_port);
683 #else
684 *port = ntohs(from.sin_port);
685 #endif
686 /* Set up all the normal socket crap */
687 setsock(new_sock, (binary ? SOCK_BINARY : 0));
688 return new_sock;
689 }
690
691 /* Like open_telnet, but uses server & port specifications of dcc
692 */
693 int open_telnet_dcc(int sock, char *server, char *port)
694 {
695 int p;
696 struct in_addr ia;
697
698 debug2("|NET| open_telnet_dcc: %s %s", server, port);
699 if (port != NULL)
700 p = atoi(port);
701 else
702 return -3;
703 if (server == NULL)
704 return -3;
705 /* fix the IPv4 IP format (ie: 167772161 -> 10.0.0.1) */
706 if (inet_aton(server, &ia))
707 return open_telnet_raw(sock, inet_ntoa(ia), p);
708 else
709 return open_telnet_raw(sock, server, p);
710 }
711
712 void egg_dns_gotanswer(int status, adns_answer *aw, char *origname)
713 {
714 char name[UHOSTLEN];
715 #ifdef IPV6
716 char *orign2;
717 #endif
718
719 if (!aw) {
720 debug0("|DNS| egg_dns_gotanswer: ANSWER IS NULL!");
721 return;
722 }
723 if (!origname) {
724 debug0("|DNS| egg_dns_gotanswer: origname is NULL!");
725 return;
726 }
727
728 debug2("|DNS| egg_dns_gotanswer: status=%d adns_answer=%x", status, (int)aw);
729 status = 0;
730 if ((aw->type == adns_r_addr)
731 #ifdef IPV6
732 || (aw->type == adns_r_addr6)
733 #endif
734 ) {
735 if ((aw->status == adns_s_ok) && (aw->nrrs > 0)) {
736 adns_rr_addr *rrp = aw->rrs.untyped;
737 if (rrp->addr.sa.sa_family == AF_INET) {
738 inet_ntop(AF_INET, &(rrp->addr.inet.sin_addr), name, UHOSTLEN-1);
739 status = 1;
740 #ifdef IPV6
741 } else if (rrp->addr.sa.sa_family == AF_INET6) {
742 inet_ntop(AF_INET6, &(rrp->addr.inet6.sin6_addr), name, UHOSTLEN-1);
743 status = 1;
744 #endif
745 }
746 #ifdef IPV6
747 } else if ((aw->type == adns_r_addr /* af_preferred */) &&
748 strncasecmp(origname, "ipv6%", 5) &&
749 strncasecmp(origname, "ipv4%", 5)) {
750 adns_query q6;
751 orign2 = strdup(origname);
752 /* ...it may be AAAA */
753 debug1("|DNS| egg_dns_gotanswer: A failed, checking for AAAA (%s)", origname);
754 adns_submit(ads, origname, adns_r_addr6, 0, orign2, &q6);
755 status = -1;
756 #endif
757 }
758 if (status == 0)
759 strcpy(name, "0.0.0.0");
760 if (status >= 0) {
761 debug3("|DNS| egg_dns_gotanswer: (ipbyhost) host: %s ip: %s status: %d", origname, name, status);
762 call_ipbyhost(origname, name, status);
763 }
764 } else if ((aw->type == adns_r_ptr_ip6) || (aw->type == adns_r_ptr)) {
765 if ((aw->status == adns_s_ok) && (aw->nrrs > 0)) {
766 if (aw->rrs.str) {
767 strncpyz(name, *(aw->rrs.str), UHOSTLEN);
768 status = 1;
769 }
770 }
771 if (!status) {
772 if (origname)
773 strncpyz(name, origname, UHOSTLEN);
774 else
775 strcpy(name, "error");
776 }
777 debug3("|DNS| egg_dns_gotanswer: (hostbyip) ip: %s host: %s status: %d", origname, name, status);
778 call_hostbyip(origname, name, status);
779 } else
780 debug0("|DNS| egg_dns_gotanswer: got unknow type of answer ?!");
781 free(origname);
782 }
783
784 void egg_dns_checkall()
785 {
786 adns_query q, r;
787 adns_answer *answer;
788 char *origname;
789
790 adns_forallqueries_begin(ads);
791 while ((q = adns_forallqueries_next(ads, (void **)&r)) != NULL) {
792 switch (adns_check(ads, &q, &answer, (void **)&origname)) {
793 case 0: /* ok */
794 egg_dns_gotanswer(1, answer, origname);
795 break;
796 case EAGAIN: /* Go into the queue again */
797 break;
798 default: /* failed */
799 egg_dns_gotanswer(0, answer, origname);
800 break;
801 }
802 }
803 }
804
805 /* Attempts to read from all the sockets in socklist
806 * fills s with up to 511 bytes if available, and returns the array index
807 *
808 * on EOF: returns -1, with socket in len
809 * on socket error: returns -2
810 * if nothing is ready: returns -3
811 */
812 static int sockread(char *s, int *len)
813 {
814 fd_set fd, fdw, fde;
815 int fds, i, x, fdtmp;
816 struct timeval t, tnow;
817 struct timeval *pt = &t;
818 int grab = 511;
819 egg_timeval_t howlong;
820
821 fds = getdtablesize();
822 #ifdef FD_SETSIZE
823 if (fds > FD_SETSIZE)
824 fds = FD_SETSIZE; /* Fixes YET ANOTHER freebsd bug!!! */
825 #endif
826
827 if (timer_get_shortest(&howlong)) {
828 /* No timer, default to 1 second. */
829 t.tv_sec = 1;
830 t.tv_usec = 0;
831 }
832 else {
833 t.tv_sec = howlong.sec;
834 t.tv_usec = howlong.usec;
835 }
836
837 FD_ZERO(&fd);
838
839 for (i = 0; i < MAXSOCKS; i++)
840 if (!(socklist[i].flags & (SOCK_UNUSED | SOCK_VIRTUAL))) {
841 if ((socklist[i].sock == STDOUT) && !backgrd)
842 fdtmp = STDIN;
843 else
844 fdtmp = socklist[i].sock;
845 /*
846 * Looks like that having more than a call, in the same
847 * program, to the FD_SET macro, triggers a bug in gcc.
848 * SIGBUS crashing binaries used to be produced on a number
849 * (prolly all?) of 64 bits architectures.
850 * Make your best to avoid to make it happen again.
851 *
852 * ITE
853 */
854 FD_SET(fdtmp , &fd);
855 }
856 tnow.tv_sec = time(NULL);
857 tnow.tv_usec = 0;
858 adns_beforeselect(ads, &fds, &fd, &fdw, &fde, &pt, 0, &tnow);
859 #ifdef HPUX_HACKS
860 #ifndef HPUX10_HACKS
861 x = select(fds, (int *) &fd, (int *) NULL, (int *) NULL, &t);
862 #else
863 x = select(fds, &fd, NULL, NULL, &t);
864 #endif
865 #else
866 x = select(fds, &fd, NULL, NULL, &t);
867 #endif
868 tnow.tv_sec = time(NULL);
869 tnow.tv_usec = 0;
870 adns_afterselect(ads, fds, &fd, &fdw, &fde, &tnow);
871
872 /* dns stuff */
873 egg_dns_checkall();
874
875 if (x > 0) {
876 /* Something happened */
877 for (i = 0; i < MAXSOCKS; i++) {
878 if ((!(socklist[i].flags & SOCK_UNUSED)) &&
879 ((FD_ISSET(socklist[i].sock, &fd)) ||
880 ((socklist[i].sock == STDOUT) && (!backgrd) &&
881 (FD_ISSET(STDIN, &fd))))) {
882 if (socklist[i].flags & (SOCK_LISTEN | SOCK_CONNECT)) {
883 /* Listening socket -- don't read, just return activity */
884 /* Same for connection attempt */
885 /* (for strong connections, require a read to succeed first) */
886 if (socklist[i].flags & SOCK_PROXYWAIT) { /* drummer */
887 /* Hang around to get the return code from proxy */
888 grab = 10;
889 } else if (!(socklist[i].flags & SOCK_STRONGCONN)) {
890 debug1("net: connect! sock %d", socklist[i].sock);
891 s[0] = 0;
892 *len = 0;
893 return i;
894 }
895 } else if (socklist[i].flags & SOCK_PASS) {
896 s[0] = 0;
897 *len = 0;
898 return i;
899 }
900 if ((socklist[i].sock == STDOUT) && !backgrd)
901 x = read(STDIN, s, grab);
902 else
903 x = read(socklist[i].sock, s, grab);
904 if (x <= 0) { /* eof */
905 if (errno == EAGAIN) {
906 s[0] = 0;
907 *len = 0;
908 return -3;
909 }
910 *len = socklist[i].sock;
911 socklist[i].flags &= ~SOCK_CONNECT;
912 debug1("net: eof!(read) socket %d", socklist[i].sock);
913 return -1;
914 }
915 s[x] = 0;
916 *len = x;
917 if (socklist[i].flags & SOCK_PROXYWAIT) {
918 debug2("net: socket: %d proxy errno: %d", socklist[i].sock, s[1]);
919 socklist[i].flags &= ~(SOCK_CONNECT | SOCK_PROXYWAIT);
920 switch (s[1]) {
921 case 90: /* Success */
922 s[0] = 0;
923 *len = 0;
924 return i;
925 case 91: /* Failed */
926 errno = ECONNREFUSED;
927 break;
928 case 92: /* No identd */
929 case 93: /* Identd said wrong username */
930 /* A better error message would be "socks misconfigured"
931 * or "identd not working" but this is simplest.
932 */
933 errno = ENETUNREACH;
934 break;
935 }
936 *len = socklist[i].sock;
937 return -1;
938 }
939 return i;
940 }
941 }
942 } else if (x == -1)
943 return -2; /* socket error */
944 else {
945 s[0] = 0;
946 *len = 0;
947 }
948 return -3;
949 }
950
951 /* sockgets: buffer and read from sockets
952 *
953 * Attempts to read from all registered sockets for up to one second. if
954 * after one second, no complete data has been received from any of the
955 * sockets, 's' will be empty, 'len' will be 0, and sockgets will return -3.
956 * if there is returnable data received from a socket, the data will be
957 * in 's' (null-terminated if non-binary), the length will be returned
958 * in len, and the socket number will be returned.
959 * normal sockets have their input buffered, and each call to sockgets
960 * will return one line terminated with a '\n'. binary sockets are not
961 * buffered and return whatever coems in as soon as it arrives.
962 * listening sockets will return an empty string when a connection comes in.
963 * connecting sockets will return an empty string on a successful connect,
964 * or EOF on a failed connect.
965 * if an EOF is detected from any of the sockets, that socket number will be
966 * put in len, and -1 will be returned.
967 * the maximum length of the string returned is 512 (including null)
968 *
969 * Returns -4 if we handled something that shouldn't be handled by the
970 * dcc functions. Simply ignore it.
971 */
972
973 int sockgets(char *s, int *len)
974 {
975 char xx[514], *p, *px;
976 int ret, i, data = 0;
977
978 for (i = 0; i < MAXSOCKS; i++) {
979 /* Check for stored-up data waiting to be processed */
980 if (!(socklist[i].flags & SOCK_UNUSED) &&
981 !(socklist[i].flags & SOCK_BUFFER) && (socklist[i].inbuf != NULL)) {
982 if (!(socklist[i].flags & SOCK_BINARY)) {
983 /* look for \r too cos windows can't follow RFCs */
984 p = strchr(socklist[i].inbuf, '\n');
985 if (p == NULL)
986 p = strchr(socklist[i].inbuf, '\r');
987 if (p != NULL) {
988 *p = 0;
989 if (strlen(socklist[i].inbuf) > 510)
990 socklist[i].inbuf[510] = 0;
991 strcpy(s, socklist[i].inbuf);
992 /* Uhm... very strange way to code this... */
993 px = (char *) malloc(strlen(p + 1) + 1);
994 strcpy(px, p + 1);
995 free(socklist[i].inbuf);
996 if (px[0])
997 socklist[i].inbuf = px;
998 else {
999 free(px);
1000 socklist[i].inbuf = NULL;
1001 }
1002 /* Strip CR if this was CR/LF combo */
1003 if (s[strlen(s) - 1] == '\r')
1004 s[strlen(s) - 1] = 0;
1005 *len = strlen(s);
1006 return socklist[i].sock;
1007 }
1008 } else {
1009 /* Handling buffered binary data (must have been SOCK_BUFFER before). */
1010 if (socklist[i].inbuflen <= 510) {
1011 *len = socklist[i].inbuflen;
1012 memcpy(s, socklist[i].inbuf, socklist[i].inbuflen);
1013 free_null(socklist[i].inbuf);
1014 socklist[i].inbuflen = 0;
1015 } else {
1016 /* Split up into chunks of 510 bytes. */
1017 *len = 510;
1018 memcpy(s, socklist[i].inbuf, *len);
1019 memcpy(socklist[i].inbuf, socklist[i].inbuf + *len, *len);
1020 socklist[i].inbuflen -= *len;
1021 socklist[i].inbuf = realloc(socklist[i].inbuf,
1022 socklist[i].inbuflen);
1023 }
1024 return socklist[i].sock;
1025 }
1026 }
1027 /* Also check any sockets that might have EOF'd during write */
1028 if (!(socklist[i].flags & SOCK_UNUSED)
1029 && (socklist[i].flags & SOCK_EOFD)) {
1030 s[0] = 0;
1031 *len = socklist[i].sock;
1032 return -1;
1033 }
1034 }
1035 /* No pent-up data of any worth -- down to business */
1036 *len = 0;
1037 ret = sockread(xx, len);
1038 if (ret < 0) {
1039 s[0] = 0;
1040 return ret;
1041 }
1042 /* Binary, listening and passed on sockets don't get buffered. */
1043 if (socklist[ret].flags & SOCK_CONNECT) {
1044 if (socklist[ret].flags & SOCK_STRONGCONN) {
1045 socklist[ret].flags &= ~SOCK_STRONGCONN;
1046 /* Buffer any data that came in, for future read. */
1047 socklist[ret].inbuflen = *len;
1048 socklist[ret].inbuf = (char *) malloc(*len + 1);
1049 /* It might be binary data. You never know. */
1050 memcpy(socklist[ret].inbuf, xx, *len);
1051 socklist[ret].inbuf[*len] = 0;
1052 }
1053 socklist[ret].flags &= ~SOCK_CONNECT;
1054 s[0] = 0;
1055 return socklist[ret].sock;
1056 }
1057 if (socklist[ret].flags & SOCK_BINARY) {
1058 memcpy(s, xx, *len);
1059 return socklist[ret].sock;
1060 }
1061 if ((socklist[ret].flags & SOCK_LISTEN) ||
1062 (socklist[ret].flags & SOCK_PASS))
1063 return socklist[ret].sock;
1064 if (socklist[ret].flags & SOCK_BUFFER) {
1065 socklist[ret].inbuf = (char *) realloc(socklist[ret].inbuf,
1066 socklist[ret].inbuflen + *len + 1);
1067 memcpy(socklist[ret].inbuf + socklist[ret].inbuflen, xx, *len);
1068 socklist[ret].inbuflen += *len;
1069 /* We don't know whether it's binary data. Make sure normal strings
1070 will be handled properly later on too. */
1071 socklist[ret].inbuf[socklist[ret].inbuflen] = 0;
1072 return -4; /* Ignore this one. */
1073 }
1074 /* Might be necessary to prepend stored-up data! */
1075 if (socklist[ret].inbuf != NULL) {
1076 p = socklist[ret].inbuf;
1077 socklist[ret].inbuf = (char *) malloc(strlen(p) + strlen(xx) + 1);
1078 strcpy(socklist[ret].inbuf, p);
1079 strcat(socklist[ret].inbuf, xx);
1080 free(p);
1081 if (strlen(socklist[ret].inbuf) < 512) {
1082 strcpy(xx, socklist[ret].inbuf);
1083 free_null(socklist[ret].inbuf);
1084 socklist[ret].inbuflen = 0;
1085 } else {
1086 p = socklist[ret].inbuf;
1087 socklist[ret].inbuflen = strlen(p) - 510;
1088 socklist[ret].inbuf = (char *) malloc(socklist[ret].inbuflen + 1);
1089 strcpy(socklist[ret].inbuf, p + 510);
1090 *(p + 510) = 0;
1091 strcpy(xx, p);
1092 free(p);
1093 /* (leave the rest to be post-pended later) */
1094 }
1095 }
1096 /* Look for EOL marker; if it's there, i have something to show */
1097 p = strchr(xx, '\n');
1098 if (p == NULL)
1099 p = strchr(xx, '\r');
1100 if (p != NULL) {
1101 *p = 0;
1102 strcpy(s, xx);
1103 strcpy(xx, p + 1);
1104 if (s[strlen(s) - 1] == '\r')
1105 s[strlen(s) - 1] = 0;
1106 data = 1; /* DCC_CHAT may now need to process a
1107 blank line */
1108 /* NO! */
1109 /* if (!s[0]) strcpy(s," "); */
1110 } else {
1111 s[0] = 0;
1112 if (strlen(xx) >= 510) {
1113 /* String is too long, so just insert fake \n */
1114 strcpy(s, xx);
1115 xx[0] = 0;
1116 data = 1;
1117 }
1118 }
1119 *len = strlen(s);
1120 /* Anything left that needs to be saved? */
1121 if (!xx[0]) {
1122 if (data)
1123 return socklist[ret].sock;
1124 else
1125 return -3;
1126 }
1127 /* Prepend old data back */
1128 if (socklist[ret].inbuf != NULL) {
1129 p = socklist[ret].inbuf;
1130 socklist[ret].inbuflen = strlen(p) + strlen(xx);
1131 socklist[ret].inbuf = (char *) malloc(socklist[ret].inbuflen + 1);
1132 strcpy(socklist[ret].inbuf, xx);
1133 strcat(socklist[ret].inbuf, p);
1134 free(p);
1135 } else {
1136 socklist[ret].inbuflen = strlen(xx);
1137 socklist[ret].inbuf = (char *) malloc(socklist[ret].inbuflen + 1);
1138 strcpy(socklist[ret].inbuf, xx);
1139 }
1140 if (data) {
1141 return socklist[ret].sock;
1142 } else {
1143 return -3;
1144 }
1145 }
1146
1147 /* Dump something to a socket
1148 */
1149 void tputs(register int z, char *s, unsigned int len)
1150 {
1151 register int i, x, idx;
1152 char *p;
1153 static int inhere = 0;
1154
1155 if (z < 0)
1156 return; /* um... HELLO?! sanity check please! */
1157 if (((z == STDOUT) || (z == STDERR)) && (!backgrd || use_stderr)) {
1158 write(z, s, len);
1159 return;
1160 }
1161 for (i = 0; i < MAXSOCKS; i++) {
1162 if (!(socklist[i].flags & SOCK_UNUSED) && (socklist[i].sock == z)) {
1163 for (idx = 0; idx < dcc_total; idx++) {
1164 if (dcc[idx].sock == z) {
1165 if (dcc[idx].type) {
1166 if (dcc[idx].type->name) {
1167 if (!strncmp(dcc[idx].type->name, "BOT", 3)) {
1168 otraffic_bn_today += len;
1169 break;
1170 } else if (!strcmp(dcc[idx].type->name, "SERVER")) {
1171 otraffic_irc_today += len;
1172 break;
1173 } else if (!strncmp(dcc[idx].type->name, "CHAT", 4)) {
1174 otraffic_dcc_today += len;
1175 break;
1176 } else if (!strncmp(dcc[idx].type->name, "FILES", 5)) {
1177 otraffic_filesys_today += len;
1178 break;
1179 } else if (!strcmp(dcc[idx].type->name, "SEND")) {
1180 otraffic_trans_today += len;
1181 break;
1182 } else if (!strncmp(dcc[idx].type->name, "GET", 3)) {
1183 otraffic_trans_today += len;
1184 break;
1185 } else {
1186 otraffic_unknown_today += len;
1187 break;
1188 }
1189 }
1190 }
1191 }
1192 }
1193
1194 if (socklist[i].outbuf != NULL) {
1195 /* Already queueing: just add it */
1196 p = (char *) realloc(socklist[i].outbuf, socklist[i].outbuflen + len);
1197 memcpy(p + socklist[i].outbuflen, s, len);
1198 socklist[i].outbuf = p;
1199 socklist[i].outbuflen += len;
1200 return;
1201 }
1202 /* Try. */
1203 x = write(z, s, len);
1204 if (x == (-1))
1205 x = 0;
1206 if (x < len) {
1207 /* Socket is full, queue it */
1208 socklist[i].outbuf = (char *) malloc(len - x);
1209 memcpy(socklist[i].outbuf, &s[x], len - x);
1210 socklist[i].outbuflen = len - x;
1211 }
1212 return;
1213 }
1214 }
1215 /* Make sure we don't cause a crash by looping here */
1216 if (!inhere) {
1217 inhere = 1;
1218
1219 putlog(LOG_MISC, "*", "!!! writing to nonexistent socket: %d", z);
1220 s[strlen(s) - 1] = 0;
1221 putlog(LOG_MISC, "*", "!-> '%s'", s);
1222
1223 inhere = 0;
1224 }
1225 }
1226
1227 /* tputs might queue data for sockets, let's dump as much of it as
1228 * possible.
1229 */
1230 void dequeue_sockets()
1231 {
1232 int i, x;
1233
1234 for (i = 0; i < MAXSOCKS; i++) {
1235 if (!(socklist[i].flags & SOCK_UNUSED) &&
1236 socklist[i].outbuf != NULL) {
1237 /* Trick tputs into doing the work */
1238 x = write(socklist[i].sock, socklist[i].outbuf,
1239 socklist[i].outbuflen);
1240 if ((x < 0) && (errno != EAGAIN)
1241 #ifdef EBADSLT
1242 && (errno != EBADSLT)
1243 #endif
1244 #ifdef ENOTCONN
1245 && (errno != ENOTCONN)
1246 #endif
1247 ) {
1248 /* This detects an EOF during writing */
1249 debug3("net: eof!(write) socket %d (%s,%d)", socklist[i].sock,
1250 strerror(errno), errno);
1251 socklist[i].flags |= SOCK_EOFD;
1252 } else if (x == socklist[i].outbuflen) {
1253 /* If the whole buffer was sent, nuke it */
1254 free_null(socklist[i].outbuf);
1255 socklist[i].outbuflen = 0;
1256 } else if (x > 0) {
1257 char *p = socklist[i].outbuf;
1258
1259 /* This removes any sent bytes from the beginning of the buffer */
1260 socklist[i].outbuf = (char *) malloc(socklist[i].outbuflen - x);
1261 memcpy(socklist[i].outbuf, p + x, socklist[i].outbuflen - x);
1262 socklist[i].outbuflen -= x;
1263 free(p);
1264 }
1265
1266 /* All queued data was sent. Call handler if one exists and the
1267 * dcc entry wants it.
1268 */
1269 if (!socklist[i].outbuf) {
1270 int idx = findanyidx(socklist[i].sock);
1271
1272 if (idx > 0 && dcc[idx].type && dcc[idx].type->outdone)
1273 dcc[idx].type->outdone(idx);
1274 }
1275 }
1276 }
1277 }
1278
1279
1280 /*
1281 * Debugging stuff
1282 */
1283
1284 void tell_netdebug(int idx)
1285 {
1286 int i;
1287 char s[80];
1288
1289 dprintf(idx, "Open sockets:");
1290 for (i = 0; i < MAXSOCKS; i++) {
1291 if (!(socklist[i].flags & SOCK_UNUSED)) {
1292 sprintf(s, " %d", socklist[i].sock);
1293 if (socklist[i].flags & SOCK_BINARY)
1294 strcat(s, " (binary)");
1295 if (socklist[i].flags & SOCK_LISTEN)
1296 strcat(s, " (listen)");
1297 if (socklist[i].flags & SOCK_PASS)
1298 strcat(s, " (passed on)");
1299 if (socklist[i].flags & SOCK_CONNECT)
1300 strcat(s, " (connecting)");
1301 if (socklist[i].flags & SOCK_STRONGCONN)
1302 strcat(s, " (strong)");
1303 if (socklist[i].flags & SOCK_NONSOCK)
1304 strcat(s, " (file)");
1305 if (socklist[i].inbuf != NULL)
1306 sprintf(&s[strlen(s)], " (inbuf: %04X)", strlen(socklist[i].inbuf));
1307 if (socklist[i].outbuf != NULL)
1308 sprintf(&s[strlen(s)], " (outbuf: %06lX)", socklist[i].outbuflen);
1309 strcat(s, ",");
1310 dprintf(idx, "%s", s);
1311 }
1312 }
1313 dprintf(idx, " done.\n");
1314 }
1315
1316 /* Checks wether the referenced socket has data queued.
1317 *
1318 * Returns true if the incoming/outgoing (depending on 'type') queues
1319 * contain data, otherwise false.
1320 */
1321 int sock_has_data(int type, int sock)
1322 {
1323 int ret = 0, i;
1324
1325 for (i = 0; i < MAXSOCKS; i++)
1326 if (!(socklist[i].flags & SOCK_UNUSED) && socklist[i].sock == sock)
1327 break;
1328 if (i < MAXSOCKS) {
1329 switch (type) {
1330 case SOCK_DATA_OUTGOING:
1331 ret = (socklist[i].outbuf != NULL);
1332 break;
1333 case SOCK_DATA_INCOMING:
1334 ret = (socklist[i].inbuf != NULL);
1335 break;
1336 }
1337 } else
1338 debug1("sock_has_data: could not find socket #%d, returning false.", sock);
1339 return ret;
1340 }
1341
1342 /* flush_inbuf():
1343 * checks if there's data in the incoming buffer of an connection
1344 * and flushs the buffer if possible
1345 *
1346 * returns: -1 if the dcc entry wasn't found
1347 * -2 if dcc[idx].type->activity doesn't exist and the data couldn't
1348 * be handled
1349 * 0 if buffer was empty
1350 * otherwise length of flushed buffer
1351 */
1352 int flush_inbuf(int idx)
1353 {
1354 int i, len;
1355 char *inbuf;
1356
1357 assert((idx >= 0) && (idx < dcc_total));
1358 for (i = 0; i < MAXSOCKS; i++) {
1359 if ((dcc[idx].sock == socklist[i].sock)
1360 && !(socklist[i].flags & SOCK_UNUSED)) {
1361 len = socklist[i].inbuflen;
1362 if ((len > 0) && socklist[i].inbuf) {
1363 if (dcc[idx].type && dcc[idx].type->activity) {
1364 inbuf = socklist[i].inbuf;
1365 socklist[i].inbuf = NULL;
1366 dcc[idx].type->activity(idx, inbuf, len);
1367 free(inbuf);
1368 return len;
1369 } else
1370 return -2;
1371 } else
1372 return 0;
1373 }
1374 }
1375 return -1;
1376 }

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23