/[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.53 - (show annotations) (download) (as text)
Sat Jan 19 20:08:58 2002 UTC (18 years, 1 month ago) by ite
Branch: MAIN
Changes since 1.52: +3 -1 lines
File MIME type: text/x-chdr
* varoius header inclusion cleanups
* moved FILEDB* defines from src/egg.h to a more suitable place in modules/filesys/filesys.h
* moved NORMAL and QUICK defines from src/egg.h to a more suitable place in modules/irc/irc.h
* fixed a warning in modules/perlscript/perlscript.c
* created src/misc.h and src/logfile.h. Moved in them the respective prototypes from src/proto.h, and the respective defines from src/egg.h
* moved private structures from src/dns.h to src/dns.c
* moved src/dns.c's related prototypes from src/egg.h to src/dns.h
* moved RES_* defines from src/egg.h to dns.h
* removed some unneeded defines here and there
* moved LOG_* defines from src/egg.h to src/logfile.h
* dns_events wasn't static

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

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23