File tgif-4.2.5-getaddrinfo.patch of Package tgif
--- remote.c.original 2014-04-06 09:14:55.875934012 +0200
+++ remote.c 2014-04-06 09:14:05.135246609 +0200
@@ -207,22 +207,43 @@
char *psz_buf;
int buf_sz;
{
+ /* prepare for getaddrinfo ()*/
+ struct addrinfo hints, *res, *p;
+ char *ipstr=NULL;
+ int do_not_continue=0;
+
char user_name[MAXSTRING+1];
int total=0;
+ memset (&hints, 0, sizeof(hints));
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+
sprintf(user_name, "%s@", TOOL_NAME);
total = strlen(user_name);
if (gethostname(&user_name[total], sizeof(user_name)-1-total) < 0) {
sprintf(&user_name[total], "UNKNOWN");
} else {
- struct hostent *p_hostent=gethostbyname(&user_name[total]);
+ if (!(getaddrinfo(&user_name[0], NULL, &hints, &res))){
+ for (p = res; p != NULL; p = p->ai_next){
+ /* only do IP V4 for now ... subject to change in the future ...*/
+ if (p->ai_family == AF_INET6){
+ do_not_continue=1;
+ }
+ else {
+ struct sockaddr_in *ipv4 = (struct sockaddr_in *)p->ai_addr;
+ ipstr = (char *) &(ipv4->sin_addr);
+ }
+ }
+ freeaddrinfo(res);
+ }
- if (p_hostent != NULL && p_hostent->h_name != NULL &&
- *p_hostent->h_name != '\0') {
- if (strchr(p_hostent->h_name, '.') == NULL &&
+ if (do_not_continue == 0 && ipstr != NULL &&
+ *ipstr != '\0') {
+ if (strchr(ipstr, '.') == NULL &&
strchr(&user_name[total], '.') != NULL) {
} else {
- strcpy(&user_name[total], p_hostent->h_name);
+ strcpy(&user_name[total], ipstr);
}
}
}
--- tangram2.c.original 2011-06-28 04:04:59.000000000 +0200
+++ tangram2.c 2014-04-06 18:49:08.561295255 +0200
@@ -398,7 +398,6 @@
{
char host[ 10 ];
char *protocol = "udp";
- struct hostent *phe;
struct servent *pse;
struct protoent *ppe;
struct sockaddr_in sin;
@@ -410,6 +409,15 @@
int one = 1;
char *service = "6743";
+ /* prepare for getaddrinfo ()*/
+ struct addrinfo hints, *res, *p;
+ char *ipstr=NULL;
+ int do_not_continue=0;
+
+ memset (&hints, 0, sizeof(hints));
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+
strcpy( host, "localhost" );
memset( (char *)&sin, 0, sizeof( sin ) );
sin.sin_family = AF_INET;
@@ -422,10 +430,24 @@
return;
}
- if( (phe = gethostbyname( host )) != NULL )
- memcpy( (char *)&sin.sin_addr, phe->h_addr, phe->h_length );
- else
- {
+ do_not_continue=getaddrinfo(host, NULL, &hints, &res);
+
+ if (!do_not_continue){
+ for (p = res; p != NULL; p = p->ai_next){
+ /* only do IP V4 for now ... subject to change in the future ...*/
+ if (p->ai_family == AF_INET6){
+ do_not_continue=1;
+ }
+ else {
+ struct sockaddr_in *ipv4 = (struct sockaddr_in *)p->ai_addr;
+ ipstr = (char *) &(ipv4->sin_addr);
+ }
+ }
+ freeaddrinfo(res);
+ if (!do_not_continue)
+ memcpy( (char *)&sin.sin_addr, ipstr, (int) strlen(ipstr));
+ }
+ if (do_not_continue){
sin.sin_addr.s_addr = inet_addr( host );
#ifdef linux
if( sin.sin_addr.s_addr == INADDR_NONE )
--- tcp.c.original 2011-06-28 04:04:59.000000000 +0200
+++ tcp.c 2014-04-06 09:02:33.392878430 +0200
@@ -76,11 +76,17 @@
int us_port, *pn_socket;
{
static int not_initialized=TRUE;
+ struct addrinfo hints, *res, *p;
+ char *ipstr=NULL;
+
struct sockaddr_in soc_address;
struct sockaddr_in *sin=(&soc_address);
- struct hostent *p_hostent=NULL;
int status=TG_REMOTE_STATUS_OK;
+ memset (&hints, 0, sizeof(hints));
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+
if (not_initialized) {
not_initialized = FALSE;
signal(SIGPIPE, BrokenPipe);
@@ -88,11 +94,22 @@
if (*psz_host >= '0' && *psz_host <= '9') {
sin->sin_addr.s_addr = inet_addr(psz_host);
} else {
- p_hostent = gethostbyname(psz_host);
- if (p_hostent == NULL) {
- return TG_REMOTE_STATUS_HOST;
- }
- memcpy(&sin->sin_addr, p_hostent->h_addr, p_hostent->h_length);
+ if (getaddrinfo(psz_host, NULL, &hints, &res)){
+ return TG_REMOTE_STATUS_HOST;
+ }
+ for (p = res; p != NULL; p = p->ai_next){
+ /* only do IP V4 for now ... subject to change in the future ...*/
+ if (p->ai_family == AF_INET6){
+ return 1;
+ }
+ else {
+ struct sockaddr_in *ipv4 = (struct sockaddr_in *)p->ai_addr;
+ ipstr = (char *) &(ipv4->sin_addr);
+ }
+ }
+ freeaddrinfo(res);
+
+ memcpy(&sin->sin_addr, ipstr, (int) strlen(ipstr));
}
sin->sin_family = AF_INET;
sin->sin_port = htons((unsigned short)us_port);