From b1b809031f5a11223d97ee02d21fb6bb3693a367 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Mon, 11 Mar 2002 00:53:49 +0000 Subject: Remove this: it couldn't be generically used, because different subclasses * camel-tcp-stream.c (camel_tcp_stream_get_socket): Remove this: it couldn't be generically used, because different subclasses returned entirely different types of data. (camel_tcp_stream_get_local_address, camel_tcp_stream_get_remote_address): Add these to replace what get_socket was being used for. (camel_tcp_address_new, camel_tcp_address_free): Utility functions for get_{local,remote}_address. * providers/smtp/camel-smtp-transport.c: Change localaddr to a CamelTcpAddress *. (connect_to_server): Call camel_tcp_stream_get_local_address to get the local IP address. (smtp_disconnect): free localaddr. (smtp_helo): Update for localaddr change. * camel-tcp-stream-raw.c (stream_get_socket): Remove (stream_get_local_address, stream_get_remote_address): Implement. * camel-tcp-stream-ssl.c (stream_get_socket): Remove (stream_get_local_address, stream_get_remote_address): Implement. * camel-tcp-stream-openssl.c (stream_get_socket): Remove (stream_get_local_address, stream_get_remote_address): Implement. svn path=/trunk/; revision=16092 --- camel/camel-tcp-stream-raw.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'camel/camel-tcp-stream-raw.c') diff --git a/camel/camel-tcp-stream-raw.c b/camel/camel-tcp-stream-raw.c index e7003ac53d..cd3a74d6f2 100644 --- a/camel/camel-tcp-stream-raw.c +++ b/camel/camel-tcp-stream-raw.c @@ -48,7 +48,8 @@ static int stream_close (CamelStream *stream); static int stream_connect (CamelTcpStream *stream, struct hostent *host, int port); static int stream_getsockopt (CamelTcpStream *stream, CamelSockOptData *data); static int stream_setsockopt (CamelTcpStream *stream, const CamelSockOptData *data); -static gpointer stream_get_socket (CamelTcpStream *stream); +static CamelTcpAddress *stream_get_local_address (CamelTcpStream *stream); +static CamelTcpAddress *stream_get_remote_address (CamelTcpStream *stream); static void camel_tcp_stream_raw_class_init (CamelTcpStreamRawClass *camel_tcp_stream_raw_class) @@ -68,8 +69,9 @@ camel_tcp_stream_raw_class_init (CamelTcpStreamRawClass *camel_tcp_stream_raw_cl camel_tcp_stream_class->connect = stream_connect; camel_tcp_stream_class->getsockopt = stream_getsockopt; - camel_tcp_stream_class->setsockopt = stream_setsockopt; - camel_tcp_stream_class->get_socket = stream_get_socket; + camel_tcp_stream_class->setsockopt = stream_setsockopt; + camel_tcp_stream_class->get_local_address = stream_get_local_address; + camel_tcp_stream_class->get_remote_address = stream_get_remote_address; } static void @@ -565,8 +567,30 @@ stream_setsockopt (CamelTcpStream *stream, const CamelSockOptData *data) sizeof (data->value)); } -static gpointer -stream_get_socket (CamelTcpStream *stream) +static CamelTcpAddress * +stream_get_local_address (CamelTcpStream *stream) { - return GINT_TO_POINTER (CAMEL_TCP_STREAM_RAW (stream)->sockfd); + struct sockaddr_in sin; + socklen_t len; + + if (getsockname (CAMEL_TCP_STREAM_RAW (stream)->sockfd, + (struct sockaddr *)&sin, &len) == -1) + return NULL; + + return camel_tcp_address_new (CAMEL_TCP_ADDRESS_IPV4, sin.sin_port, + 4, &sin.sin_addr); +} + +static CamelTcpAddress * +stream_get_remote_address (CamelTcpStream *stream) +{ + struct sockaddr_in sin; + socklen_t len; + + if (getpeername (CAMEL_TCP_STREAM_RAW (stream)->sockfd, + (struct sockaddr *)&sin, &len) == -1) + return NULL; + + return camel_tcp_address_new (CAMEL_TCP_ADDRESS_IPV4, sin.sin_port, + 4, &sin.sin_addr); } -- cgit