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 /gl | |
parent | 482635401b91171259c9a027d0bc2faefb7e8c68 (diff) | |
download | gnutls-d86ab06220f5148db3a664d5659b4ec3f35d1079.tar.gz |
Added recv(), send(), connect() and inet_ntop() gnulib modules.
Diffstat (limited to 'gl')
-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 |
12 files changed, 675 insertions, 17 deletions
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; +} |