diff --git a/ChangeLog b/ChangeLog
index d52508b..af7429b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2010-08-19 Mats Erik Andersson
+
+ * libinetutils/sockaddr_aux.h: New file.
+ * libinetutils/sockaddr_aux.c: New file.
+ * libinetutils/Makefile.am: Add sockaddr_aux.h and sockaddr_aux.c.
+ * libinetutils/tftpsubs.c (synchnet): Replace 'struct sockaddr_in' by
+ 'struct sockaddr_storage'.
+
2010-08-18 Giuseppe Scrivano
Under GNU/Linux print interfaces without an address with ifconfig -a.
diff --git a/libinetutils/Makefile.am b/libinetutils/Makefile.am
index 07e0566..a15b4e4 100644
--- a/libinetutils/Makefile.am
+++ b/libinetutils/Makefile.am
@@ -19,7 +19,8 @@
noinst_LIBRARIES = libinetutils.a
-noinst_HEADERS = argcv.h libinetutils.h tftpsubs.h shishi_def.h
+noinst_HEADERS = argcv.h libinetutils.h tftpsubs.h shishi_def.h \
+ sockaddr_aux.h
EXTRA_DIST = logwtmp.c
@@ -29,6 +30,7 @@ libinetutils_a_SOURCES = \
daemon.c\
defauthors.c\
des_rw.c\
+ sockaddr_aux.c \
kcmd.c\
krcmd.c\
localhost.c\
diff --git a/libinetutils/sockaddr_aux.c b/libinetutils/sockaddr_aux.c
new file mode 100644
index 0000000..f882f6e
--- /dev/null
+++ b/libinetutils/sockaddr_aux.c
@@ -0,0 +1,98 @@
+/*
+ Copyright (C) 2010 Free Software Foundation, Inc.
+
+ This file is part of GNU Inetutils.
+
+ GNU Inetutils is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or (at
+ your option) any later version.
+
+ GNU Inetutils is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see `http://www.gnu.org/licenses/'.
+*/
+
+/* A collection of helpers intended to handle IPv6 and IPv4 simultaneously
+ in a transparent manner. An underlying use of 'struct sockaddr_storage'
+ is conceiled as 'struct sockaddr' in the call from an application.
+
+ The helper function resolves and manipulates this as 'struct sockaddr_in'
+ or as 'struct sockaddr_in6', depending on contents.
+
+ Mats Erik Andersson, August 2010
+*/
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include "sockaddr_aux.h"
+
+/*
+ * get_port
+ *
+ * Return: port number in host byte order.
+ * Input: pointer to 'struct sockaddr'.
+ */
+in_port_t
+get_port (struct sockaddr *sa)
+{
+ switch (sa->sa_family)
+ {
+ case AF_INET:
+ return ntohs (((struct sockaddr_in *) sa)->sin_port);
+ case AF_INET6:
+ return ntohs (((struct sockaddr_in6 *) sa)->sin6_port);
+ default:
+ return 0;
+ }
+}
+
+/*
+ * set_port
+ *
+ * Input: pointer to 'struct sockaddr', and
+ * port number in host byte order.
+ */
+void
+set_port (struct sockaddr *sa, in_port_t port)
+{
+ switch (sa->sa_family)
+ {
+ case AF_INET:
+ (((struct sockaddr_in *) sa)->sin_port) = htons (port);
+ break;
+ case AF_INET6:
+ (((struct sockaddr_in6 *) sa)->sin6_port) = htons (port);
+ default:
+ break;
+ }
+}
+
+/*
+ * get_socklen
+ *
+ * Input: pointer to 'struct sockaddr'.
+ * Return: exact address structure size for AF_INET and AF_INET6.
+ */
+socklen_t
+get_socklen (struct sockaddr *sa)
+{
+ switch (sa->sa_family)
+ {
+ case AF_INET:
+ return sizeof (struct sockaddr_in);
+ break;
+ case AF_INET6:
+ return sizeof (struct sockaddr_in6);
+ break;
+ default:
+ return sizeof (*sa);
+ break;
+ }
+}
diff --git a/libinetutils/sockaddr_aux.h b/libinetutils/sockaddr_aux.h
new file mode 100644
index 0000000..7e2545d
--- /dev/null
+++ b/libinetutils/sockaddr_aux.h
@@ -0,0 +1,43 @@
+/*
+ Copyright (C) 2010 Free Software Foundation, Inc.
+
+ This file is part of GNU Inetutils.
+
+ GNU Inetutils is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or (at
+ your option) any later version.
+
+ GNU Inetutils is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see `http://www.gnu.org/licenses/'.
+*/
+
+/* A collection of helpers intended to handle IPv6 and IPv4 simultaneously
+ in a transparent manner. An underlying use of 'struct sockaddr_storage'
+ is conceiled as 'struct sockaddr' in the call from an application.
+
+ The helper function resolves and manipulates this as 'struct sockaddr_in'
+ or as 'struct sockaddr_in6', depending on contents.
+
+ Mats Erik Andersson, August 2010
+*/
+
+/*
+ * Prototypes for address family independecy.
+ */
+
+#include
+#include
+#include
+#include
+
+in_port_t get_port (struct sockaddr *sa);
+
+void set_port (struct sockaddr *sa, in_port_t port);
+
+socklen_t get_socklen (struct sockaddr *sa);
diff --git a/libinetutils/tftpsubs.c b/libinetutils/tftpsubs.c
index 6eb0a09..371764b 100644
--- a/libinetutils/tftpsubs.c
+++ b/libinetutils/tftpsubs.c
@@ -287,7 +287,7 @@ synchnet (int f)
{
int i, j = 0;
char rbuf[PKTSIZE];
- struct sockaddr_in from;
+ struct sockaddr_storage from;
socklen_t fromlen;
while (1)