Browse Source

Log server address that we connected to.

This is useful when DNS name is used for server address. Without logging
the actual IP address there was no way to know which server refused the
connection or returned error.
Georgi Chorbadzhiyski 10 years ago
parent
commit
95f023d216
1 changed files with 5 additions and 4 deletions
  1. 5
    4
      camd.c

+ 5
- 4
camd.c View File

@@ -55,13 +55,13 @@ int connect_client(int socktype, const char *hostname, const char *service) {
55 55
 
56 56
 	int sockfd = -1;
57 57
 	struct addrinfo *ressave = res;
58
+	char str_addr[INET6_ADDRSTRLEN] = { 0 };
58 59
 	while (res) {
59 60
 		sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
60 61
 		if (sockfd > -1) {
62
+			my_inet_ntop(res->ai_family, res->ai_addr, str_addr, sizeof(str_addr));
61 63
 			if (do_connect(sockfd, res->ai_addr, res->ai_addrlen, 1000) < 0) {
62
-				char str_addr[INET6_ADDRSTRLEN];
63
-				my_inet_ntop(res->ai_family, res->ai_addr, str_addr, sizeof(str_addr));
64
-				ts_LOGf("CAM | Could not connect to server %s:%s (%s) | %s\n",
64
+				ts_LOGf("CAM | Error connecting to server %s port %s (addr=%s) | %s\n",
65 65
 					hostname, service, str_addr, strerror(errno));
66 66
 				close(sockfd);
67 67
 				sockfd = -1;
@@ -82,7 +82,8 @@ int connect_client(int socktype, const char *hostname, const char *service) {
82 82
 		setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(int));
83 83
 	}
84 84
 
85
-	ts_LOGf("CAM | Connected to fd:%d\n", sockfd);
85
+	ts_LOGf("CAM | Connected to server %s port %s (addr=%s fd=%d).\n",
86
+		hostname, service, str_addr, sockfd);
86 87
 
87 88
 	return sockfd;
88 89
 }

Loading…
Cancel
Save