@cryptotaxi247 / netdata-1 / commits / 251b76b7b

properly enable TCP and use TCP by default if protocol is not given

Costa Tsaousis (ktsaou) committed Dec 24, 2016 at 17:47 UTC 251b76b7b761278d57ae1d15052576ce073e7630
1 file changed +6 -4
src/socket.c
+6 -4
@@ -22,16 +22,18 @@ int connect_to(const char *definition, int default_port, struct timeval *timeout
22 snprintfz(default_service, 10, "%d", default_port);
23
24 char *host = buffer, *service = default_service, *interface = "";
25 - int protocol = 0;
25 + int protocol = IPPROTO_TCP, socktype = SOCK_STREAM;
26 uint32_t scope_id = 0;
27
28 if(strncmp(host, "tcp:", 4) == 0) {
29 host += 4;
30 protocol = IPPROTO_TCP;
31 + socktype = SOCK_STREAM;
32 }
33 else if(strncmp(host, "udp:", 4) == 0) {
34 host += 4;
35 protocol = IPPROTO_UDP;
36 + socktype = SOCK_DGRAM;
37 }
38
39 char *e = host;
@@ -76,10 +78,10 @@ int connect_to(const char *definition, int default_port, struct timeval *timeout
78 if(!*service)
79 service = default_service;
80
79 - memset(&hints, 0, sizeof(struct addrinfo));
81 + memset(&hints, 0, sizeof(hints));
82 hints.ai_family = PF_UNSPEC; /* Allow IPv4 or IPv6 */
81 - hints.ai_socktype = SOCK_DGRAM; /* Datagram socket */
82 - hints.ai_protocol = protocol; /* The required protocol */
83 + hints.ai_socktype = socktype;
84 + hints.ai_protocol = protocol;
85
86 int ai_err = getaddrinfo(host, service, &hints, &ai_head);
87 if (ai_err != 0) {