support IPv6 (#198422)

This commit is contained in:
Nils Philippsen 2010-06-29 15:19:47 +00:00
parent 6dc8a78efc
commit 3c65f159ac
2 changed files with 136 additions and 1 deletions

128
xsane-0.997-ipv6.patch Normal file
View File

@ -0,0 +1,128 @@
diff -up xsane-0.997/src/xsane-save.c.ipv6 xsane-0.997/src/xsane-save.c
--- xsane-0.997/src/xsane-save.c.ipv6 2008-09-20 22:48:29.000000000 +0200
+++ xsane-0.997/src/xsane-save.c 2010-06-29 17:05:03.853290307 +0200
@@ -29,6 +29,8 @@
#include <time.h>
#include <sys/wait.h>
+#include <glib.h>
+
/* the following test is always false */
#ifdef _native_WIN32
# include <winsock.h>
@@ -7462,55 +7464,81 @@ void write_email_attach_file(int fd_sock
/* returns fd_socket if sucessfull, < 0 when error occured */
int open_socket(char *server, int port)
{
- int fd_socket;
- struct sockaddr_in sin;
- struct hostent *he;
+ int fd_socket, e;
+
+ struct addrinfo *ai_list, *ai;
+ struct addrinfo hints;
+ gchar *port_s;
+ gint connected;
+
+ memset(&hints, '\0', sizeof(hints));
+ hints.ai_flags = AI_ADDRCONFIG;
+ hints.ai_socktype = SOCK_STREAM;
+
+ port_s = g_strdup_printf("%d", port);
+ e = getaddrinfo(server, port_s, &hints, &ai_list);
+ g_free(port_s);
- he = gethostbyname(server);
- if (!he)
+ if (e != 0)
{
- DBG(DBG_error, "open_socket: Could not get hostname of \"%s\"\n", server);
+ DBG(DBG_error, "open_socket: Could not lookup \"%s\"\n", server);
return -1;
}
- else
+
+ connected = 0;
+ for (ai = ai_list; ai != NULL && !connected; ai = ai->ai_next)
{
- DBG(DBG_info, "open_socket: connecting to \"%s\" = %d.%d.%d.%d\n",
- he->h_name,
- (unsigned char) he->h_addr_list[0][0],
- (unsigned char) he->h_addr_list[0][1],
- (unsigned char) he->h_addr_list[0][2],
- (unsigned char) he->h_addr_list[0][3]);
- }
+ gchar hostname[NI_MAXHOST];
+ gchar hostaddr[NI_MAXHOST];
+
+ /* If all else fails */
+ strncpy(hostname, "(unknown name)", NI_MAXHOST-1);
+ strncpy(hostaddr, "(unknown address)", NI_MAXHOST-1);
+
+ /* Determine canonical name and IPv4/IPv6 address */
+ (void) getnameinfo(ai->ai_addr, ai->ai_addrlen, hostname, sizeof(hostname),
+ NULL, 0, 0);
+ (void) getnameinfo(ai->ai_addr, ai->ai_addrlen, hostaddr, sizeof(hostaddr),
+ NULL, 0, NI_NUMERICHOST);
+
+ DBG(DBG_info, "open_socket: connecting to \"%s\" (\"%s\"): %s\n",
+ server, hostname, hostaddr);
- if (he->h_addrtype != AF_INET)
- {
- DBG(DBG_error, "open_socket: Unknown address family: %d\n", he->h_addrtype);
- return -1;
- }
+ if ((ai->ai_family != AF_INET) && (ai->ai_family != AF_INET6))
+ {
+ DBG(DBG_error, "open_socket: Unknown address family: %d\n", ai->ai_family);
+ continue;
+ }
- fd_socket = socket(AF_INET, SOCK_STREAM, 0);
+ fd_socket = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
- if (fd_socket < 0)
- {
- DBG(DBG_error, "open_socket: Could not create socket: %s\n", strerror(errno));
- return -1;
- }
+ if (fd_socket < 0)
+ {
+ DBG(DBG_error, "open_socket: Could not create socket: %s\n", strerror(errno));
+ continue;
+ }
-/* setsockopt (dev->ctl, level, TCP_NODELAY, &on, sizeof (on)); */
+ /* setsockopt (dev->ctl, level, TCP_NODELAY, &on, sizeof (on)); */
- sin.sin_port = htons(port);
- sin.sin_family = AF_INET;
- memcpy(&sin.sin_addr, he->h_addr_list[0], he->h_length);
+ if (connect(fd_socket, ai->ai_addr, ai->ai_addrlen) != 0)
+ {
+ DBG(DBG_error, "open_socket: Could not connect with port %d of socket: %s\n", port, strerror(errno));
+ continue;
+ }
+
+ /* All went well */
+ connected = 1;
+ }
- if (connect(fd_socket, &sin, sizeof(sin)))
+ if (!connected)
{
- DBG(DBG_error, "open_socket: Could not connect with port %d of socket: %s\n", ntohs(sin.sin_port), strerror(errno));
- return -1;
+ DBG(DBG_info, "open_socket: Could not connect to any address");
+ return -1;
}
- DBG(DBG_info, "open_socket: Connected with port %d\n", ntohs(sin.sin_port));
+ DBG(DBG_info, "open_socket: Connected with port %d\n", port);
- return fd_socket;
+ return fd_socket;
}
/* ---------------------------------------------------------------------------------------------------------------------- */

View File

@ -14,7 +14,7 @@
Name: xsane
Summary: X Window System front-end for the SANE scanner interface
Version: 0.997
Release: 7%{?dist}
Release: 8%{?dist}
Source0: http://www.xsane.org/download/%{name}-%{version}.tar.gz
Source1: xsane.desktop
# distro-specific: use "xdg-open" instead of "netscape" to launch help browser
@ -30,6 +30,9 @@ Patch3: xsane-0.997-off-root-build.patch
# https://bugzilla.redhat.com/show_bug.cgi?id=608047
# submitted to upstream (Oliver Rauch) via email, 2010-06-28
Patch4: xsane-0.997-no-file-selected.patch
# https://bugzilla.redhat.com/show_bug.cgi?id=198422
# submitted to upstream (Oliver Rauch) via email, 2010-06-29
Patch5: xsane-0.997-ipv6.patch
# autoconf-generated files
Patch10: xsane-0.997-5-autoconf.patch.bz2
License: GPLv2+
@ -85,6 +88,7 @@ done
%patch2 -p1 -b .no-eula
%patch3 -p1 -b .off-root-build
%patch4 -p1 -b .no-file-selected
%patch5 -p1 -b .ipv6
%patch10 -p1 -b .autoconf
@ -154,6 +158,9 @@ fi
%{_datadir}/sane/xsane
%changelog
* Tue Jun 29 2010 Nils Philippsen <nils@redhat.com> 0.997-8
- support IPv6 (#198422)
* Mon Jun 28 2010 Nils Philippsen <nils@redhat.com> 0.997-7
- work around old %%configure macro