[Telepathy-commits] [telepathy-idle/master] Only try to connect to the IRC server over TCP

Jonathon Jongsma jonathon.jongsma at collabora.co.uk
Fri Feb 13 15:35:11 PST 2009


Previously we were not specifying any socket type in our getaddrinfo call, so
our address results included both TCP and UDP candidates.  When connecting to
the TCP one failed, it would try the UDP one, which would lead to some
unexpected behavior (for instance, connect() on a UDP socket with O_NONBLOCK set
will return 0 rather than -1/EINPROGRESS, which violates some assumptions in the
code).  If the UDP socket did manage to get connected, it would violate other
assumptions (for instance, setting the TCP_NODELAY option doesn't make sense on
a non-TCP socket and triggers a warning).
So, it doesn't really make sense to connect to a IRC server with UDP anyway, so
this patch restricts telepathy-idle to use TCP sockets only
---
 src/idle-dns-resolver.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/src/idle-dns-resolver.c b/src/idle-dns-resolver.c
index ef9c7aa..20be670 100644
--- a/src/idle-dns-resolver.c
+++ b/src/idle-dns-resolver.c
@@ -21,6 +21,7 @@
 
 #include <netdb.h>
 #include <sys/socket.h>
+#include <string.h>
 
 #define IDLE_DEBUG_FLAG IDLE_DEBUG_DNS
 #include "idle-debug.h"
@@ -106,6 +107,7 @@ static gboolean _resolve_idle_func(struct _idle_helper *helper) {
 	IdleDNSQueryData *data = g_hash_table_lookup(helper->res->queries, GUINT_TO_POINTER(helper->serial));
 	struct addrinfo *info = NULL;
 	struct addrinfo *cur;
+	struct addrinfo hints;
 	int rc;
 	IdleDNSResultReal *results = NULL, *tail = NULL;
 	IdleDNSResultCallback cb;
@@ -115,7 +117,9 @@ static gboolean _resolve_idle_func(struct _idle_helper *helper) {
 	cb = data->cb;
 	user_data = data->user_data;
 
-	rc = getaddrinfo(data->name, service, NULL, &info);
+	memset(&hints, 0, sizeof(hints));
+	hints.ai_socktype = SOCK_STREAM;
+	rc = getaddrinfo(data->name, service, &hints, &info);
 
 	if (rc) {
 		IDLE_DEBUG("getaddrinfo(): %s", gai_strerror(rc));
-- 
1.5.6.5




More information about the telepathy-commits mailing list