aboutsummaryrefslogtreecommitdiffstats
path: root/camel/camel-tcp-stream-openssl.c
diff options
context:
space:
mode:
Diffstat (limited to 'camel/camel-tcp-stream-openssl.c')
-rw-r--r--camel/camel-tcp-stream-openssl.c34
1 files changed, 29 insertions, 5 deletions
diff --git a/camel/camel-tcp-stream-openssl.c b/camel/camel-tcp-stream-openssl.c
index 2c3709fbd8..7996b37ae5 100644
--- a/camel/camel-tcp-stream-openssl.c
+++ b/camel/camel-tcp-stream-openssl.c
@@ -62,7 +62,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 SSL *open_ssl_connection (CamelService *service, int sockfd, CamelTcpStreamOpenSSL *openssl);
@@ -94,7 +95,8 @@ camel_tcp_stream_openssl_class_init (CamelTcpStreamOpenSSLClass *camel_tcp_strea
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->get_local_address = stream_get_local_address;
+ camel_tcp_stream_class->get_remote_address = stream_get_remote_address;
/* init OpenSSL stuff */
SSLeay_add_ssl_algorithms ();
@@ -788,10 +790,32 @@ 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_OPENSSL (stream)->priv->sockfd);
+ struct sockaddr_in sin;
+ socklen_t len;
+
+ if (getsockname (CAMEL_TCP_STREAM_OPENSSL (stream)->priv->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_OPENSSL (stream)->priv->sockfd,
+ (struct sockaddr *)&sin, &len) == -1)
+ return NULL;
+
+ return camel_tcp_address_new (CAMEL_TCP_ADDRESS_IPV4, sin.sin_port,
+ 4, &sin.sin_addr);
}
#endif /* HAVE_OPENSSL */