Changeset a02f34f for protocols/msn
- Timestamp:
- 2008-08-11T23:07:12Z (16 years ago)
- Branches:
- master
- Children:
- 5d550c5
- Parents:
- 66be784
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/msn/invitation.c
r66be784 ra02f34f 28 28 #include "invitation.h" 29 29 #include "msn.h" 30 31 /* Some ifdefs for ulibc and apparently also BSD (Thanks to Whoopie) */ 32 #ifndef HOST_NAME_MAX 33 #include <sys/param.h> 34 #ifdef MAXHOSTNAMELEN 35 #define HOST_NAME_MAX MAXHOSTNAMELEN 36 #else 37 #define HOST_NAME_MAX 255 38 #endif 39 #endif 40 41 #ifndef AI_NUMERICSERV 42 #define AI_NUMERICSERV 0x0400 /* Don't use name resolution. */ 43 #endif 30 #include "lib/ftutil.h" 44 31 45 32 #ifdef debug … … 78 65 if( (op) == -1 ) \ 79 66 return msn_ftp_abort( file , msg ": %s", strerror( errno ) ); 80 81 /*82 * Creates a listening socket and returns its address in host, port.83 */84 gboolean msn_ftp_listen( msn_filetransfer_t *msn_file, char *host, char *port )85 {86 file_transfer_t *file = msn_file->dcc;87 int fd,gret;88 char hostname[ HOST_NAME_MAX + 1 ];89 struct addrinfo hints, *rp;90 struct sockaddr_storage saddrst, *saddr = &saddrst;91 socklen_t ssize = sizeof( struct sockaddr_storage );92 93 /* won't be long till someone asks for this to be configurable :) */94 95 ASSERTSOCKOP( gethostname( hostname, sizeof( hostname ) ), "gethostname()" );96 97 memset( &hints, 0, sizeof( struct addrinfo ) );98 hints.ai_socktype = SOCK_STREAM;99 hints.ai_flags = AI_NUMERICSERV;100 101 if ( ( gret = getaddrinfo( hostname, "0", &hints, &rp ) ) != 0 )102 return msn_ftp_abort( file, "getaddrinfo() failed: %s", gai_strerror( gret ) );103 104 memcpy( saddr, rp->ai_addr, rp->ai_addrlen );105 106 ASSERTSOCKOP( fd = msn_file->fd = socket( saddr->ss_family, SOCK_STREAM, 0 ), "Opening socket" );107 108 ASSERTSOCKOP( bind( fd, ( struct sockaddr *)saddr, rp->ai_addrlen ), "Binding socket" );109 110 freeaddrinfo( rp );111 112 ASSERTSOCKOP( listen( fd, 1 ), "Making socket listen" );113 114 if ( !inet_ntop( saddr->ss_family, saddr->ss_family == AF_INET ?115 ( void * )&( ( struct sockaddr_in * ) saddr )->sin_addr.s_addr : ( void * )&( ( struct sockaddr_in6 * ) saddr )->sin6_addr.s6_addr116 , host, INET6_ADDRSTRLEN ) )117 return msn_ftp_abort( file, "inet_ntop failed on listening socket" );118 119 ASSERTSOCKOP( getsockname( fd, ( struct sockaddr *)saddr, &ssize ), "Getting socket name" );120 121 if( saddr->ss_family == AF_INET )122 sprintf( port, "%d", ntohs( ( ( struct sockaddr_in *) saddr )->sin_port ) );123 else124 sprintf( port, "%d", ntohs( ( ( struct sockaddr_in6 *) saddr )->sin6_port ) );125 126 return TRUE;127 }128 67 129 68 void msn_ftp_invitation_cmd( struct im_connection *ic, char *who, int cookie, char *icmd, … … 282 221 char host[INET6_ADDRSTRLEN]; 283 222 char port[6]; 223 char *errmsg; 284 224 285 225 msn_file->auth_cookie = acookie; 286 226 287 if( !msn_ftp_listen( msn_file, host, port ) ) 288 return; 227 if( ( msn_file->fd = ft_listen( NULL, host, port, FALSE, &errmsg ) ) == -1 ) { 228 msn_ftp_abort( file, "Failed to listen locally, check your ft_listen setting in bitlbee.conf: %s", errmsg ); 229 return; 230 } 289 231 290 232 msn_file->r_event_id = b_input_add( msn_file->fd, GAIM_INPUT_READ, msn_ftps_connected, file );
Note: See TracChangeset
for help on using the changeset viewer.