diff options
author | Costa Tsaousis (ktsaou) <costa@tsaousis.gr> | 2016-12-24 17:47:05 +0200 |
---|---|---|
committer | Costa Tsaousis (ktsaou) <costa@tsaousis.gr> | 2016-12-24 17:47:05 +0200 |
commit | 251b76b7b761278d57ae1d15052576ce073e7630 (patch) | |
tree | d3b1066ca10e86e826875de898a4d02b261cc813 | |
parent | 57138feab40021a8e9578b42a8bf871f9f13ab17 (diff) |
properly enable TCP and use TCP by default if protocol is not given
-rw-r--r-- | src/socket.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/socket.c b/src/socket.c index 6d60be772e..681e6c71f2 100644 --- a/src/socket.c +++ b/src/socket.c @@ -22,16 +22,18 @@ int connect_to(const char *definition, int default_port, struct timeval *timeout snprintfz(default_service, 10, "%d", default_port); char *host = buffer, *service = default_service, *interface = ""; - int protocol = 0; + int protocol = IPPROTO_TCP, socktype = SOCK_STREAM; uint32_t scope_id = 0; if(strncmp(host, "tcp:", 4) == 0) { host += 4; protocol = IPPROTO_TCP; + socktype = SOCK_STREAM; } else if(strncmp(host, "udp:", 4) == 0) { host += 4; protocol = IPPROTO_UDP; + socktype = SOCK_DGRAM; } char *e = host; @@ -76,10 +78,10 @@ int connect_to(const char *definition, int default_port, struct timeval *timeout if(!*service) service = default_service; - memset(&hints, 0, sizeof(struct addrinfo)); + memset(&hints, 0, sizeof(hints)); hints.ai_family = PF_UNSPEC; /* Allow IPv4 or IPv6 */ - hints.ai_socktype = SOCK_DGRAM; /* Datagram socket */ - hints.ai_protocol = protocol; /* The required protocol */ + hints.ai_socktype = socktype; + hints.ai_protocol = protocol; int ai_err = getaddrinfo(host, service, &hints, &ai_head); if (ai_err != 0) { |