Changeset 60e4df3
- Timestamp:
- 2010-03-17T23:23:27Z (15 years ago)
- Branches:
- master
- Children:
- c1a3c27
- Parents:
- e8c8d00
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
dcc.c
re8c8d00 r60e4df3 61 61 */ 62 62 unsigned int receivedchunks=0, receiveddata=0; 63 64 int max_packet_size = 0;65 63 66 64 static void dcc_finish( file_transfer_t *file ); … … 133 131 struct sockaddr_storage saddr; 134 132 char *errmsg; 135 char host[ INET6_ADDRSTRLEN];133 char host[HOST_NAME_MAX]; 136 134 char port[6]; 137 135 … … 290 288 291 289 /* 292 * fills max_packet_size with twice the TCP maximum segment size293 */294 gboolean dcc_check_maxseg( dcc_file_transfer_t *df, int fd )295 {296 /*297 * use twice the maximum segment size as a maximum for calls to send().298 */299 if( max_packet_size == 0 )300 {301 unsigned int mpslen = sizeof( max_packet_size );302 if( getsockopt( fd, IPPROTO_TCP, TCP_MAXSEG, &max_packet_size, &mpslen ) )303 return dcc_abort( df, "getsockopt() failed" );304 max_packet_size *= 2;305 }306 return TRUE;307 }308 309 /*310 290 * After setup, the transfer itself is handled entirely by this function. 311 291 * There are basically four things to handle: connect, receive, send, and error. … … 334 314 file->status = FT_STATUS_TRANSFERRING; 335 315 sock_make_nonblocking( fd ); 336 337 if ( !dcc_check_maxseg( df, fd ) )338 return FALSE;339 316 340 317 /* IM protocol callback */ … … 446 423 { 447 424 ft->status = FT_STATUS_TRANSFERRING; 448 if ( !dcc_check_maxseg( df, fd ) )449 return FALSE;450 425 451 426 //df->watch_in = b_input_add( df->fd, GAIM_INPUT_READ, dccs_recv_proto, df ); -
lib/ftutil.c
re8c8d00 r60e4df3 28 28 #include "lib/ftutil.h" 29 29 30 /* Some ifdefs for ulibc and apparently also BSD (Thanks to Whoopie) */31 #ifndef HOST_NAME_MAX32 #include <sys/param.h>33 #ifdef MAXHOSTNAMELEN34 #define HOST_NAME_MAX MAXHOSTNAMELEN35 #else36 #define HOST_NAME_MAX 25537 #endif38 #endif39 40 30 #define ASSERTSOCKOP(op, msg) \ 41 31 if( (op) == -1 ) {\ 42 sprintf( errmsg, msg ": %s", strerror( errno ) ); \32 g_snprintf( errmsg, sizeof( errmsg ), msg ": %s", strerror( errno ) ); \ 43 33 return -1; } 44 34 … … 46 36 * Creates a listening socket and returns it in saddr_ptr. 47 37 */ 48 int ft_listen( struct sockaddr_storage *saddr_ptr, char *host p, char *port, int for_bitlbee_client, char **errptr )38 int ft_listen( struct sockaddr_storage *saddr_ptr, char *host, char *port, int for_bitlbee_client, char **errptr ) 49 39 { 50 int fd, gret,saddrlen;40 int fd, gret, saddrlen; 51 41 struct addrinfo hints, *rp; 52 42 socklen_t ssize = sizeof( struct sockaddr_storage ); 53 43 struct sockaddr_storage saddrs, *saddr = &saddrs; 54 44 static char errmsg[1024]; 55 char host[ HOST_NAME_MAX + 1 ];56 45 char *ftlisten = global.conf->ft_listen; 57 46 58 *errptr = errmsg; 47 if( errptr ) 48 *errptr = errmsg; 59 49 60 s printf( port, "0" );50 strcpy( port, "0" ); 61 51 62 52 /* Format is <IP-A>[:<Port-A>];<IP-B>[:<Port-B>] where … … 64 54 * and B is for connections with IM peers. 65 55 */ 66 if( ftlisten ) { 56 if( ftlisten ) 57 { 67 58 char *scolon = strchr( ftlisten, ';' ); 68 59 char *colon; 69 60 70 if( scolon ) { 71 if( for_bitlbee_client ) { 61 if( scolon ) 62 { 63 if( for_bitlbee_client ) 64 { 72 65 *scolon = '\0'; 73 s printf( host, ftlisten);66 strncpy( host, ftlisten, HOST_NAME_MAX ); 74 67 *scolon = ';'; 75 } else {76 sprintf( host, scolon + 1 );77 68 } 78 } else { 79 sprintf( host, ftlisten ); 69 else 70 { 71 strncpy( host, scolon + 1, HOST_NAME_MAX ); 72 } 73 } 74 else 75 { 76 strncpy( host, ftlisten, HOST_NAME_MAX ); 80 77 } 81 78 82 if( ( colon = strchr( host, ':' ) ) ) { 79 if( ( colon = strchr( host, ':' ) ) ) 80 { 83 81 *colon = '\0'; 84 s printf( port, colon + 1);82 strncpy( port, colon + 1, 5 ); 85 83 } 86 } else { 84 } 85 else 86 { 87 87 ASSERTSOCKOP( gethostname( host, HOST_NAME_MAX + 1 ), "gethostname()" ); 88 88 } … … 92 92 hints.ai_flags = AI_NUMERICSERV; 93 93 94 if ( ( gret = getaddrinfo( host, port, &hints, &rp ) ) != 0 ) { 94 if ( ( gret = getaddrinfo( host, port, &hints, &rp ) ) != 0 ) 95 { 95 96 sprintf( errmsg, "getaddrinfo() failed: %s", gai_strerror( gret ) ); 96 97 return -1; … … 104 105 105 106 ASSERTSOCKOP( fd = socket( saddr->ss_family, SOCK_STREAM, 0 ), "Opening socket" ); 106 107 107 ASSERTSOCKOP( bind( fd, ( struct sockaddr *)saddr, saddrlen ), "Binding socket" ); 108 109 108 ASSERTSOCKOP( listen( fd, 1 ), "Making socket listen" ); 110 109 111 110 if ( !inet_ntop( saddr->ss_family, saddr->ss_family == AF_INET ? 112 ( void * )&( ( struct sockaddr_in * ) saddr )->sin_addr.s_addr : ( void * )&( ( struct sockaddr_in6 * ) saddr )->sin6_addr.s6_addr 113 , host, INET6_ADDRSTRLEN ) ) { 114 sprintf( errmsg, "inet_ntop failed on listening socket" ); 111 ( void * )&( ( struct sockaddr_in * ) saddr )->sin_addr.s_addr : 112 ( void * )&( ( struct sockaddr_in6 * ) saddr )->sin6_addr.s6_addr, 113 host, HOST_NAME_MAX ) ) 114 { 115 strcpy( errmsg, "inet_ntop failed on listening socket" ); 115 116 return -1; 116 117 } … … 119 120 120 121 if( saddr->ss_family == AF_INET ) 121 sprintf( port, "%d", ntohs( ( (struct sockaddr_in *) saddr )->sin_port ) );122 g_snprintf( port, 6, "%d", ntohs( ( (struct sockaddr_in *) saddr )->sin_port ) ); 122 123 else 123 sprintf( port, "%d", ntohs( ( (struct sockaddr_in6 *) saddr )->sin6_port ) );124 g_snprintf( port, 6, "%d", ntohs( ( (struct sockaddr_in6 *) saddr )->sin6_port ) ); 124 125 125 126 if( saddr_ptr ) 126 127 memcpy( saddr_ptr, saddr, saddrlen ); 127 128 128 strcpy( hostp, host ); 129 129 /* I hate static-length strings.. */ 130 host[HOST_NAME_MAX] = '\0'; 131 port[5] = '\0'; 132 130 133 return fd; 131 134 } -
lib/ftutil.h
re8c8d00 r60e4df3 26 26 #endif 27 27 28 /* Some ifdefs for ulibc and apparently also BSD (Thanks to Whoopie) */ 29 #ifndef HOST_NAME_MAX 30 #include <sys/param.h> 31 #ifdef MAXHOSTNAMELEN 32 #define HOST_NAME_MAX MAXHOSTNAMELEN 33 #else 34 #define HOST_NAME_MAX 255 35 #endif 36 #endif 37 38 /* This function should be used with care. host should be AT LEAST a 39 char[HOST_NAME_MAX+1] and port AT LEAST a char[6]. */ 28 40 int ft_listen( struct sockaddr_storage *saddr_ptr, char *host, char *port, int for_bitlbee_client, char **errptr ); -
protocols/jabber/s5bytestream.c
re8c8d00 r60e4df3 890 890 char *proxy, *next, *errmsg = NULL; 891 891 char port[6]; 892 char host[ INET6_ADDRSTRLEN];892 char host[HOST_NAME_MAX+1]; 893 893 jabber_streamhost_t *sh, *sh2; 894 894 GSList *streamhosts = jd->streamhosts; -
protocols/msn/invitation.c
re8c8d00 r60e4df3 219 219 char buf[1024]; 220 220 unsigned int acookie = time ( NULL ); 221 char host[ INET6_ADDRSTRLEN];221 char host[HOST_NAME_MAX+1]; 222 222 char port[6]; 223 223 char *errmsg;
Note: See TracChangeset
for help on using the changeset viewer.