From 1ed7dbec53aec2cd9f7fb4afbb48abf199b2e01b Mon Sep 17 00:00:00 2001
From: Koichiro IWAO
Date: Tue, 23 Feb 2016 15:14:22 +0900
Subject: [PATCH 1/3] common: add log for g_tcp_connect
in case getaddrinfo(3) might fail.
In FreeBSD, AI_V4MAPPED support for getaddrinfo(3) was very recently
implemented[1]. Most of FreeBSD systems in the world do not have
this implementation yet. This will be a problem when AI_V4MAPPED
isn't supported and xrdp is built with IPv6 option. In such a case,
g_tcp_connect always fails.
Of course getaddrinfo(3) might fail in other cases. The log helps
us to know what's happening.
[1] https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=198092
---
common/os_calls.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/common/os_calls.c b/common/os_calls.c
index a4c98a75..f02b8c65 100644
--- a/common/os_calls.c
+++ b/common/os_calls.c
@@ -668,6 +668,7 @@ int APP_CC
g_tcp_connect(int sck, const char *address, const char *port)
{
int res = 0;
+ char errorMsg[256];
struct addrinfo p;
struct addrinfo *h = (struct addrinfo *)NULL;
struct addrinfo *rp = (struct addrinfo *)NULL;
@@ -693,6 +694,12 @@ g_tcp_connect(int sck, const char *address, const char *port)
{
res = getaddrinfo(address, port, &p, &h);
}
+ if (res != 0)
+ {
+ snprintf(errorMsg, 255, "g_tcp_connect: getaddrinfo() failed: %s",
+ gai_strerror(res));
+ log_message(LOG_LEVEL_ERROR, errorMsg);
+ }
if (res > -1)
{
if (h != NULL)
From d01854a341dd054de0ff528fd0ec49d3061f08db Mon Sep 17 00:00:00 2001
From: Koichiro IWAO
Date: Tue, 23 Feb 2016 17:16:57 +0900
Subject: [PATCH 2/3] common: no logic change, fix alignment, whitespaces
---
common/os_calls.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/common/os_calls.c b/common/os_calls.c
index f02b8c65..4e79cdeb 100644
--- a/common/os_calls.c
+++ b/common/os_calls.c
@@ -986,8 +986,8 @@ g_tcp_accept(int sck)
ret = accept(sck, (struct sockaddr *)&s, &i);
if(ret>0)
{
- snprintf(ipAddr,255,"A connection received from: %s port %d"
- ,inet_ntoa(s.sin_addr),ntohs(s.sin_port));
+ snprintf(ipAddr, 255, "A connection received from: %s port %d",
+ inet_ntoa(s.sin_addr), ntohs(s.sin_port));
log_message(LOG_LEVEL_INFO,ipAddr);
}
return ret ;
From 9460bdb643dc7971daff3fae81d84a5f9f3ab48c Mon Sep 17 00:00:00 2001
From: Koichiro IWAO
Date: Tue, 23 Feb 2016 17:20:20 +0900
Subject: [PATCH 3/3] common: no logic change, indent 2 -> 4
---
common/os_calls.c | 72 +++++++++++++++++++++++------------------------
1 file changed, 36 insertions(+), 36 deletions(-)
diff --git a/common/os_calls.c b/common/os_calls.c
index 4e79cdeb..991ebb44 100644
--- a/common/os_calls.c
+++ b/common/os_calls.c
@@ -722,31 +722,31 @@ g_tcp_connect(int sck, const char *address, const char *port)
int APP_CC
g_tcp_connect(int sck, const char* address, const char* port)
{
- struct sockaddr_in s;
- struct hostent* h;
+ struct sockaddr_in s;
+ struct hostent* h;
- g_memset(&s, 0, sizeof(struct sockaddr_in));
- s.sin_family = AF_INET;
- s.sin_port = htons((tui16)atoi(port));
- s.sin_addr.s_addr = inet_addr(address);
- if (s.sin_addr.s_addr == INADDR_NONE)
- {
- h = gethostbyname(address);
- if (h != 0)
+ g_memset(&s, 0, sizeof(struct sockaddr_in));
+ s.sin_family = AF_INET;
+ s.sin_port = htons((tui16)atoi(port));
+ s.sin_addr.s_addr = inet_addr(address);
+ if (s.sin_addr.s_addr == INADDR_NONE)
{
- if (h->h_name != 0)
- {
- if (h->h_addr_list != 0)
+ h = gethostbyname(address);
+ if (h != 0)
{
- if ((*(h->h_addr_list)) != 0)
- {
- s.sin_addr.s_addr = *((int*)(*(h->h_addr_list)));
- }
+ if (h->h_name != 0)
+ {
+ if (h->h_addr_list != 0)
+ {
+ if ((*(h->h_addr_list)) != 0)
+ {
+ s.sin_addr.s_addr = *((int*)(*(h->h_addr_list)));
+ }
+ }
+ }
}
- }
}
- }
- return connect(sck, (struct sockaddr*)&s, sizeof(struct sockaddr_in));
+ return connect(sck, (struct sockaddr*)&s, sizeof(struct sockaddr_in));
}
#endif
@@ -903,13 +903,13 @@ g_tcp_bind(int sck, const char *port)
int APP_CC
g_tcp_bind(int sck, const char* port)
{
- struct sockaddr_in s;
+ struct sockaddr_in s;
- memset(&s, 0, sizeof(struct sockaddr_in));
- s.sin_family = AF_INET;
- s.sin_port = htons((tui16)atoi(port));
- s.sin_addr.s_addr = INADDR_ANY;
- return bind(sck, (struct sockaddr*)&s, sizeof(struct sockaddr_in));
+ memset(&s, 0, sizeof(struct sockaddr_in));
+ s.sin_family = AF_INET;
+ s.sin_port = htons((tui16)atoi(port));
+ s.sin_addr.s_addr = INADDR_ANY;
+ return bind(sck, (struct sockaddr*)&s, sizeof(struct sockaddr_in));
}
#endif
@@ -946,17 +946,17 @@ g_tcp_bind_address(int sck, const char *port, const char *address)
int APP_CC
g_tcp_bind_address(int sck, const char* port, const char* address)
{
- struct sockaddr_in s;
+ struct sockaddr_in s;
- memset(&s, 0, sizeof(struct sockaddr_in));
- s.sin_family = AF_INET;
- s.sin_port = htons((tui16)atoi(port));
- s.sin_addr.s_addr = INADDR_ANY;
- if (inet_aton(address, &s.sin_addr) < 0)
- {
- return -1; /* bad address */
- }
- return bind(sck, (struct sockaddr*)&s, sizeof(struct sockaddr_in));
+ memset(&s, 0, sizeof(struct sockaddr_in));
+ s.sin_family = AF_INET;
+ s.sin_port = htons((tui16)atoi(port));
+ s.sin_addr.s_addr = INADDR_ANY;
+ if (inet_aton(address, &s.sin_addr) < 0)
+ {
+ return -1; /* bad address */
+ }
+ return bind(sck, (struct sockaddr*)&s, sizeof(struct sockaddr_in));
}
#endif