gnokii-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SCM] libgnokii and core programs branch, master, updated. rel_0_6_29-32


From: Pawel Kot
Subject: [SCM] libgnokii and core programs branch, master, updated. rel_0_6_29-326-gc52a43c
Date: Sat, 03 Dec 2011 18:24:19 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "libgnokii and core programs".

The branch, master has been updated
       via  c52a43c931ff63c2664b91aa4c7e7c42c12960ba (commit)
      from  7bc2b41c8ee2619f7123656474bccdcb094aaa52 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/gnokii.git/commit/?id=c52a43c931ff63c2664b91aa4c7e7c42c12960ba


commit c52a43c931ff63c2664b91aa4c7e7c42c12960ba
Author: Pawel Kot <address@hidden>
Date:   Sat Dec 3 19:21:21 2011 +0100

    Replace gethostbyname with getaddrinfo.
    
    gethostbyname is deprecated as it does not support ipv6. Provide an
    alternative implementation of device_open() in tcp driver using getaddrinfo.

diff --git a/ChangeLog b/ChangeLog
index 9cad018..1d71836 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,9 @@
 =========================
  * translation updates
     o updated Italian translation                   (Daniele Forsi)
+ * libgnokii updates
+    o replace gethostbyname (deprecated) with getaddrinfo in tcp
+      driver                                            (Paweł Kot)
 
 0.6.31
 ======
diff --git a/common/devices/tcp.c b/common/devices/tcp.c
index 86cf728..362d6bf 100644
--- a/common/devices/tcp.c
+++ b/common/devices/tcp.c
@@ -7,7 +7,8 @@
   This file is part of gnokii.
 
   Copyright (C) 2002      Jan Kratochvil, Pavel Machek, Manfred Jonsson, Ladis 
Michl
-  Copyright (C) 2002-2004 BORBELY Zoltan, Pawel Kot
+  Copyright (C) 2002-2004 BORBELY Zoltan
+  Copyright (C) 2002-2011 Pawel Kot
 
 */
 
@@ -54,10 +55,15 @@
 static int tcp_open(const char *file)
 {
        int fd;
+#ifdef HAVE_GETADDRINFO
+       struct addrinfo hints, *result, *rp;
+#else
        struct sockaddr_in addr;
-       char *filedup,*portstr,*end;
-       unsigned long portul;
        struct hostent *hostent;
+#endif
+       int gai_errorcode;
+       char *filedup, *portstr, *end;
+       unsigned long portul;
 
        fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
        if (fd == -1) {
@@ -65,15 +71,12 @@ static int tcp_open(const char *file)
                return -1;
        }
        if (!(filedup = strdup(file))) {
-       fail_close:
-               close(fd);
-               return -1;
+               perror(_("Gnokii tcp_open: strdup()"));
+               goto fail_close;
        }
        if (!(portstr = strchr(filedup, ':'))) {
                fprintf(stderr, _("Gnokii tcp_open: colon (':') not found in 
connect strings \"%s\"!\n"), filedup);
-       fail_free:
-               free(filedup);
-               goto fail_close;
+               goto fail_free;
        }
        *portstr++ = '\0';
        portul = strtoul(portstr, &end, 0);
@@ -81,6 +84,35 @@ static int tcp_open(const char *file)
                fprintf(stderr, _("Gnokii tcp_open: Port string \"%s\" not 
valid for IPv4 connection!\n"), portstr);
                goto fail_free;
        }
+
+#ifdef HAVE_GETADDRINFO
+       memset(&hints, 0, sizeof(struct addrinfo));
+       hints.ai_family = AF_UNSPEC;     /* Allow IPv4 or IPv6 */
+       hints.ai_socktype = SOCK_STREAM;
+       hints.ai_flags = 0;
+       hints.ai_protocol = IPPROTO_TCP;
+
+       gai_errorcode = getaddrinfo(filedup, portstr, &hints, &result);
+       if (gai_errorcode != 0) {
+               fprintf(stderr, "%s\n", gai_strerror(gai_errorcode));
+               goto fail_free;
+       }
+
+       for (rp = result; rp != NULL; rp = rp->ai_next) {
+               if ((rp->ai_family != PF_INET) &&
+                   (rp->ai_family != PF_INET6))
+                       continue;
+               if (connect(fd, rp->ai_addr, rp->ai_addrlen) != -1)
+                       break;
+       }
+
+       freeaddrinfo(result);
+
+       if (rp == NULL) {
+               fprintf(stderr, _("Gnokii tcp_open: Cannot connect!\n"));
+               goto fail_free;
+       }
+#else
        if (!(hostent = gethostbyname(filedup))) {
                fprintf(stderr, _("Gnokii tcp_open: Unknown host \"%s\"!\n"), 
filedup);
                goto fail_free;
@@ -89,7 +121,6 @@ static int tcp_open(const char *file)
                fprintf(stderr, _("Gnokii tcp_open: Address resolve for host 
\"%s\" not compatible!\n"), filedup);
                goto fail_free;
        }
-       free(filedup);
 
        addr.sin_family = AF_INET;
        addr.sin_port = htons(portul);
@@ -97,10 +128,19 @@ static int tcp_open(const char *file)
 
        if (connect(fd, (struct sockaddr *)&addr, sizeof(addr))) {
                perror(_("Gnokii tcp_open: connect()"));
-               goto fail_close;
+               goto fail_free;
        }
+#endif
 
+       free(filedup);
        return fd;
+
+fail_free:
+       free(filedup);
+
+fail_close:
+       close(fd);
+       return -1;
 }
 
 int tcp_close(int fd, struct gn_statemachine *state)
@@ -140,7 +180,7 @@ int tcp_opendevice(const char *file, int with_async, struct 
gn_statemachine *sta
 
 #if !(__unices__)
        retcode = fcntl(fd, F_SETOWN, getpid());
-       if (retcode == -1){
+       if (retcode == -1) {
                perror(_("Gnokii tcp_opendevice: fcntl(F_SETOWN)"));
                tcp_close(fd, state);
                return -1;
diff --git a/configure.in b/configure.in
index eb6df15..633b5fa 100644
--- a/configure.in
+++ b/configure.in
@@ -937,6 +937,7 @@ AC_FUNC_STRFTIME
 AC_CHECK_FUNCS(mktime timegm gettimeofday select poll wcrtomb)
 AC_CHECK_FUNCS(strchr strdup strndup strstr strtol strtok strsep)
 AC_CHECK_FUNCS(asprintf vasprintf snprintf vsnprintf getpass setenv)
+AC_CHECK_FUNCS(getaddrinfo)
 AC_CACHE_CHECK(for ISO C99 compliant snprintf,ac_cv_func_snprintf_c99,
        [AC_TRY_RUN([
 #include <stdio.h>

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog            |    3 ++
 common/devices/tcp.c |   64 ++++++++++++++++++++++++++++++++++++++++---------
 configure.in         |    1 +
 3 files changed, 56 insertions(+), 12 deletions(-)


hooks/post-receive
-- 
libgnokii and core programs



reply via email to

[Prev in Thread] Current Thread [Next in Thread]