/[weechat]/weechat/src/irc/irc-dcc.c
ViewVC logotype

Diff of /weechat/src/irc/irc-dcc.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.24 by flashcode, Tue Jul 19 17:35:51 2005 UTC revision 1.25 by kolter, Thu Aug 4 19:01:29 2005 UTC
# Line 34  Line 34 
34  #include <sys/types.h>  #include <sys/types.h>
35  #include <sys/socket.h>  #include <sys/socket.h>
36  #include <netinet/in.h>  #include <netinet/in.h>
37    #include <arpa/inet.h>
38    #include <netdb.h>
39    
40  #include "../common/weechat.h"  #include "../common/weechat.h"
41  #include "irc.h"  #include "irc.h"
# Line 233  int Line 235  int
235  dcc_connect (t_irc_dcc *ptr_dcc)  dcc_connect (t_irc_dcc *ptr_dcc)
236  {  {
237      struct sockaddr_in addr;      struct sockaddr_in addr;
238        struct hostent *hostent;
239        char *ip4;
240            
241      if (ptr_dcc->type == DCC_CHAT_SEND)      if (ptr_dcc->type == DCC_CHAT_SEND)
242          ptr_dcc->status = DCC_WAITING;          ptr_dcc->status = DCC_WAITING;
# Line 245  dcc_connect (t_irc_dcc *ptr_dcc) Line 249  dcc_connect (t_irc_dcc *ptr_dcc)
249          if (ptr_dcc->sock == -1)          if (ptr_dcc->sock == -1)
250              return 0;              return 0;
251      }      }
252      if (fcntl (ptr_dcc->sock, F_SETFL, O_NONBLOCK) == -1)  
         return 0;  
       
253      /* for sending (chat or file), listen to socket for a connection */      /* for sending (chat or file), listen to socket for a connection */
254      if (DCC_IS_SEND(ptr_dcc->type))      if (DCC_IS_SEND(ptr_dcc->type))
255      {        {
256            if (fcntl (ptr_dcc->sock, F_SETFL, O_NONBLOCK) == -1)
257              return 0;    
258          if (listen (ptr_dcc->sock, 1) == -1)          if (listen (ptr_dcc->sock, 1) == -1)
259              return 0;              return 0;
260          if (fcntl (ptr_dcc->sock, F_SETFL, 0) == -1)          if (fcntl (ptr_dcc->sock, F_SETFL, 0) == -1)
# Line 260  dcc_connect (t_irc_dcc *ptr_dcc) Line 264  dcc_connect (t_irc_dcc *ptr_dcc)
264      /* for receiving (chat or file), connect to listening host */      /* for receiving (chat or file), connect to listening host */
265      if (DCC_IS_RECV(ptr_dcc->type))      if (DCC_IS_RECV(ptr_dcc->type))
266      {      {
267          memset (&addr, 0, sizeof (addr));        if (cfg_proxy_use)
268          addr.sin_port = htons (ptr_dcc->port);          {
269          addr.sin_family = AF_INET;            memset (&addr, 0, sizeof (addr));
270          addr.sin_addr.s_addr = htonl (ptr_dcc->addr);            addr.sin_addr.s_addr = htonl (ptr_dcc->addr);
271          connect (ptr_dcc->sock, (struct sockaddr *) &addr, sizeof (addr));            ip4 = inet_ntoa(addr.sin_addr);
272    
273              memset (&addr, 0, sizeof (addr));
274              addr.sin_port = htons (cfg_proxy_port);
275              addr.sin_family = AF_INET;
276              if ((hostent = gethostbyname (cfg_proxy_address)) == NULL)
277                return 0;
278              memcpy(&(addr.sin_addr),*(hostent->h_addr_list), sizeof(struct in_addr));
279    
280              if (connect (ptr_dcc->sock, (struct sockaddr *) &addr, sizeof (addr)) == -1)
281                return 0;
282              if (pass_proxy(ptr_dcc->sock, ip4, ptr_dcc->port, ptr_dcc->server->username) == -1)
283                return 0;
284            }
285          else
286            {
287              memset (&addr, 0, sizeof (addr));
288              addr.sin_port = htons (ptr_dcc->port);
289              addr.sin_family = AF_INET;
290              addr.sin_addr.s_addr = htonl (ptr_dcc->addr);
291              if (connect (ptr_dcc->sock, (struct sockaddr *) &addr, sizeof (addr)) == -1)
292                return 0;
293            }      
294          if (fcntl (ptr_dcc->sock, F_SETFL, O_NONBLOCK) == -1)
295            return 0;      
296      }      }
297            
298      return 1;      return 1;

Legend:
Removed from v.1.24  
changed lines
  Added in v.1.25

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26