]> arthur.barton.de Git - netdata.git/commitdiff
properly enable TCP and use TCP by default if protocol is not given
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sat, 24 Dec 2016 15:47:05 +0000 (17:47 +0200)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sat, 24 Dec 2016 15:47:05 +0000 (17:47 +0200)
src/socket.c

index 6d60be772e506e1f59bb8e729a6769f6cb78c7e8..681e6c71f245e7f3a9f142e09e110069d2c89f2b 100644 (file)
@@ -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) {