diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2011-10-27 09:22:50 +0200 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2011-10-27 09:22:50 +0200 |
commit | d86ab06220f5148db3a664d5659b4ec3f35d1079 (patch) | |
tree | c3cb111c1c77b773ecf13a49fb521b6a5269bdab | |
parent | 482635401b91171259c9a027d0bc2faefb7e8c68 (diff) | |
download | gnutls-d86ab06220f5148db3a664d5659b4ec3f35d1079.tar.gz |
Added recv(), send(), connect() and inet_ntop() gnulib modules.
-rwxr-xr-x | build-aux/config.rpath | 136 | ||||
-rw-r--r-- | gl/Makefile.am | 39 | ||||
-rw-r--r-- | gl/connect.c (renamed from gl/tests/connect.c) | 0 | ||||
-rw-r--r-- | gl/inet_ntop.c | 249 | ||||
-rw-r--r-- | gl/m4/gnulib-cache.m4 | 6 | ||||
-rw-r--r-- | gl/m4/gnulib-comp.m4 | 42 | ||||
-rw-r--r-- | gl/m4/inet_ntop.m4 | 68 | ||||
-rw-r--r-- | gl/recv.c | 49 | ||||
-rw-r--r-- | gl/send.c | 49 | ||||
-rw-r--r-- | gl/tests/Makefile.am | 36 | ||||
-rw-r--r-- | gl/tests/test-inet_ntop.c | 56 | ||||
-rw-r--r-- | gl/tests/test-recv.c | 49 | ||||
-rw-r--r-- | gl/tests/test-send.c | 49 |
13 files changed, 731 insertions, 97 deletions
diff --git a/build-aux/config.rpath b/build-aux/config.rpath index 8bd7f5d726..c547c68825 100755 --- a/build-aux/config.rpath +++ b/build-aux/config.rpath @@ -2,7 +2,7 @@ # Output a system dependent set of variables, describing how to set the # run time search path of shared libraries in an executable. # -# Copyright 1996-2011 Free Software Foundation, Inc. +# Copyright 1996-2007 Free Software Foundation, Inc. # Taken from GNU libtool, 2001 # Originally by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996 # @@ -47,7 +47,7 @@ for cc_temp in $CC""; do done cc_basename=`echo "$cc_temp" | sed -e 's%^.*/%%'` -# Code taken from libtool.m4's _LT_COMPILER_PIC. +# Code taken from libtool.m4's AC_LIBTOOL_PROG_COMPILER_PIC. wl= if test "$GCC" = yes; then @@ -57,7 +57,14 @@ else aix*) wl='-Wl,' ;; - mingw* | cygwin* | pw32* | os2* | cegcc*) + darwin*) + case $cc_basename in + xlc*) + wl='-Wl,' + ;; + esac + ;; + mingw* | cygwin* | pw32* | os2*) ;; hpux9* | hpux10* | hpux11*) wl='-Wl,' @@ -65,37 +72,24 @@ else irix5* | irix6* | nonstopux*) wl='-Wl,' ;; - linux* | k*bsd*-gnu | kopensolaris*-gnu) + newsos6) + ;; + linux* | k*bsd*-gnu) case $cc_basename in - ecc*) + icc* | ecc*) wl='-Wl,' ;; - icc* | ifort*) - wl='-Wl,' - ;; - lf95*) - wl='-Wl,' - ;; - nagfor*) - wl='-Wl,-Wl,,' - ;; - pgcc* | pgf77* | pgf90* | pgf95* | pgfortran*) + pgcc | pgf77 | pgf90) wl='-Wl,' ;; ccc*) wl='-Wl,' ;; - xl* | bgxl* | bgf* | mpixl*) - wl='-Wl,' - ;; como) wl='-lopt=' ;; *) case `$CC -V 2>&1 | sed 5q` in - *Sun\ F* | *Sun*Fortran*) - wl= - ;; *Sun\ C*) wl='-Wl,' ;; @@ -103,24 +97,13 @@ else ;; esac ;; - newsos6) - ;; - *nto* | *qnx*) - ;; osf3* | osf4* | osf5*) wl='-Wl,' ;; rdos*) ;; solaris*) - case $cc_basename in - f77* | f90* | f95* | sunf77* | sunf90* | sunf95*) - wl='-Qoption ld ' - ;; - *) - wl='-Wl,' - ;; - esac + wl='-Wl,' ;; sunos4*) wl='-Qoption ld ' @@ -141,7 +124,7 @@ else esac fi -# Code taken from libtool.m4's _LT_LINKER_SHLIBS. +# Code taken from libtool.m4's AC_LIBTOOL_PROG_LD_SHLIBS. hardcode_libdir_flag_spec= hardcode_libdir_separator= @@ -149,7 +132,7 @@ hardcode_direct=no hardcode_minus_L=no case "$host_os" in - cygwin* | mingw* | pw32* | cegcc*) + cygwin* | mingw* | pw32*) # FIXME: the MSVC++ port hasn't been tested in a loooong time # When not using gcc, we currently assume that we are using # Microsoft Visual C++. @@ -175,21 +158,22 @@ if test "$with_gnu_ld" = yes; then # option of GNU ld is called -rpath, not --rpath. hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' case "$host_os" in - aix[3-9]*) + aix3* | aix4* | aix5*) # On AIX/PPC, the GNU linker is very broken if test "$host_cpu" != ia64; then ld_shlibs=no fi ;; amigaos*) - case "$host_cpu" in - powerpc) - ;; - m68k) - hardcode_libdir_flag_spec='-L$libdir' - hardcode_minus_L=yes - ;; - esac + hardcode_libdir_flag_spec='-L$libdir' + hardcode_minus_L=yes + # Samuel A. Falvo II <kc5tja@dolphin.openprojects.net> reports + # that the semantics of dynamic libraries on AmigaOS, at least up + # to version 4, is to share data among multiple programs linked + # with the same dynamic library. Since this doesn't match the + # behavior of shared libraries on other platforms, we cannot use + # them. + ld_shlibs=no ;; beos*) if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then @@ -198,7 +182,7 @@ if test "$with_gnu_ld" = yes; then ld_shlibs=no fi ;; - cygwin* | mingw* | pw32* | cegcc*) + cygwin* | mingw* | pw32*) # hardcode_libdir_flag_spec is actually meaningless, as there is # no search path for DLLs. hardcode_libdir_flag_spec='-L$libdir' @@ -208,13 +192,11 @@ if test "$with_gnu_ld" = yes; then ld_shlibs=no fi ;; - haiku*) - ;; interix[3-9]*) hardcode_direct=no hardcode_libdir_flag_spec='${wl}-rpath,$libdir' ;; - gnu* | linux* | tpf* | k*bsd*-gnu | kopensolaris*-gnu) + gnu* | linux* | k*bsd*-gnu) if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then : else @@ -272,7 +254,7 @@ else hardcode_direct=unsupported fi ;; - aix[4-9]*) + aix4* | aix5*) if test "$host_cpu" = ia64; then # On IA64, the linker does run time linking by default, so we don't # have to do anything special. @@ -282,7 +264,7 @@ else # Test if we are trying to use run time linking or normal # AIX style linking. If -brtl is somewhere in LDFLAGS, we # need to do runtime linking. - case $host_os in aix4.[23]|aix4.[23].*|aix[5-9]*) + case $host_os in aix4.[23]|aix4.[23].*|aix5*) for ld_flag in $LDFLAGS; do if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then aix_use_runtimelinking=yes @@ -337,18 +319,14 @@ else fi ;; amigaos*) - case "$host_cpu" in - powerpc) - ;; - m68k) - hardcode_libdir_flag_spec='-L$libdir' - hardcode_minus_L=yes - ;; - esac + hardcode_libdir_flag_spec='-L$libdir' + hardcode_minus_L=yes + # see comment about different semantics on the GNU ld section + ld_shlibs=no ;; bsdi[45]*) ;; - cygwin* | mingw* | pw32* | cegcc*) + cygwin* | mingw* | pw32*) # When not using gcc, we currently assume that we are using # Microsoft Visual C++. # hardcode_libdir_flag_spec is actually meaningless, as there is @@ -358,15 +336,24 @@ else ;; darwin* | rhapsody*) hardcode_direct=no - if { case $cc_basename in ifort*) true;; *) test "$GCC" = yes;; esac; }; then + if test "$GCC" = yes ; then : else - ld_shlibs=no + case $cc_basename in + xlc*) + ;; + *) + ld_shlibs=no + ;; + esac fi ;; dgux*) hardcode_libdir_flag_spec='-L$libdir' ;; + freebsd1*) + ld_shlibs=no + ;; freebsd2.2*) hardcode_libdir_flag_spec='-R$libdir' hardcode_direct=yes @@ -427,8 +414,6 @@ else hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' hardcode_libdir_separator=: ;; - *nto* | *qnx*) - ;; openbsd*) if test -f /usr/libexec/ld.so; then hardcode_direct=yes @@ -509,7 +494,7 @@ else fi # Check dynamic linker characteristics -# Code taken from libtool.m4's _LT_SYS_DYNAMIC_LINKER. +# Code taken from libtool.m4's AC_LIBTOOL_SYS_DYNAMIC_LINKER. # Unlike libtool.m4, here we don't care about _all_ names of the library, but # only about the one the linker finds when passed -lNAME. This is the last # element of library_names_spec in libtool.m4, or possibly two of them if the @@ -520,16 +505,11 @@ case "$host_os" in aix3*) library_names_spec='$libname.a' ;; - aix[4-9]*) + aix4* | aix5*) library_names_spec='$libname$shrext' ;; amigaos*) - case "$host_cpu" in - powerpc*) - library_names_spec='$libname$shrext' ;; - m68k) - library_names_spec='$libname.a' ;; - esac + library_names_spec='$libname.a' ;; beos*) library_names_spec='$libname$shrext' @@ -537,7 +517,7 @@ case "$host_os" in bsdi[45]*) library_names_spec='$libname$shrext' ;; - cygwin* | mingw* | pw32* | cegcc*) + cygwin* | mingw* | pw32*) shrext=.dll library_names_spec='$libname.dll.a $libname.lib' ;; @@ -548,6 +528,8 @@ case "$host_os" in dgux*) library_names_spec='$libname$shrext' ;; + freebsd1*) + ;; freebsd* | dragonfly*) case "$host_os" in freebsd[123]*) @@ -559,9 +541,6 @@ case "$host_os" in gnu*) library_names_spec='$libname$shrext' ;; - haiku*) - library_names_spec='$libname$shrext' - ;; hpux9* | hpux10* | hpux11*) case $host_cpu in ia64*) @@ -597,7 +576,7 @@ case "$host_os" in ;; linux*oldld* | linux*aout* | linux*coff*) ;; - linux* | k*bsd*-gnu | kopensolaris*-gnu) + linux* | k*bsd*-gnu) library_names_spec='$libname$shrext' ;; knetbsd*-gnu) @@ -609,7 +588,7 @@ case "$host_os" in newsos6) library_names_spec='$libname$shrext' ;; - *nto* | *qnx*) + nto-qnx*) library_names_spec='$libname$shrext' ;; openbsd*) @@ -640,9 +619,6 @@ case "$host_os" in sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) library_names_spec='$libname$shrext' ;; - tpf*) - library_names_spec='$libname$shrext' - ;; uts4*) library_names_spec='$libname$shrext' ;; diff --git a/gl/Makefile.am b/gl/Makefile.am index 22dc37be6d..428ee4436e 100644 --- a/gl/Makefile.am +++ b/gl/Makefile.am @@ -21,7 +21,7 @@ # the same distribution terms as the rest of that program. # # Generated by gnulib-tool. -# Reproduce by: gnulib-tool --import --dir=. --local-dir=gl/override --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=gl/tests --aux-dir=build-aux --with-tests --avoid=alignof-tests --avoid=lseek-tests --no-conditional-dependencies --libtool --macro-prefix=gl --no-vc-files accept alloca alphasort argp bind byteswap c-ctype close crypto/hmac-md5 crypto/md5 error extensions func getpass getsubopt gettext gettime havelib inet_pton lib-msvc-compat lib-symbol-versions listen maintainer-makefile manywarnings memmem-simple minmax netdb netinet_in progname read-file recvfrom scandir select sendto setsockopt shutdown snprintf socket sockets socklen stdint strcase strverscmp sys_socket sys_stat time_r timespec u64 unistd valgrind-tests vasprintf version-etc version-etc-fsf vfprintf-posix vprintf-posix vsnprintf warnings +# Reproduce by: gnulib-tool --import --dir=. --local-dir=gl/override --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=gl/tests --aux-dir=build-aux --with-tests --avoid=alignof-tests --avoid=lseek-tests --no-conditional-dependencies --libtool --macro-prefix=gl --no-vc-files accept alloca alphasort argp bind byteswap c-ctype close connect crypto/hmac-md5 crypto/md5 error extensions func getpass getsubopt gettext gettime havelib inet_ntop inet_pton lib-msvc-compat lib-symbol-versions listen maintainer-makefile manywarnings memmem-simple minmax netdb netinet_in progname read-file recv recvfrom scandir select send sendto setsockopt shutdown snprintf socket sockets socklen stdint strcase strverscmp sys_socket sys_stat time_r timespec u64 unistd valgrind-tests vasprintf version-etc version-etc-fsf vfprintf-posix vprintf-posix vsnprintf warnings AUTOMAKE_OPTIONS = 1.5 gnits @@ -51,6 +51,7 @@ libgnu_la_DEPENDENCIES = $(gl_LTLIBOBJS) EXTRA_libgnu_la_SOURCES = libgnu_la_LDFLAGS = $(AM_LDFLAGS) libgnu_la_LDFLAGS += -no-undefined +libgnu_la_LDFLAGS += $(INET_NTOP_LIB) libgnu_la_LDFLAGS += $(INET_PTON_LIB) libgnu_la_LDFLAGS += $(LIBSOCKET) libgnu_la_LDFLAGS += $(LIB_CLOCK_GETTIME) @@ -217,6 +218,15 @@ EXTRA_libgnu_la_SOURCES += closedir.c ## end gnulib module closedir +## begin gnulib module connect + + +EXTRA_DIST += connect.c w32sock.h + +EXTRA_libgnu_la_SOURCES += connect.c + +## end gnulib module connect + ## begin gnulib module crypto/hmac-md5 libgnu_la_SOURCES += hmac-md5.c @@ -589,6 +599,15 @@ EXTRA_DIST += $(top_srcdir)/build-aux/config.rpath ## end gnulib module havelib +## begin gnulib module inet_ntop + + +EXTRA_DIST += inet_ntop.c + +EXTRA_libgnu_la_SOURCES += inet_ntop.c + +## end gnulib module inet_ntop + ## begin gnulib module inet_pton @@ -1035,6 +1054,15 @@ EXTRA_libgnu_la_SOURCES += realloc.c ## end gnulib module realloc-posix +## begin gnulib module recv + + +EXTRA_DIST += recv.c w32sock.h + +EXTRA_libgnu_la_SOURCES += recv.c + +## end gnulib module recv + ## begin gnulib module recvfrom @@ -1062,6 +1090,15 @@ EXTRA_libgnu_la_SOURCES += select.c ## end gnulib module select +## begin gnulib module send + + +EXTRA_DIST += send.c w32sock.h + +EXTRA_libgnu_la_SOURCES += send.c + +## end gnulib module send + ## begin gnulib module sendto diff --git a/gl/tests/connect.c b/gl/connect.c index afd13b9f8d..afd13b9f8d 100644 --- a/gl/tests/connect.c +++ b/gl/connect.c diff --git a/gl/inet_ntop.c b/gl/inet_ntop.c new file mode 100644 index 0000000000..c11b1e0c81 --- /dev/null +++ b/gl/inet_ntop.c @@ -0,0 +1,249 @@ +/* inet_ntop.c -- convert IPv4 and IPv6 addresses from binary to text form + + Copyright (C) 2005-2006, 2008-2011 Free Software Foundation, Inc. + + This program 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, or (at your option) + any later version. + + This program 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, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* + * Copyright (c) 1996-1999 by Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS + * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE + * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + */ + +#include <config.h> + +/* Specification. */ +#include <arpa/inet.h> + +#if HAVE_DECL_INET_NTOP + +# undef inet_ntop + +const char * +rpl_inet_ntop (int af, const void *restrict src, + char *restrict dst, socklen_t cnt) +{ + return inet_ntop (af, src, dst, cnt); +} + +#else + +# include <stdio.h> +# include <string.h> +# include <errno.h> + +# define NS_IN6ADDRSZ 16 +# define NS_INT16SZ 2 + +/* + * WARNING: Don't even consider trying to compile this on a system where + * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. + */ +typedef int verify_int_size[4 <= sizeof (int) ? 1 : -1]; + +static const char *inet_ntop4 (const unsigned char *src, char *dst, socklen_t size); +# if HAVE_IPV6 +static const char *inet_ntop6 (const unsigned char *src, char *dst, socklen_t size); +# endif + + +/* char * + * inet_ntop(af, src, dst, size) + * convert a network format address to presentation format. + * return: + * pointer to presentation format address (`dst'), or NULL (see errno). + * author: + * Paul Vixie, 1996. + */ +const char * +inet_ntop (int af, const void *restrict src, + char *restrict dst, socklen_t cnt) +{ + switch (af) + { +# if HAVE_IPV4 + case AF_INET: + return (inet_ntop4 (src, dst, cnt)); +# endif + +# if HAVE_IPV6 + case AF_INET6: + return (inet_ntop6 (src, dst, cnt)); +# endif + + default: + errno = EAFNOSUPPORT; + return (NULL); + } + /* NOTREACHED */ +} + +/* const char * + * inet_ntop4(src, dst, size) + * format an IPv4 address + * return: + * `dst' (as a const) + * notes: + * (1) uses no statics + * (2) takes a u_char* not an in_addr as input + * author: + * Paul Vixie, 1996. + */ +static const char * +inet_ntop4 (const unsigned char *src, char *dst, socklen_t size) +{ + char tmp[sizeof "255.255.255.255"]; + int len; + + len = sprintf (tmp, "%u.%u.%u.%u", src[0], src[1], src[2], src[3]); + if (len < 0) + return NULL; + + if (len > size) + { + errno = ENOSPC; + return NULL; + } + + return strcpy (dst, tmp); +} + +# if HAVE_IPV6 + +/* const char * + * inet_ntop6(src, dst, size) + * convert IPv6 binary address into presentation (printable) format + * author: + * Paul Vixie, 1996. + */ +static const char * +inet_ntop6 (const unsigned char *src, char *dst, socklen_t size) +{ + /* + * Note that int32_t and int16_t need only be "at least" large enough + * to contain a value of the specified size. On some systems, like + * Crays, there is no such thing as an integer variable with 16 bits. + * Keep this in mind if you think this function should have been coded + * to use pointer overlays. All the world's not a VAX. + */ + char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp; + struct + { + int base, len; + } best, cur; + unsigned int words[NS_IN6ADDRSZ / NS_INT16SZ]; + int i; + + /* + * Preprocess: + * Copy the input (bytewise) array into a wordwise array. + * Find the longest run of 0x00's in src[] for :: shorthanding. + */ + memset (words, '\0', sizeof words); + for (i = 0; i < NS_IN6ADDRSZ; i += 2) + words[i / 2] = (src[i] << 8) | src[i + 1]; + best.base = -1; + cur.base = -1; + for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) + { + if (words[i] == 0) + { + if (cur.base == -1) + cur.base = i, cur.len = 1; + else + cur.len++; + } + else + { + if (cur.base != -1) + { + if (best.base == -1 || cur.len > best.len) + best = cur; + cur.base = -1; + } + } + } + if (cur.base != -1) + { + if (best.base == -1 || cur.len > best.len) + best = cur; + } + if (best.base != -1 && best.len < 2) + best.base = -1; + + /* + * Format the result. + */ + tp = tmp; + for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) + { + /* Are we inside the best run of 0x00's? */ + if (best.base != -1 && i >= best.base && i < (best.base + best.len)) + { + if (i == best.base) + *tp++ = ':'; + continue; + } + /* Are we following an initial run of 0x00s or any real hex? */ + if (i != 0) + *tp++ = ':'; + /* Is this address an encapsulated IPv4? */ + if (i == 6 && best.base == 0 && + (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) + { + if (!inet_ntop4 (src + 12, tp, sizeof tmp - (tp - tmp))) + return (NULL); + tp += strlen (tp); + break; + } + { + int len = sprintf (tp, "%x", words[i]); + if (len < 0) + return NULL; + tp += len; + } + } + /* Was it a trailing run of 0x00's? */ + if (best.base != -1 && (best.base + best.len) == + (NS_IN6ADDRSZ / NS_INT16SZ)) + *tp++ = ':'; + *tp++ = '\0'; + + /* + * Check for overflow, copy, and we're done. + */ + if ((socklen_t) (tp - tmp) > size) + { + errno = ENOSPC; + return NULL; + } + + return strcpy (dst, tmp); +} + +# endif + +#endif diff --git a/gl/m4/gnulib-cache.m4 b/gl/m4/gnulib-cache.m4 index 33907399f9..4777c60465 100644 --- a/gl/m4/gnulib-cache.m4 +++ b/gl/m4/gnulib-cache.m4 @@ -27,7 +27,7 @@ # Specification in the form of a command-line invocation: -# gnulib-tool --import --dir=. --local-dir=gl/override --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=gl/tests --aux-dir=build-aux --with-tests --avoid=alignof-tests --avoid=lseek-tests --no-conditional-dependencies --libtool --macro-prefix=gl --no-vc-files accept alloca alphasort argp bind byteswap c-ctype close crypto/hmac-md5 crypto/md5 error extensions func getpass getsubopt gettext gettime havelib inet_pton lib-msvc-compat lib-symbol-versions listen maintainer-makefile manywarnings memmem-simple minmax netdb netinet_in progname read-file recvfrom scandir select sendto setsockopt shutdown snprintf socket sockets socklen stdint strcase strverscmp sys_socket sys_stat time_r timespec u64 unistd valgrind-tests vasprintf version-etc version-etc-fsf vfprintf-posix vprintf-posix vsnprintf warnings +# gnulib-tool --import --dir=. --local-dir=gl/override --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=gl/tests --aux-dir=build-aux --with-tests --avoid=alignof-tests --avoid=lseek-tests --no-conditional-dependencies --libtool --macro-prefix=gl --no-vc-files accept alloca alphasort argp bind byteswap c-ctype close connect crypto/hmac-md5 crypto/md5 error extensions func getpass getsubopt gettext gettime havelib inet_ntop inet_pton lib-msvc-compat lib-symbol-versions listen maintainer-makefile manywarnings memmem-simple minmax netdb netinet_in progname read-file recv recvfrom scandir select send sendto setsockopt shutdown snprintf socket sockets socklen stdint strcase strverscmp sys_socket sys_stat time_r timespec u64 unistd valgrind-tests vasprintf version-etc version-etc-fsf vfprintf-posix vprintf-posix vsnprintf warnings # Specification in the form of a few gnulib-tool.m4 macro invocations: gl_LOCAL_DIR([gl/override]) @@ -40,6 +40,7 @@ gl_MODULES([ byteswap c-ctype close + connect crypto/hmac-md5 crypto/md5 error @@ -50,6 +51,7 @@ gl_MODULES([ gettext gettime havelib + inet_ntop inet_pton lib-msvc-compat lib-symbol-versions @@ -62,9 +64,11 @@ gl_MODULES([ netinet_in progname read-file + recv recvfrom scandir select + send sendto setsockopt shutdown diff --git a/gl/m4/gnulib-comp.m4 b/gl/m4/gnulib-comp.m4 index 461cac0d12..1461989c89 100644 --- a/gl/m4/gnulib-comp.m4 +++ b/gl/m4/gnulib-comp.m4 @@ -142,6 +142,8 @@ AC_DEFUN([gl_EARLY], # Code from module ignore-value: # Code from module ignore-value-tests: # Code from module include_next: + # Code from module inet_ntop: + # Code from module inet_ntop-tests: # Code from module inet_pton: # Code from module inet_pton-tests: # Code from module intprops: @@ -213,12 +215,16 @@ AC_DEFUN([gl_EARLY], # Code from module read-file-tests: # Code from module readdir: # Code from module realloc-posix: + # Code from module recv: + # Code from module recv-tests: # Code from module recvfrom: # Code from module recvfrom-tests: # Code from module same-inode: # Code from module scandir: # Code from module select: # Code from module select-tests: + # Code from module send: + # Code from module send-tests: # Code from module sendto: # Code from module sendto-tests: # Code from module setenv: @@ -393,6 +399,11 @@ if test $HAVE_CLOSEDIR = 0 || test $REPLACE_CLOSEDIR = 1; then AC_LIBOBJ([closedir]) fi gl_DIRENT_MODULE_INDICATOR([closedir]) +AC_REQUIRE([gl_HEADER_SYS_SOCKET]) +if test "$ac_cv_header_winsock2_h" = yes; then + AC_LIBOBJ([connect]) +fi +gl_SYS_SOCKET_MODULE_INDICATOR([connect]) gl_MD5 gl_DIRENT_H gl_DIRNAME_LGPL @@ -512,6 +523,12 @@ m4_if(m4_version_compare([2.61a.100], m4_defn([m4_PACKAGE_VERSION])), [1], [], [AC_CONFIG_LINKS([$GNUmakefile:$GNUmakefile], [], [GNUmakefile=$GNUmakefile])]) +gl_FUNC_INET_NTOP +if test $HAVE_INET_NTOP = 0 || test $REPLACE_INET_NTOP = 1; then + AC_LIBOBJ([inet_ntop]) + gl_PREREQ_INET_NTOP +fi +gl_ARPA_INET_MODULE_INDICATOR([inet_ntop]) gl_FUNC_INET_PTON if test $HAVE_INET_PTON = 0 || test $REPLACE_INET_NTOP = 1; then AC_LIBOBJ([inet_pton]) @@ -618,6 +635,11 @@ fi gl_STDLIB_MODULE_INDICATOR([realloc-posix]) AC_REQUIRE([gl_HEADER_SYS_SOCKET]) if test "$ac_cv_header_winsock2_h" = yes; then + AC_LIBOBJ([recv]) +fi +gl_SYS_SOCKET_MODULE_INDICATOR([recv]) +AC_REQUIRE([gl_HEADER_SYS_SOCKET]) +if test "$ac_cv_header_winsock2_h" = yes; then AC_LIBOBJ([recvfrom]) fi gl_SYS_SOCKET_MODULE_INDICATOR([recvfrom]) @@ -634,6 +656,11 @@ fi gl_SYS_SELECT_MODULE_INDICATOR([select]) AC_REQUIRE([gl_HEADER_SYS_SOCKET]) if test "$ac_cv_header_winsock2_h" = yes; then + AC_LIBOBJ([send]) +fi +gl_SYS_SOCKET_MODULE_INDICATOR([send]) +AC_REQUIRE([gl_HEADER_SYS_SOCKET]) +if test "$ac_cv_header_winsock2_h" = yes; then AC_LIBOBJ([sendto]) fi gl_SYS_SOCKET_MODULE_INDICATOR([sendto]) @@ -826,11 +853,6 @@ changequote([, ])dnl AC_SUBST([gltests_WITNESS]) gl_module_indicator_condition=$gltests_WITNESS m4_pushdef([gl_MODULE_INDICATOR_CONDITION], [$gl_module_indicator_condition]) -AC_REQUIRE([gl_HEADER_SYS_SOCKET]) -if test "$ac_cv_header_winsock2_h" = yes; then - AC_LIBOBJ([connect]) -fi -gl_SYS_SOCKET_MODULE_INDICATOR([connect]) gl_FUNC_DUP2 if test $HAVE_DUP2 = 0 || test $REPLACE_DUP2 = 1; then AC_LIBOBJ([dup2]) @@ -868,6 +890,7 @@ fi gl_UNISTD_MODULE_INDICATOR([getpagesize]) AC_REQUIRE([AC_C_INLINE]) AC_C_BIGENDIAN +AC_C_BIGENDIAN gl_INTTYPES_H gl_INTTYPES_INCOMPLETE gl_FUNC_IOCTL @@ -1092,6 +1115,7 @@ AC_DEFUN([gl_FILE_LIST], [ lib/c-ctype.h lib/close.c lib/closedir.c + lib/connect.c lib/dirent-private.h lib/dirent.in.h lib/dirname-lgpl.c @@ -1131,6 +1155,7 @@ AC_DEFUN([gl_FILE_LIST], [ lib/gettimeofday.c lib/hmac-md5.c lib/hmac.h + lib/inet_ntop.c lib/inet_pton.c lib/intprops.h lib/isnan.c @@ -1177,9 +1202,11 @@ AC_DEFUN([gl_FILE_LIST], [ lib/read-file.h lib/readdir.c lib/realloc.c + lib/recv.c lib/recvfrom.c lib/scandir.c lib/select.c + lib/send.c lib/sendto.c lib/setsockopt.c lib/shutdown.c @@ -1291,6 +1318,7 @@ AC_DEFUN([gl_FILE_LIST], [ m4/gnulib-common.m4 m4/iconv.m4 m4/include_next.m4 + m4/inet_ntop.m4 m4/inet_pton.m4 m4/intdiv0.m4 m4/intl.m4 @@ -1482,6 +1510,7 @@ AC_DEFUN([gl_FILE_LIST], [ tests/test-gettimeofday.c tests/test-hmac-md5.c tests/test-ignore-value.c + tests/test-inet_ntop.c tests/test-inet_pton.c tests/test-intprops.c tests/test-inttypes.c @@ -1516,6 +1545,7 @@ AC_DEFUN([gl_FILE_LIST], [ tests/test-printf-posix.output tests/test-rawmemchr.c tests/test-read-file.c + tests/test-recv.c tests/test-recvfrom.c tests/test-select-fd.c tests/test-select-in.sh @@ -1523,6 +1553,7 @@ AC_DEFUN([gl_FILE_LIST], [ tests/test-select-stdin.c tests/test-select.c tests/test-select.h + tests/test-send.c tests/test-sendto.c tests/test-setenv.c tests/test-setsockopt.c @@ -1579,7 +1610,6 @@ AC_DEFUN([gl_FILE_LIST], [ tests/test-wchar.c tests/zerosize-ptr.h tests=lib/binary-io.h - tests=lib/connect.c tests=lib/dup2.c tests=lib/fcntl.in.h tests=lib/fdopen.c diff --git a/gl/m4/inet_ntop.m4 b/gl/m4/inet_ntop.m4 new file mode 100644 index 0000000000..4936fa382f --- /dev/null +++ b/gl/m4/inet_ntop.m4 @@ -0,0 +1,68 @@ +# inet_ntop.m4 serial 19 +dnl Copyright (C) 2005-2006, 2008-2011 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_INET_NTOP], +[ + AC_REQUIRE([gl_ARPA_INET_H_DEFAULTS]) + + dnl Persuade Solaris <arpa/inet.h> to declare inet_ntop. + AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) + + AC_REQUIRE([AC_C_RESTRICT]) + + dnl Most platforms that provide inet_ntop define it in libc. + dnl Solaris 8..10 provide inet_ntop in libnsl instead. + dnl Solaris 2.6..7 provide inet_ntop in libresolv instead. + dnl Native Windows provides it in -lws2_32 instead, with a declaration in + dnl <ws2tcpip.h>, and it uses stdcall calling convention, not cdecl + dnl (hence we cannot use AC_CHECK_FUNCS, AC_SEARCH_LIBS to find it). + HAVE_INET_NTOP=1 + INET_NTOP_LIB= + gl_PREREQ_SYS_H_WINSOCK2 + if test $HAVE_WINSOCK2_H = 1; then + AC_CHECK_DECLS([inet_ntop],,, [[#include <ws2tcpip.h>]]) + if test $ac_cv_have_decl_inet_ntop = yes; then + dnl It needs to be overridden, because the stdcall calling convention + dnl is not compliant with POSIX. + REPLACE_INET_NTOP=1 + INET_NTOP_LIB="-lws2_32" + else + HAVE_DECL_INET_NTOP=0 + HAVE_INET_NTOP=0 + fi + else + gl_save_LIBS=$LIBS + AC_SEARCH_LIBS([inet_ntop], [nsl resolv], [], + [AC_CHECK_FUNCS([inet_ntop]) + if test $ac_cv_func_inet_ntop = no; then + HAVE_INET_NTOP=0 + fi + ]) + LIBS=$gl_save_LIBS + + if test "$ac_cv_search_inet_ntop" != "no" \ + && test "$ac_cv_search_inet_ntop" != "none required"; then + INET_NTOP_LIB="$ac_cv_search_inet_ntop" + fi + + AC_CHECK_HEADERS_ONCE([netdb.h]) + AC_CHECK_DECLS([inet_ntop],,, + [[#include <arpa/inet.h> + #if HAVE_NETDB_H + # include <netdb.h> + #endif + ]]) + if test $ac_cv_have_decl_inet_ntop = no; then + HAVE_DECL_INET_NTOP=0 + fi + fi + AC_SUBST([INET_NTOP_LIB]) +]) + +# Prerequisites of lib/inet_ntop.c. +AC_DEFUN([gl_PREREQ_INET_NTOP], [ + AC_REQUIRE([gl_SOCKET_FAMILIES]) +]) diff --git a/gl/recv.c b/gl/recv.c new file mode 100644 index 0000000000..4755f63709 --- /dev/null +++ b/gl/recv.c @@ -0,0 +1,49 @@ +/* recv.c --- wrappers for Windows recv function + + Copyright (C) 2008-2011 Free Software Foundation, Inc. + + This program 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. + + This program 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/>. */ + +/* Written by Paolo Bonzini */ + +#include <config.h> + +#define WIN32_LEAN_AND_MEAN +/* Get winsock2.h. */ +#include <sys/socket.h> + +/* Get set_winsock_errno, FD_TO_SOCKET etc. */ +#include "w32sock.h" + +#undef recv + +ssize_t +rpl_recv (int fd, void *buf, size_t len, int flags) +{ + SOCKET sock = FD_TO_SOCKET (fd); + + if (sock == INVALID_SOCKET) + { + errno = EBADF; + return -1; + } + else + { + int r = recv (sock, buf, len, flags); + if (r < 0) + set_winsock_errno (); + + return r; + } +} diff --git a/gl/send.c b/gl/send.c new file mode 100644 index 0000000000..cd21482900 --- /dev/null +++ b/gl/send.c @@ -0,0 +1,49 @@ +/* send.c --- wrappers for Windows send function + + Copyright (C) 2008-2011 Free Software Foundation, Inc. + + This program 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. + + This program 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/>. */ + +/* Written by Paolo Bonzini */ + +#include <config.h> + +#define WIN32_LEAN_AND_MEAN +/* Get winsock2.h. */ +#include <sys/socket.h> + +/* Get set_winsock_errno, FD_TO_SOCKET etc. */ +#include "w32sock.h" + +#undef send + +ssize_t +rpl_send (int fd, const void *buf, size_t len, int flags) +{ + SOCKET sock = FD_TO_SOCKET (fd); + + if (sock == INVALID_SOCKET) + { + errno = EBADF; + return -1; + } + else + { + int r = send (sock, buf, len, flags); + if (r < 0) + set_winsock_errno (); + + return r; + } +} diff --git a/gl/tests/Makefile.am b/gl/tests/Makefile.am index 205b736bbc..4759912e18 100644 --- a/gl/tests/Makefile.am +++ b/gl/tests/Makefile.am @@ -142,15 +142,6 @@ EXTRA_DIST += test-close.c signature.h macros.h ## end gnulib module close-tests -## begin gnulib module connect - - -EXTRA_DIST += connect.c w32sock.h - -EXTRA_libtests_a_SOURCES += connect.c - -## end gnulib module connect - ## begin gnulib module connect-tests TESTS += test-connect @@ -500,6 +491,15 @@ EXTRA_DIST += test-ignore-value.c ## end gnulib module ignore-value-tests +## begin gnulib module inet_ntop-tests + +TESTS += test-inet_ntop +check_PROGRAMS += test-inet_ntop +test_inet_ntop_LDADD = $(LDADD) @INET_NTOP_LIB@ +EXTRA_DIST += test-inet_ntop.c signature.h macros.h + +## end gnulib module inet_ntop-tests + ## begin gnulib module inet_pton-tests TESTS += test-inet_pton @@ -816,6 +816,15 @@ EXTRA_DIST += test-read-file.c ## end gnulib module read-file-tests +## begin gnulib module recv-tests + +TESTS += test-recv +check_PROGRAMS += test-recv +test_recv_LDADD = $(LDADD) @LIBSOCKET@ +EXTRA_DIST += test-recv.c signature.h macros.h + +## end gnulib module recv-tests + ## begin gnulib module recvfrom-tests TESTS += test-recvfrom @@ -844,6 +853,15 @@ EXTRA_DIST += macros.h signature.h test-select.c test-select.h test-select-fd.c ## end gnulib module select-tests +## begin gnulib module send-tests + +TESTS += test-send +check_PROGRAMS += test-send +test_send_LDADD = $(LDADD) @LIBSOCKET@ +EXTRA_DIST += test-send.c signature.h macros.h + +## end gnulib module send-tests + ## begin gnulib module sendto-tests TESTS += test-sendto diff --git a/gl/tests/test-inet_ntop.c b/gl/tests/test-inet_ntop.c new file mode 100644 index 0000000000..ebb7c1c093 --- /dev/null +++ b/gl/tests/test-inet_ntop.c @@ -0,0 +1,56 @@ +/* Test of inet_ntop function. + Copyright (C) 2009-2011 Free Software Foundation, Inc. + + This program 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. + + This program 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/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2009. */ + +#include <config.h> + +#include <arpa/inet.h> + +#include "signature.h" +SIGNATURE_CHECK (inet_ntop, char const *, (int, void const *, char *, + socklen_t)); + +#include <netinet/in.h> +#include <sys/socket.h> +#include <string.h> + +#include "macros.h" + +int +main (void) +{ +#if defined AF_INET /* HAVE_IPV4 */ + { + struct in_addr internal; + char printable[16]; + const char *result; + + /* This machine was for a long time known as + ma2s2.mathematik.uni-karlsruhe.de. */ +# ifdef WORDS_BIGENDIAN + internal.s_addr = 0x810D7302; +# else + internal.s_addr = 0x02730D81; +# endif + result = inet_ntop (AF_INET, &internal, printable, sizeof (printable)); + ASSERT (result != NULL); + ASSERT (strcmp (result, "129.13.115.2") == 0); + } +#endif + + return 0; +} diff --git a/gl/tests/test-recv.c b/gl/tests/test-recv.c new file mode 100644 index 0000000000..ae811b6658 --- /dev/null +++ b/gl/tests/test-recv.c @@ -0,0 +1,49 @@ +/* Test the recv() function. + Copyright (C) 2011 Free Software Foundation, Inc. + + This program 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. + + This program 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/>. */ + +#include <config.h> + +#include <sys/socket.h> + +#include "signature.h" +SIGNATURE_CHECK (recv, ssize_t, (int, void *, size_t, int)); + +#include <errno.h> + +#include "sockets.h" +#include "macros.h" + +int +main (void) +{ + gl_sockets_startup (SOCKETS_1_1); + + /* Test behaviour for invalid file descriptors. */ + { + char byte; + errno = 0; + ASSERT (recv (-1, &byte, 1, 0) == -1); + ASSERT (errno == EBADF); + } + { + char byte; + errno = 0; + ASSERT (recv (99, &byte, 1, 0) == -1); + ASSERT (errno == EBADF); + } + + return 0; +} diff --git a/gl/tests/test-send.c b/gl/tests/test-send.c new file mode 100644 index 0000000000..9fb24d4395 --- /dev/null +++ b/gl/tests/test-send.c @@ -0,0 +1,49 @@ +/* Test the send() function. + Copyright (C) 2011 Free Software Foundation, Inc. + + This program 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. + + This program 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/>. */ + +#include <config.h> + +#include <sys/socket.h> + +#include "signature.h" +SIGNATURE_CHECK (send, ssize_t, (int, const void *, size_t, int)); + +#include <errno.h> + +#include "sockets.h" +#include "macros.h" + +int +main (void) +{ + gl_sockets_startup (SOCKETS_1_1); + + /* Test behaviour for invalid file descriptors. */ + { + char byte = 'x'; + errno = 0; + ASSERT (send (-1, &byte, 1, 0) == -1); + ASSERT (errno == EBADF); + } + { + char byte = 'x'; + errno = 0; + ASSERT (send (99, &byte, 1, 0) == -1); + ASSERT (errno == EBADF); + } + + return 0; +} |