gnutls-commit
[Top][All Lists]
Advanced

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

[SCM] GNU gnutls branch, master, updated. gnutls-3_0_12-156-gfec4c0b


From: Nikos Mavrogiannopoulos
Subject: [SCM] GNU gnutls branch, master, updated. gnutls-3_0_12-156-gfec4c0b
Date: Wed, 08 Feb 2012 09:54:03 +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 "GNU gnutls".

http://git.savannah.gnu.org/cgit/gnutls.git/commit/?id=fec4c0b841356f94f7fccb6a038e948b59ca24bb

The branch, master has been updated
       via  fec4c0b841356f94f7fccb6a038e948b59ca24bb (commit)
       via  049548a86f0323083012aaabe7555ba10b67eaa4 (commit)
       via  bdafbb24bc2d4beda71faa87036ace0dcab474fb (commit)
       via  673a79027c04eaa8aa68353990753cf32dc7774a (commit)
       via  11b4fd9d4ffd392b5b5a4ec0f0fefe713b2e1117 (commit)
      from  35c17f2fd72083bf12c5faa83195d18c3cb759ce (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 -----------------------------------------------------------------
commit fec4c0b841356f94f7fccb6a038e948b59ca24bb
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Wed Feb 8 10:59:05 2012 +0100

    enable crywrap only if function daemon exists.

commit 049548a86f0323083012aaabe7555ba10b67eaa4
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Wed Feb 8 10:58:23 2012 +0100

    Be conservative when sending GNUTLS_E_AGAIN and check for a DTLS timeout 
before.

commit bdafbb24bc2d4beda71faa87036ace0dcab474fb
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Wed Feb 8 10:42:37 2012 +0100

    added strndup and updated gnulib.

commit 673a79027c04eaa8aa68353990753cf32dc7774a
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Wed Feb 8 10:31:53 2012 +0100

    Added test to simulate loss of packets in DTLS.

commit 11b4fd9d4ffd392b5b5a4ec0f0fefe713b2e1117
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Wed Feb 8 10:16:45 2012 +0100

    DTLS fixes.
    Corrected bugs in DTLS sliding window code to account for lost packets
    arriving after an epoch change. The last handshake flight is now being
    kept by both parties in order to be used as a lost packet indication.

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

Summary of changes:
 .gitignore                                |    2 +
 configure.ac                              |   12 +-
 gl/Makefile.am                            |    3 +-
 gl/argp-help.c                            |   18 ++--
 gl/argp-parse.c                           |    6 +-
 gl/argp.h                                 |    6 +-
 gl/base64.c                               |   24 +++-
 gl/fseeko.c                               |    3 +
 gl/fseterr.c                              |    3 +
 gl/gettimeofday.c                         |   11 ++
 gl/m4/exponentd.m4                        |    5 +-
 gl/m4/gettimeofday.m4                     |    6 +-
 gl/m4/gnulib-cache.m4                     |    3 +-
 gl/m4/po.m4                               |    8 +-
 gl/m4/stdalign.m4                         |    7 +-
 gl/m4/sys_time_h.m4                       |   32 ++++-
 gl/m4/vasnprintf.m4                       |    6 +-
 gl/select.c                               |    8 +-
 gl/sleep.c                                |    2 +-
 gl/stdio-impl.h                           |    2 +
 gl/stdio.in.h                             |    2 +-
 gl/sys_select.in.h                        |   23 +++-
 gl/sys_socket.in.h                        |    2 +-
 gl/sys_stat.in.h                          |   27 +++-
 gl/sys_time.in.h                          |   14 ++-
 gl/tests/init.sh                          |    5 +-
 gl/tests/ioctl.c                          |    7 +-
 gl/tests/test-base64.c                    |    4 +-
 gl/tests/test-init.sh                     |   19 ++--
 gl/tests/test-strerror.c                  |    2 +-
 gl/tests/test-sys_select.c                |    5 +-
 gl/tests/test-sys_time.c                  |    4 +
 gl/tests/w32sock.h                        |    4 +-
 gl/vasnprintf.c                           |    4 +-
 gl/version-etc.h                          |    2 +-
 gl/w32sock.h                              |    4 +-
 lib/debug.c                               |    2 +-
 lib/gnutls_buffers.c                      |   13 +--
 lib/gnutls_dtls.c                         |   53 +++++---
 lib/gnutls_dtls.h                         |   11 ++
 lib/gnutls_record.c                       |   14 ++-
 maint.mk                                  |   14 +-
 tests/Makefile.am                         |    2 +-
 tests/loss-common.h                       |  215 +++++++++++++++++++++++++++++
 tests/{mini-eagain-dtls.c => mini-loss.c} |   85 +++++-------
 45 files changed, 532 insertions(+), 172 deletions(-)
 create mode 100644 tests/loss-common.h
 copy tests/{mini-eagain-dtls.c => mini-loss.c} (68%)

diff --git a/.gitignore b/.gitignore
index 291a285..e723136 100644
--- a/.gitignore
+++ b/.gitignore
@@ -518,6 +518,7 @@ tests/key-id/Makefile
 tests/key-id/Makefile.in
 tests/libutils.la
 tests/mini
+tests/mini-loss
 tests/mini-deflate
 tests/mini-eagain
 tests/mini-eagain-dtls
@@ -582,3 +583,4 @@ tests/x509paths/
 tests/x509self
 tests/x509sign-verify
 tests/x509signself
+gl/tests/test-base64
diff --git a/configure.ac b/configure.ac
index 37f5458..b992f35 100644
--- a/configure.ac
+++ b/configure.ac
@@ -118,7 +118,7 @@ AC_C_BIGENDIAN
 
 
 dnl No fork on MinGW, disable some self-tests until we fix them.
-AC_CHECK_FUNCS([fork getrusage getpwuid_r],,)
+AC_CHECK_FUNCS([fork getrusage getpwuid_r daemon],,)
 AM_CONDITIONAL(HAVE_FORK, test "$ac_cv_func_fork" != "no")
 AC_LIB_HAVE_LINKFLAGS(pthread,, [#include <pthread.h>], [pthread_mutex_lock 
(0);])
 
@@ -376,6 +376,8 @@ dnl Crywrap dependencies
 *** Checking dependencies for crywrap...
 ])
 
+crywrap=no
+
 if test "$have_win" != "yes"; then
 
 AC_CHECK_HEADERS([arpa/inet.h netinet/in.h sys/select.h sys/types.h 
sys/wait.h])
@@ -400,11 +402,13 @@ AC_CHECK_FUNCS([alarm atexit dup2 epoll_create kqueue 
memchr memset munmap \
 
 PKG_CHECK_MODULES(LIBIDN, libidn >= 0.0.0, [libidn=yes], [libidn=no])
 
-else
-libidn=no
+ if test "x$libidn" != "xno" && test "$ac_cv_func_daemon" != "no";then
+  crywrap=yes
+ fi
+
 fi
 
-AM_CONDITIONAL(ENABLE_CRYWRAP, test "x$libidn" != "xno")
+AM_CONDITIONAL(ENABLE_CRYWRAP, test "x$crywrap" != "xno")
 rm -f suppressions.valgrind
 dnl end of crywrap requirements
 
diff --git a/gl/Makefile.am b/gl/Makefile.am
index 1da9139..e21e585 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=lock-tests --avoid=lseek-tests --no-conditional-dependencies --libtool 
--macro-prefix=gl --no-vc-files accept alloca alphasort argp base64 bind 
byteswap c-ctype close connect error extensions func gendocs getaddrinfo 
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 pmccabe2html progname read-file recv recvfrom scandir 
select send sendto setsockopt shutdown snprintf socket sockets socklen stdint 
strcase strtok_r 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=lock-tests --avoid=lseek-tests --no-conditional-dependencies --libtool 
--macro-prefix=gl --no-vc-files accept alloca alphasort argp base64 bind 
byteswap c-ctype close connect error extensions func gendocs getaddrinfo 
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 pmccabe2html progname read-file recv recvfrom scandir 
select send sendto setsockopt shutdown snprintf socket sockets socklen stdint 
strcase strndup strtok_r 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
 
@@ -2071,6 +2071,7 @@ sys/time.h: sys_time.in.h $(top_builddir)/config.status 
$(CXXDEFS_H) $(ARG_NONNU
              -e 's/@''HAVE_GETTIMEOFDAY''@/$(HAVE_GETTIMEOFDAY)/g' \
              -e 's/@''HAVE_STRUCT_TIMEVAL''@/$(HAVE_STRUCT_TIMEVAL)/g' \
              -e 's/@''REPLACE_GETTIMEOFDAY''@/$(REPLACE_GETTIMEOFDAY)/g' \
+             -e 's/@''REPLACE_STRUCT_TIMEVAL''@/$(REPLACE_STRUCT_TIMEVAL)/g' \
              -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
              -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
              -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
diff --git a/gl/argp-help.c b/gl/argp-help.c
index 6d2903e..a126acb 100644
--- a/gl/argp-help.c
+++ b/gl/argp-help.c
@@ -1,4 +1,4 @@
-/* Hierarchial argument parsing help output
+/* Hierarchical argument parsing help output
    Copyright (C) 1995-2005, 2007, 2009-2012 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Written by Miles Bader <address@hidden>.
@@ -154,7 +154,7 @@ ARGP_HELP_FMT: %s value is less than or equal to %s"),
   uparams.valid = 1;
 }
 
-/* Read user options from the environment, and fill in UPARAMS appropiately. */
+/* Read user options from the environment, and fill in UPARAMS appropriately. 
*/
 static void
 fill_in_uparams (const struct argp_state *state)
 {
@@ -277,11 +277,11 @@ fill_in_uparams (const struct argp_state *state)
      -xARG, -yARG, --long1=ARG, --long2=ARG        Documentation...
 
    Where ARG will be omitted if there's no argument, for this option, or
-   will be surrounded by "[" and "]" appropiately if the argument is
-   optional.  The documentation string is word-wrapped appropiately, and if
+   will be surrounded by "[" and "]" appropriately if the argument is
+   optional.  The documentation string is word-wrapped appropriately, and if
    the list of options is long enough, it will be started on a separate line.
    If there are no short options for a given option, the first long option is
-   indented slighly in a way that's supposed to make most long options appear
+   indented slightly in a way that's supposed to make most long options appear
    to be in a separate column.
 
    For example, the following output (from ps):
@@ -753,7 +753,7 @@ hol_entry_cmp (const struct hol_entry *entry1,
   if (entry1->cluster != entry2->cluster)
     {
       /* The entries are not within the same cluster, so we can't compare them
-         directly, we have to use the appropiate clustering level too.  */
+         directly, we have to use the appropriate clustering level too.  */
       if (! entry1->cluster)
         /* ENTRY1 is at the "base level", not in a cluster, so we have to
            compare it's group number with that of the base cluster in which
@@ -1023,7 +1023,7 @@ filter_doc (const char *doc, int key, const struct argp 
*argp,
     return doc;
 }
 
-/* Prints STR as a header line, with the margin lines set appropiately, and
+/* Prints STR as a header line, with the margin lines set appropriately, and
    notes the fact that groups should be separated with a blank line.  ARGP is
    the argp that should dictate any user doc filtering to take place.  Note
    that the previous wrap margin isn't restored, but the left margin is reset
@@ -1480,7 +1480,7 @@ argp_args_usage (const struct argp *argp, const struct 
argp_state *state,
 }
 
 /* Print the documentation for ARGP to STREAM; if POST is false, then
-   everything preceeding a '\v' character in the documentation strings (or
+   everything preceding a '\v' character in the documentation strings (or
    the whole string, for those with none) is printed, otherwise, everything
    following the '\v' character (nothing for strings without).  Each separate
    bit of documentation is separated a blank line, and if PRE_BLANK is true,
@@ -1579,7 +1579,7 @@ argp_doc (const struct argp *argp, const struct 
argp_state *state,
 }
 
 /* Output a usage message for ARGP to STREAM.  If called from
-   argp_state_help, STATE is the relevent parsing state.  FLAGS are from the
+   argp_state_help, STATE is the relevant parsing state.  FLAGS are from the
    set ARGP_HELP_*.  NAME is what to use wherever a "program name" is
    needed. */
 static void
diff --git a/gl/argp-parse.c b/gl/argp-parse.c
index 09558b4..3b411d4 100644
--- a/gl/argp-parse.c
+++ b/gl/argp-parse.c
@@ -1,4 +1,4 @@
-/* Hierarchial argument parsing, layered over getopt
+/* Hierarchical argument parsing, layered over getopt
    Copyright (C) 1995-2000, 2002-2004, 2009-2012 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Written by Miles Bader <address@hidden>.
@@ -204,7 +204,7 @@ struct group
      particular short options is from.  */
   char *short_end;
 
-  /* The number of non-option args sucessfully handled by this parser.  */
+  /* The number of non-option args successfully handled by this parser.  */
   unsigned args_processed;
 
   /* This group's parser's parent's group.  */
@@ -386,7 +386,7 @@ convert_options (const struct argp *argp,
   return group;
 }
 
-/* Find the merged set of getopt options, with keys appropiately prefixed. */
+/* Find the merged set of getopt options, with keys appropriately prefixed. */
 static void
 parser_convert (struct parser *parser, const struct argp *argp, int flags)
 {
diff --git a/gl/argp.h b/gl/argp.h
index f9f266e..c0c68a6 100644
--- a/gl/argp.h
+++ b/gl/argp.h
@@ -1,4 +1,4 @@
-/* Hierarchial argument parsing, layered over getopt.
+/* Hierarchical argument parsing, layered over getopt.
    Copyright (C) 1995-1999, 2003-2012 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Written by Miles Bader <address@hidden>.
@@ -278,7 +278,7 @@ struct argp
 };
 
 /* Possible KEY arguments to a help filter function.  */
-#define ARGP_KEY_HELP_PRE_DOC   0x2000001 /* Help text preceeding options. */
+#define ARGP_KEY_HELP_PRE_DOC   0x2000001 /* Help text preceding options. */
 #define ARGP_KEY_HELP_POST_DOC  0x2000002 /* Help text following options. */
 #define ARGP_KEY_HELP_HEADER    0x2000003 /* Option header string. */
 #define ARGP_KEY_HELP_EXTRA     0x2000004 /* After all other documentation;
@@ -506,7 +506,7 @@ extern void __argp_help (const struct argp *__restrict 
__argp,
    parsing routine (thus taking an argp_state structure as the first
    argument).  They may or may not print an error message and exit, depending
    on the flags in STATE -- in any case, the caller should be prepared for
-   them *not* to exit, and should return an appropiate error after calling
+   them *not* to exit, and should return an appropriate error after calling
    them.  [argp_usage & argp_error should probably be called argp_state_...,
    but they're used often enough that they should be short]  */
 
diff --git a/gl/base64.c b/gl/base64.c
index acf49c8..e1731b6 100644
--- a/gl/base64.c
+++ b/gl/base64.c
@@ -308,6 +308,24 @@ base64_decode_ctx_init (struct base64_decode_context *ctx)
   ctx->i = 0;
 }
 
+inline static int is_nl(char c)
+{
+  if (c == ' ' || c == '\t' || c == '\n' || c == '\r')
+    return 1;
+  return 0;
+}
+
+inline static int search_for_nl(char const *t, size_t t_size)
+{
+int i;
+
+  for (i=0;i<t_size;i++)
+    if (t[i] == ' ' || t[i] == '\t' || t[i] == '\n' || t[i] == '\r')
+      return 1;
+  
+  return 0;
+}
+
 /* If CTX->i is 0 or 4, there are four or more bytes in [*IN..IN_END), and
    none of those four is a newline, then return *IN.  Otherwise, copy up to
    4 - CTX->i non-newline bytes from that range into CTX->buf, starting at
@@ -326,7 +344,7 @@ get_4 (struct base64_decode_context *ctx,
   if (ctx->i == 0)
     {
       char const *t = *in;
-      if (4 <= in_end - *in && memchr (t, '\n', 4) == NULL)
+      if (4 <= in_end - *in && search_for_nl(t, 4) == 0)
         {
           /* This is the common case: no newline.  */
           *in += 4;
@@ -341,7 +359,7 @@ get_4 (struct base64_decode_context *ctx,
     while (p < in_end)
       {
         char c = *p++;
-        if (c != '\n')
+        if (!is_nl(c))
           {
             ctx->buf[ctx->i++] = c;
             if (ctx->i == 4)
@@ -494,7 +512,7 @@ base64_decode_ctx (struct base64_decode_context *ctx,
 
       /* Handle the common case of 72-byte wrapped lines.
          This also handles any other multiple-of-4-byte wrapping.  */
-      if (inlen && *in == '\n' && ignore_newlines)
+      if (inlen && is_nl(*in) && ignore_newlines)
         {
           ++in;
           --inlen;
diff --git a/gl/fseeko.c b/gl/fseeko.c
index eae1b72..08e1f71 100644
--- a/gl/fseeko.c
+++ b/gl/fseeko.c
@@ -89,6 +89,9 @@ fseeko (FILE *fp, off_t offset, int whence)
       && fp->__get_limit == fp->__bufp
       && fp->__put_limit == fp->__bufp
       && !fp->__pushed_back)
+#elif defined EPLAN9                /* Plan9 */
+  if (fp->rp == fp->buf
+      && fp->wp == fp->buf)
 #else
   #error "Please port gnulib fseeko.c to your platform! Look at the code in 
fpurge.c, then report this to bug-gnulib."
 #endif
diff --git a/gl/fseterr.c b/gl/fseterr.c
index 30b41e1..78791af 100644
--- a/gl/fseterr.c
+++ b/gl/fseterr.c
@@ -45,6 +45,9 @@ fseterr (FILE *fp)
   fp->_Mode |= 0x200 /* _MERR */;
 #elif defined __MINT__              /* Atari FreeMiNT */
   fp->__error = 1;
+#elif defined EPLAN9                /* Plan9 */
+  if (fp->state != 0 /* CLOSED */)
+    fp->state = 5 /* ERR */;
 #elif 0                             /* unknown  */
   /* Portable fallback, based on an idea by Rich Felker.
      Wow! 6 system calls for something that is just a bit operation!
diff --git a/gl/gettimeofday.c b/gl/gettimeofday.c
index 3c0fdd9..d18606a 100644
--- a/gl/gettimeofday.c
+++ b/gl/gettimeofday.c
@@ -110,7 +110,18 @@ gettimeofday (struct timeval *restrict tv, void *restrict 
tz)
   struct tm save = *localtime_buffer_addr;
 # endif
 
+# if defined timeval /* 'struct timeval' overridden by gnulib?  */
+#  undef timeval
+  struct timeval otv;
+  int result = gettimeofday (&otv, (struct timezone *) tz);
+  if (result == 0)
+    {
+      tv->tv_sec = otv.tv_sec;
+      tv->tv_usec = otv.tv_usec;
+    }
+# else
   int result = gettimeofday (tv, (struct timezone *) tz);
+# endif
 
 # if GETTIMEOFDAY_CLOBBERS_LOCALTIME
   *localtime_buffer_addr = save;
diff --git a/gl/m4/exponentd.m4 b/gl/m4/exponentd.m4
index 48df999..0ae4ccf 100644
--- a/gl/m4/exponentd.m4
+++ b/gl/m4/exponentd.m4
@@ -1,4 +1,4 @@
-# exponentd.m4 serial 2
+# exponentd.m4 serial 3
 dnl Copyright (C) 2007-2008, 2010-2012 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -80,7 +80,8 @@ int main ()
           dnl different sets of instructions: The older FPA instructions assume
           dnl that they are stored in big-endian word order, while the words
           dnl (like integer types) are stored in little-endian byte order.
-          dnl The newer VFP instructions assume little-endian order 
consistenly.
+          dnl The newer VFP instructions assume little-endian order
+          dnl consistently.
           AC_EGREP_CPP([mixed_endianness], [
 #if defined arm || defined __arm || defined __arm__
   mixed_endianness
diff --git a/gl/m4/gettimeofday.m4 b/gl/m4/gettimeofday.m4
index 2385e39..dc68c43 100644
--- a/gl/m4/gettimeofday.m4
+++ b/gl/m4/gettimeofday.m4
@@ -1,4 +1,4 @@
-# serial 17
+# serial 18
 
 # Copyright (C) 2001-2003, 2005, 2007, 2009-2012 Free Software Foundation, Inc.
 # This file is free software; the Free Software Foundation
@@ -50,6 +50,10 @@ int gettimeofday (struct timeval *restrict, struct timezone 
*restrict);
     elif test $gl_cv_func_gettimeofday_posix_signature != yes; then
       REPLACE_GETTIMEOFDAY=1
     fi
+    dnl If we override 'struct timeval', we also have to override gettimeofday.
+    if test $REPLACE_STRUCT_TIMEVAL = 1; then
+      REPLACE_GETTIMEOFDAY=1
+    fi
     m4_ifdef([gl_FUNC_TZSET_CLOBBER], [
       gl_FUNC_TZSET_CLOBBER
       if test $gl_cv_func_tzset_clobber = yes; then
diff --git a/gl/m4/gnulib-cache.m4 b/gl/m4/gnulib-cache.m4
index 4c81916..0e41084 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=lock-tests 
--avoid=lseek-tests --no-conditional-dependencies --libtool --macro-prefix=gl 
--no-vc-files accept alloca alphasort argp base64 bind byteswap c-ctype close 
connect error extensions func gendocs getaddrinfo 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 
pmccabe2html progname read-file recv recvfrom scandir select send sendto 
setsockopt shutdown snprintf socket sockets socklen stdint strcase strtok_r 
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=lock-tests 
--avoid=lseek-tests --no-conditional-dependencies --libtool --macro-prefix=gl 
--no-vc-files accept alloca alphasort argp base64 bind byteswap c-ctype close 
connect error extensions func gendocs getaddrinfo 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 
pmccabe2html progname read-file recv recvfrom scandir select send sendto 
setsockopt shutdown snprintf socket sockets socklen stdint strcase strndup 
strtok_r 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])
@@ -80,6 +80,7 @@ gl_MODULES([
   socklen
   stdint
   strcase
+  strndup
   strtok_r
   strverscmp
   sys_socket
diff --git a/gl/m4/po.m4 b/gl/m4/po.m4
index 6bf122a..05d8f7b 100644
--- a/gl/m4/po.m4
+++ b/gl/m4/po.m4
@@ -1,4 +1,4 @@
-# po.m4 serial 17a
+# po.m4 serial 17b
 dnl Copyright (C) 1995-2012 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -130,12 +130,12 @@ changequote([,])dnl
               test -n "$as_me" && echo "$as_me: setting ALL_LINGUAS in 
configure.in is obsolete" || echo "setting ALL_LINGUAS in configure.in is 
obsolete"
             fi
             ALL_LINGUAS_=`sed -e "/^#/d" -e "s/#.*//" 
"$ac_given_srcdir/$ac_dir/LINGUAS"`
-            # Hide the ALL_LINGUAS assigment from automake < 1.5.
+            # Hide the ALL_LINGUAS assignment from automake < 1.5.
             eval 'ALL_LINGUAS''=$ALL_LINGUAS_'
             POMAKEFILEDEPS="$POMAKEFILEDEPS LINGUAS"
           else
             # The set of available languages was given in configure.in.
-            # Hide the ALL_LINGUAS assigment from automake < 1.5.
+            # Hide the ALL_LINGUAS assignment from automake < 1.5.
             eval 'ALL_LINGUAS''=$OBSOLETE_ALL_LINGUAS'
           fi
           # Compute POFILES
@@ -317,7 +317,7 @@ changequote([,])dnl
     sed_x_LINGUAS=`$gt_echo "$sed_x_variable" | sed -e '/^ *#/d' -e 
's/VARIABLE/LINGUAS/g'`
     ALL_LINGUAS_=`sed -n -e "$sed_x_LINGUAS" < "$ac_file"`
   fi
-  # Hide the ALL_LINGUAS assigment from automake < 1.5.
+  # Hide the ALL_LINGUAS assignment from automake < 1.5.
   eval 'ALL_LINGUAS''=$ALL_LINGUAS_'
   # Compute POFILES
   # as      $(foreach lang, $(ALL_LINGUAS), $(srcdir)/$(lang).po)
diff --git a/gl/m4/stdalign.m4 b/gl/m4/stdalign.m4
index d78a589..6659c9c 100644
--- a/gl/m4/stdalign.m4
+++ b/gl/m4/stdalign.m4
@@ -25,15 +25,16 @@ AC_DEFUN([gl_STDALIGN_H],
             #else
             # define ao(type) offsetof (struct { char a; type b; }, b)
             #endif
-            char test1[_Alignof (double) == ao (double) ? 1 : -1];
-            char test2[alignof (long int) == ao (long int) ? 1 : -1];
+            char test_double[ao (double) % _Alignof (double) == 0 ? 1 : -1];
+            char test_long[ao (long int) % _Alignof (long int) == 0 ? 1 : -1];
+            char test_alignof[alignof (double) == _Alignof (double) ? 1 : -1];
 
             /* Test _Alignas only on platforms where gnulib can help.  */
             #if \
                 (__GNUC__ || __IBMC__ || __IBMCPP__ \
                  || 0x5110 <= __SUNPRO_C || 1300 <= _MSC_VER)
               int alignas (8) alignas_int = 1;
-              char test3[8 <= _Alignof (alignas_int) ? 1 : -1];
+              char test_alignas[_Alignof (alignas_int) == 8 ? 1 : -1];
             #endif
           ]])],
        [gl_cv_header_working_stdalign_h=yes],
diff --git a/gl/m4/sys_time_h.m4 b/gl/m4/sys_time_h.m4
index bed3797..26eaf8e 100644
--- a/gl/m4/sys_time_h.m4
+++ b/gl/m4/sys_time_h.m4
@@ -1,5 +1,5 @@
 # Configure a replacement for <sys/time.h>.
-# serial 7
+# serial 8
 
 # Copyright (C) 2007, 2009-2012 Free Software Foundation, Inc.
 # This file is free software; the Free Software Foundation
@@ -43,9 +43,36 @@ AC_DEFUN([gl_HEADER_SYS_TIME_H_BODY],
           ]],
           [[static struct timeval x; x.tv_sec = x.tv_usec;]])],
        [gl_cv_sys_struct_timeval=yes],
-       [gl_cv_sys_struct_timeval=no])])
+       [gl_cv_sys_struct_timeval=no])
+    ])
   if test $gl_cv_sys_struct_timeval != yes; then
     HAVE_STRUCT_TIMEVAL=0
+  else
+    dnl On native Windows with a 64-bit 'time_t', 'struct timeval' is defined
+    dnl (in <sys/time.h> and <winsock2.h> for mingw64, in <winsock2.h> only
+    dnl for MSVC) with a tv_sec field of type 'long' (32-bit!), which is
+    dnl smaller than the 'time_t' type mandated by POSIX.
+    AC_CACHE_CHECK([for correct struct timeval.tv_sec member],
+      [gl_cv_sys_struct_timeval_tv_sec],
+      [AC_COMPILE_IFELSE(
+         [AC_LANG_PROGRAM(
+            [[#if HAVE_SYS_TIME_H
+               #include <sys/time.h>
+              #endif
+              #include <time.h>
+              #if HAVE_WINSOCK2_H
+              # include <winsock2.h>
+              #endif
+            ]],
+            [[static struct timeval x;
+              typedef int verify_tv_sec_type[sizeof (x.tv_sec) == sizeof 
(time_t) ? 1 : -1];
+            ]])],
+         [gl_cv_sys_struct_timeval_tv_sec=yes],
+         [gl_cv_sys_struct_timeval_tv_sec=no])
+      ])
+    if test $gl_cv_sys_struct_timeval_tv_sec != yes; then
+      REPLACE_STRUCT_TIMEVAL=1
+    fi
   fi
 
   dnl Check for declarations of anything we want to poison if the
@@ -75,4 +102,5 @@ AC_DEFUN([gl_HEADER_SYS_TIME_H_DEFAULTS],
   HAVE_STRUCT_TIMEVAL=1;     AC_SUBST([HAVE_STRUCT_TIMEVAL])
   HAVE_SYS_TIME_H=1;         AC_SUBST([HAVE_SYS_TIME_H])
   REPLACE_GETTIMEOFDAY=0;    AC_SUBST([REPLACE_GETTIMEOFDAY])
+  REPLACE_STRUCT_TIMEVAL=0;  AC_SUBST([REPLACE_STRUCT_TIMEVAL])
 ])
diff --git a/gl/m4/vasnprintf.m4 b/gl/m4/vasnprintf.m4
index 61fe499..0ce11da 100644
--- a/gl/m4/vasnprintf.m4
+++ b/gl/m4/vasnprintf.m4
@@ -1,4 +1,4 @@
-# vasnprintf.m4 serial 34
+# vasnprintf.m4 serial 35
 dnl Copyright (C) 2002-2004, 2006-2012 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -29,7 +29,7 @@ AC_DEFUN([gl_REPLACE_VASNPRINTF],
   gl_PREREQ_ASNPRINTF
 ])
 
-# Prequisites of lib/printf-args.h, lib/printf-args.c.
+# Prerequisites of lib/printf-args.h, lib/printf-args.c.
 AC_DEFUN([gl_PREREQ_PRINTF_ARGS],
 [
   AC_REQUIRE([AC_TYPE_LONG_LONG_INT])
@@ -37,7 +37,7 @@ AC_DEFUN([gl_PREREQ_PRINTF_ARGS],
   AC_REQUIRE([gt_TYPE_WINT_T])
 ])
 
-# Prequisites of lib/printf-parse.h, lib/printf-parse.c.
+# Prerequisites of lib/printf-parse.h, lib/printf-parse.c.
 AC_DEFUN([gl_PREREQ_PRINTF_PARSE],
 [
   AC_REQUIRE([gl_FEATURES_H])
diff --git a/gl/select.c b/gl/select.c
index e933094..0c821dd 100644
--- a/gl/select.c
+++ b/gl/select.c
@@ -37,8 +37,13 @@
 #include <conio.h>
 #include <time.h>
 
+/* Get the overridden 'struct timeval'.  */
+#include <sys/time.h>
+
 #include "msvc-nothrow.h"
 
+#undef select
+
 struct bitset {
   unsigned char in[FD_SETSIZE / CHAR_BIT];
   unsigned char out[FD_SETSIZE / CHAR_BIT];
@@ -80,7 +85,7 @@ typedef DWORD (WINAPI *PNtQueryInformationFile)
 
 /* Optimized test whether a HANDLE refers to a console.
    See <http://lists.gnu.org/archive/html/bug-gnulib/2009-08/msg00065.html>.  
*/
-#define IsConsoleHandle(h) (((long) (h) & 3) == 3)
+#define IsConsoleHandle(h) (((intptr_t) (h) & 3) == 3)
 
 static BOOL
 IsSocketHandle (HANDLE h)
@@ -237,6 +242,7 @@ windows_poll_handle (HANDLE h, int fd,
 int
 rpl_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *xfds,
             struct timeval *timeout)
+#undef timeval
 {
   static struct timeval tv0;
   static HANDLE hEvent;
diff --git a/gl/sleep.c b/gl/sleep.c
index e5d3299..9a4b940 100644
--- a/gl/sleep.c
+++ b/gl/sleep.c
@@ -35,7 +35,7 @@ sleep (unsigned int seconds)
   unsigned int remaining;
 
   /* Sleep for 1 second many times, because
-       1. Sleep is not interruptiple by Ctrl-C,
+       1. Sleep is not interruptible by Ctrl-C,
        2. we want to avoid arithmetic overflow while multiplying with 1000.  */
   for (remaining = seconds; remaining > 0; remaining--)
     Sleep (1000);
diff --git a/gl/stdio-impl.h b/gl/stdio-impl.h
index a065c1a..4935795 100644
--- a/gl/stdio-impl.h
+++ b/gl/stdio-impl.h
@@ -26,6 +26,8 @@
 # include <sys/param.h>
 #endif
 
+#include <errno.h>                             /* For detecting Plan9.  */
+
 #if defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, 
DragonFly, MacOS X, Cygwin */
 
 # if defined __DragonFly__          /* DragonFly */
diff --git a/gl/stdio.in.h b/gl/stdio.in.h
index 0481930..06d9780 100644
--- a/gl/stdio.in.h
+++ b/gl/stdio.in.h
@@ -779,7 +779,7 @@ _GL_CXXALIASWARN (pclose);
 #elif defined GNULIB_POSIXCHECK
 # undef pclose
 # if HAVE_RAW_DECL_PCLOSE
-_GL_WARN_ON_USE (pclose, "popen is unportable - "
+_GL_WARN_ON_USE (pclose, "pclose is unportable - "
                  "use gnulib module pclose for more portability");
 # endif
 #endif
diff --git a/gl/sys_select.in.h b/gl/sys_select.in.h
index 5f93fb1..4b35d19 100644
--- a/gl/sys_select.in.h
+++ b/gl/sys_select.in.h
@@ -42,6 +42,15 @@
 # define _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_BSD_TYPES_H
 # @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
 
+/* On OpenBSD 5.0, <pthread.h> includes <sys/types.h>, which includes
+   <sys/select.h>.  At this point we cannot include <signal.h>, because that
+   includes gnulib's pthread.h override, which gives a syntax error because
+   /usr/include/pthread.h has not been completely processed.  Simply delegate
+   to the system's header in this case.  */
+#elif @HAVE_SYS_SELECT_H@ && defined __OpenBSD__ && (defined _PTHREAD_H_ && 
!defined PTHREAD_MUTEX_INITIALIZER)
+
+# @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
+
 #else
 
 #ifndef address@hidden@_SYS_SELECT_H
@@ -51,12 +60,6 @@
    in <signal.h> where it belongs.  */
 #include <sys/types.h>
 
-/* Get definition of 'sigset_t'.
-   But avoid namespace pollution on glibc systems.  */
-#if !(defined __GLIBC__ && !defined __UCLIBC__)
-# include <signal.h>
-#endif
-
 #if @HAVE_SYS_SELECT_H@
 
 /* On OSF/1 4.0, <sys/select.h> provides only a forward declaration
@@ -81,6 +84,14 @@
 
 #endif
 
+/* Get definition of 'sigset_t'.
+   But avoid namespace pollution on glibc systems.
+   Do this after the include_next (for the sake of OpenBSD 5.0) but before
+   the split double-inclusion guard (for the sake of Solaris).  */
+#if !(defined __GLIBC__ && !defined __UCLIBC__)
+# include <signal.h>
+#endif
+
 #ifndef address@hidden@_SYS_SELECT_H
 #define address@hidden@_SYS_SELECT_H
 
diff --git a/gl/sys_socket.in.h b/gl/sys_socket.in.h
index 49b61de..819aff1 100644
--- a/gl/sys_socket.in.h
+++ b/gl/sys_socket.in.h
@@ -143,7 +143,7 @@ struct sockaddr_storage
    that you can influence which definitions you get by setting the
    WINVER symbol before including these two files.  For example,
    getaddrinfo is only available if _WIN32_WINNT >= 0x0501 (that
-   symbol is set indiriectly through WINVER).  You can set this by
+   symbol is set indirectly through WINVER).  You can set this by
    adding AC_DEFINE(WINVER, 0x0501) to configure.ac.  Note that your
    code may not run on older Windows releases then.  My Windows 2000
    box was not able to run the code, for example.  The situation is
diff --git a/gl/sys_stat.in.h b/gl/sys_stat.in.h
index 44b6a1b..6d159f0 100644
--- a/gl/sys_stat.in.h
+++ b/gl/sys_stat.in.h
@@ -616,14 +616,33 @@ _GL_WARN_ON_USE (mknodat, "mknodat is not portable - "
 /* We can't use the object-like #define stat rpl_stat, because of
    struct stat.  This means that rpl_stat will not be used if the user
    does (stat)(a,b).  Oh well.  */
-#  undef stat
-#  ifdef _LARGE_FILES
+#  if defined _AIX && defined stat && defined _LARGE_FILES
     /* With _LARGE_FILES defined, AIX (only) defines stat to stat64,
        so we have to replace stat64() instead of stat(). */
-#   define stat stat64
 #   undef stat64
 #   define stat64(name, st) rpl_stat (name, st)
-#  else /* !_LARGE_FILES */
+#  elif defined __MINGW32__ && defined stat
+#   ifdef _USE_32BIT_TIME_T
+     /* The system headers define stat to _stat32i64.  */
+#    undef _stat32i64
+#    define _stat32i64(name, st) rpl_stat (name, st)
+#   else
+     /* The system headers define stat to _stat64.  */
+#    undef _stat64
+#    define _stat64(name, st) rpl_stat (name, st)
+#   endif
+#  elif defined _MSC_VER && defined stat
+#   ifdef _USE_32BIT_TIME_T
+     /* The system headers define stat to _stat32.  */
+#    undef _stat32
+#    define _stat32(name, st) rpl_stat (name, st)
+#   else
+     /* The system headers define stat to _stat64i32.  */
+#    undef _stat64i32
+#    define _stat64i32(name, st) rpl_stat (name, st)
+#   endif
+#  else /* !(_AIX ||__MINGW32__ ||  _MSC_VER) */
+#   undef stat
 #   define stat(name, st) rpl_stat (name, st)
 #  endif /* !_LARGE_FILES */
 _GL_EXTERN_C int stat (const char *name, struct stat *buf)
diff --git a/gl/sys_time.in.h b/gl/sys_time.in.h
index c9ee565..ee86ccc 100644
--- a/gl/sys_time.in.h
+++ b/gl/sys_time.in.h
@@ -40,9 +40,11 @@
 #  include <time.h>
 # endif
 
-/* On native Windows with MSVC:
-   Get the 'struct timeval' type.  */
-# if defined _MSC_VER && @HAVE_WINSOCK2_H@ && !defined _GL_INCLUDING_WINSOCK2_H
+/* On native Windows with MSVC, get the 'struct timeval' type.
+   Also, on native Windows with a 64-bit time_t, where we are overriding the
+   'struct timeval' type, get all declarations of system functions whose
+   signature contains 'struct timeval'.  */
+# if (defined _MSC_VER || @REPLACE_STRUCT_TIMEVAL@) && @HAVE_WINSOCK2_H@ && 
!defined _GL_INCLUDING_WINSOCK2_H
 #  define _GL_INCLUDING_WINSOCK2_H
 #  include <winsock2.h>
 #  undef _GL_INCLUDING_WINSOCK2_H
@@ -58,7 +60,11 @@
 extern "C" {
 # endif
 
-# if ! @HAVE_STRUCT_TIMEVAL@
+# if address@hidden@ || @REPLACE_STRUCT_TIMEVAL@
+
+#  if @REPLACE_STRUCT_TIMEVAL@
+#   define timeval rpl_timeval
+#  endif
 
 #  if !GNULIB_defined_struct_timeval
 struct timeval
diff --git a/gl/tests/init.sh b/gl/tests/init.sh
index 5985552..ae86714 100644
--- a/gl/tests/init.sh
+++ b/gl/tests/init.sh
@@ -255,7 +255,10 @@ compare_dev_null_ ()
   return 2
 }
 
-if diff_out_=`exec 2>/dev/null; diff -u "$0" "$0" < /dev/null`; then
+if diff_out_=`exec 2>/dev/null; diff -u "$0" "$0" < /dev/null` \
+   && diff -u Makefile "$0" 2>/dev/null | grep '^[+]#!' >/dev/null; then
+  # diff accepts the -u option and does not (like AIX 7 'diff') produce an
+  # extra space on column 1 of every content line.
   if test -z "$diff_out_"; then
     compare_ () { diff -u "$@"; }
   else
diff --git a/gl/tests/ioctl.c b/gl/tests/ioctl.c
index 8701b7a..2e51c92 100644
--- a/gl/tests/ioctl.c
+++ b/gl/tests/ioctl.c
@@ -47,6 +47,8 @@ rpl_ioctl (int fd, int request, ... /* {void *,char *} arg */)
 # include <errno.h>
 
 # include "fd-hook.h"
+/* Get _get_osfhandle.  */
+# include "msvc-nothrow.h"
 
 static int
 primary_ioctl (int fd, int request, void *arg)
@@ -55,7 +57,10 @@ primary_ioctl (int fd, int request, void *arg)
      fds non-blocking, use the gnulib 'nonblocking' module, until
      gnulib implements fcntl F_GETFL / F_SETFL with O_NONBLOCK.  */
 
-  errno = ENOSYS;
+  if ((HANDLE) _get_osfhandle (fd) != INVALID_HANDLE_VALUE)
+    errno = ENOSYS;
+  else
+    errno = EBADF;
   return -1;
 }
 
diff --git a/gl/tests/test-base64.c b/gl/tests/test-base64.c
index 9a533c5..a71ffba 100644
--- a/gl/tests/test-base64.c
+++ b/gl/tests/test-base64.c
@@ -153,7 +153,7 @@ main (void)
 
   {
     struct base64_decode_context ctx;
-    const char *newlineb64 = "YWJjZG\nVmZ2hp\namtsbW5vcA==";
+    const char *newlineb64 = "YWJjZG\nVmZ2hp\r\n\tamtsbW5vcA==";
 
     base64_decode_ctx_init (&ctx);
 
@@ -168,7 +168,7 @@ main (void)
     struct base64_decode_context ctx;
     base64_decode_ctx_init (&ctx);
 
-    ok = base64_decode_alloc_ctx (&ctx, "YW\nJjZGVmZ2hp", 13, &p, &len);
+    ok = base64_decode_alloc_ctx (&ctx, "YW\n JjZGVmZ2hp", 14, &p, &len);
     ASSERT (ok);
     ASSERT (len == 9);
     ASSERT (memcmp (p, "abcdefghi", len) == 0);
diff --git a/gl/tests/test-init.sh b/gl/tests/test-init.sh
index c644609..a2825cc 100755
--- a/gl/tests/test-init.sh
+++ b/gl/tests/test-init.sh
@@ -50,20 +50,19 @@ EOF
   case $- in *x*) ;; *) test -s err && fail_ "err not empty: $(cat err)";; esac
 
   compare empty in >out 2>err && fail=1
-  # Remove the TAB-date suffix on each --- and +++ line,
-  # for both the expected and the actual output files.
-  # Also remove the @@ line, since Solaris 5.10 and GNU diff formats differ:
-  # -@@ -0,0 +1 @@
-  # +@@ -1,0 +1,1 @@
-  cat <<\EOF > exp
+  # Compare against expected output only if compare is using diff -u.
+  if grep @ out >/dev/null; then
+    # Remove the TAB-date suffix on each --- and +++ line,
+    # for both the expected and the actual output files.
+    # Also remove the @@ line, since Solaris 5.10 and GNU diff formats differ:
+    # -@@ -0,0 +1 @@
+    # +@@ -1,0 +1,1 @@
+    sed 's/    .*//;/^@@/d' out > k && mv k out
+    cat <<\EOF > exp
 --- empty
 +++ in
 +xyz
 EOF
-  sed 's/      .*//;/^@@/d' out > k && mv k out
-
-  # Compare against expected output only if compare is using diff -u.
-  if diff -u out out < /dev/null > /dev/null 2>&1; then
     compare exp out || fail=1
   fi
   case $- in *x*) ;; *) test -s err && fail_ "err not empty: $(cat err)";; esac
diff --git a/gl/tests/test-strerror.c b/gl/tests/test-strerror.c
index a40c079..14673f2 100644
--- a/gl/tests/test-strerror.c
+++ b/gl/tests/test-strerror.c
@@ -64,7 +64,7 @@ main (void)
   ASSERT (strstr (str, "ndefined") == NULL);
 
   /* POSIX requires strerror to produce a non-NULL result for all
-     inputs; as an extension, we also guarantee a non-empty reseult.
+     inputs; as an extension, we also guarantee a non-empty result.
      Reporting EINVAL is optional.  */
   errno = 0;
   str = strerror (-3);
diff --git a/gl/tests/test-sys_select.c b/gl/tests/test-sys_select.c
index a473eba..78f66ed 100644
--- a/gl/tests/test-sys_select.c
+++ b/gl/tests/test-sys_select.c
@@ -38,7 +38,10 @@ SIGNATURE_CHECK (FD_ZERO, void, (fd_set *));
 #endif
 
 /* Check that the 'struct timeval' type is defined.  */
-struct timeval t1;
+struct timeval a;
+
+/* Check that &a.tv_sec is a 'time_t *', ignoring signedness issues.  */
+typedef int verify_tv_sec_type[sizeof (a.tv_sec) == sizeof (time_t) ? 1 : -1];
 
 /* Check that sigset_t is defined.  */
 sigset_t t2;
diff --git a/gl/tests/test-sys_time.c b/gl/tests/test-sys_time.c
index a9ac5e3..44e21a2 100644
--- a/gl/tests/test-sys_time.c
+++ b/gl/tests/test-sys_time.c
@@ -20,8 +20,12 @@
 
 #include <sys/time.h>
 
+/* Check that the 'struct timeval' type is defined.  */
 struct timeval a;
 
+/* Check that &a.tv_sec is a 'time_t *', ignoring signedness issues.  */
+typedef int verify_tv_sec_type[sizeof (a.tv_sec) == sizeof (time_t) ? 1 : -1];
+
 int
 main (void)
 {
diff --git a/gl/tests/w32sock.h b/gl/tests/w32sock.h
index 846c342..ef0b593 100644
--- a/gl/tests/w32sock.h
+++ b/gl/tests/w32sock.h
@@ -1,4 +1,4 @@
-/* w32sock.h --- internal auxilliary functions for Windows socket functions
+/* w32sock.h --- internal auxiliary functions for Windows socket functions
 
    Copyright (C) 2008-2012 Free Software Foundation, Inc.
 
@@ -29,7 +29,7 @@
 #include "msvc-nothrow.h"
 
 #define FD_TO_SOCKET(fd)   ((SOCKET) _get_osfhandle ((fd)))
-#define SOCKET_TO_FD(fh)   (_open_osfhandle ((long) (fh), O_RDWR | O_BINARY))
+#define SOCKET_TO_FD(fh)   (_open_osfhandle ((intptr_t) (fh), O_RDWR | 
O_BINARY))
 
 static inline void
 set_winsock_errno (void)
diff --git a/gl/vasnprintf.c b/gl/vasnprintf.c
index 16fca49..297eb20 100644
--- a/gl/vasnprintf.c
+++ b/gl/vasnprintf.c
@@ -2814,7 +2814,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                   if (has_width)
                     {
 #  if ENABLE_UNISTDIO
-                      /* Outside POSIX, it's preferrable to compare the width
+                      /* Outside POSIX, it's preferable to compare the width
                          against the number of _characters_ of the converted
                          value.  */
                       w = DCHAR_MBSNLEN (result + length, characters);
@@ -5417,7 +5417,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                       {
                         size_t w;
 # if ENABLE_UNISTDIO
-                        /* Outside POSIX, it's preferrable to compare the width
+                        /* Outside POSIX, it's preferable to compare the width
                            against the number of _characters_ of the converted
                            value.  */
                         w = DCHAR_MBSNLEN (result + length, count);
diff --git a/gl/version-etc.h b/gl/version-etc.h
index c62704c..5548c02 100644
--- a/gl/version-etc.h
+++ b/gl/version-etc.h
@@ -37,7 +37,7 @@ extern const char version_etc_copyright[];
    standard way: command and package names, package version, followed
    by a short GPLv3+ notice and a list of up to 10 author names.
 
-   If COMMAND_NAME is NULL, the PACKAGE is asumed to be the name of
+   If COMMAND_NAME is NULL, the PACKAGE is assumed to be the name of
    the program.  The formats are therefore:
 
    PACKAGE VERSION
diff --git a/gl/w32sock.h b/gl/w32sock.h
index 846c342..ef0b593 100644
--- a/gl/w32sock.h
+++ b/gl/w32sock.h
@@ -1,4 +1,4 @@
-/* w32sock.h --- internal auxilliary functions for Windows socket functions
+/* w32sock.h --- internal auxiliary functions for Windows socket functions
 
    Copyright (C) 2008-2012 Free Software Foundation, Inc.
 
@@ -29,7 +29,7 @@
 #include "msvc-nothrow.h"
 
 #define FD_TO_SOCKET(fd)   ((SOCKET) _get_osfhandle ((fd)))
-#define SOCKET_TO_FD(fh)   (_open_osfhandle ((long) (fh), O_RDWR | O_BINARY))
+#define SOCKET_TO_FD(fh)   (_open_osfhandle ((intptr_t) (fh), O_RDWR | 
O_BINARY))
 
 static inline void
 set_winsock_errno (void)
diff --git a/lib/debug.c b/lib/debug.c
index fc350f3..1e5b0c6 100644
--- a/lib/debug.c
+++ b/lib/debug.c
@@ -49,7 +49,7 @@ _gnutls_packet2str (content_type_t packet)
   switch (packet)
     {
     case GNUTLS_CHANGE_CIPHER_SPEC:
-      return "Change Cipher Spec";
+      return "ChangeCipherSpec";
     case GNUTLS_ALERT:
       return "Alert";
     case GNUTLS_HANDSHAKE:
diff --git a/lib/gnutls_buffers.c b/lib/gnutls_buffers.c
index 7cbd635..b896c1a 100644
--- a/lib/gnutls_buffers.c
+++ b/lib/gnutls_buffers.c
@@ -51,6 +51,7 @@
 #include <gnutls_constate.h> /* gnutls_epoch_get */
 #include <errno.h>
 #include <system.h>
+#include "debug.h"
 
 #ifndef EAGAIN
 #define EAGAIN EWOULDBLOCK
@@ -600,7 +601,6 @@ _gnutls_io_write_flush (gnutls_session_t session)
   return sent;
 }
 
-#include "debug.h"
 /* Checks whether there are received data within
  * a timeframe.
  *
@@ -960,16 +960,7 @@ handshake_buffer_st* recv_buf = 
session->internals.handshake_recv_buffer;
     }
 
 timeout:
-  if (gnutls_time(0) - session->internals.dtls.handshake_start_time >
-      session->internals.dtls.total_timeout_ms/1000) 
-    return gnutls_assert_val(GNUTLS_E_TIMEDOUT);
-  else
-    {
-      if (session->internals.dtls.blocking != 0)
-        millisleep(50);
-        
-      return gnutls_assert_val(GNUTLS_E_AGAIN);
-    }
+  RETURN_DTLS_EAGAIN_OR_TIMEOUT(session);
 }
 
 /* This is a receive function for the gnutls handshake 
diff --git a/lib/gnutls_dtls.c b/lib/gnutls_dtls.c
index 5c6c333..316897e 100644
--- a/lib/gnutls_dtls.c
+++ b/lib/gnutls_dtls.c
@@ -179,6 +179,7 @@ int ret;
    * non blocking way, check if it is time to retransmit or just
    * return.
    */
+
   if (session->internals.dtls.flight_init != 0 && 
session->internals.dtls.blocking == 0)
     {
       /* just in case previous run was interrupted */
@@ -205,11 +206,8 @@ int ret;
               goto cleanup;
             }
         }
-      else
-        return ret;
     }
 
-
   do 
     {
       if (now-session->internals.dtls.handshake_start_time >= 
session->internals.dtls.total_timeout_ms/1000) 
@@ -233,7 +231,7 @@ int ret;
           session->internals.dtls.handshake_last_call = now;
           session->internals.dtls.actual_retrans_timeout_ms = 
session->internals.dtls.retrans_timeout_ms;
 
-          if (last_type == GNUTLS_HANDSHAKE_FINISHED && 
_dtls_is_async(session))
+          if (last_type == GNUTLS_HANDSHAKE_FINISHED)
             {
               /* we cannot do anything here. We just return 0 and
                * if a retransmission occurs because peer didn't receive it
@@ -243,8 +241,6 @@ int ret;
             }
           else
             session->internals.dtls.last_flight = 0;
-
-
         }
 
       ret = _gnutls_io_write_flush (session);
@@ -252,7 +248,7 @@ int ret;
         return gnutls_assert_val(ret);
 
       /* last message in handshake -> no ack */
-      if (session->internals.dtls.last_flight != 0)
+      if (session->internals.dtls.last_flight != 0 && _dtls_is_async(session))
         {
           /* we cannot do anything here. We just return 0 and
            * if a retransmission occurs because peer didn't receive it
@@ -298,7 +294,7 @@ cleanup:
   return ret;
 
 nb_timeout:
-    return GNUTLS_E_AGAIN;
+  RETURN_DTLS_EAGAIN_OR_TIMEOUT(session);
 }
 
 #define window_table session->internals.dtls.record_sw
@@ -321,12 +317,13 @@ static void rot_window(gnutls_session_t session, int 
places)
 int _dtls_record_check(gnutls_session_t session, uint64 * _seq)
 {
 uint64_t seq = 0, diff;
-int i, offset = 0;
+unsigned int i, offset = 0;
 
-  for (i=0;i<8;i++) 
+  seq |= _seq->i[0] & 0xff;
+  for (i=1;i<8;i++) 
     {
-      seq |= _seq->i[i];
       seq <<= 8;
+      seq |= _seq->i[i] & 0xff;
     }
 
   if (window_size == 0)
@@ -341,9 +338,10 @@ int i, offset = 0;
       return -1;
     }
 
-  if (window_size == DTLS_RECORD_WINDOW_SIZE) {
-    rot_window(session, MOVE_SIZE);
-  }
+  if (window_size == DTLS_RECORD_WINDOW_SIZE) 
+    {
+      rot_window(session, MOVE_SIZE);
+    }
 
   if (seq < window_table[window_size-1])
     {
@@ -352,19 +350,34 @@ int i, offset = 0;
 
       if (diff >= window_size) 
         {
+          /* Probably an epoch change. Check if we can fit it */
+          if (window_table[0] == 0)
+            {
+              window_table[0] = seq;
+              return 0;
+            }
+          
+          for (i=0;i<window_size-1;i++)
+            {
+              if (seq == window_table[i])
+                return -1;
+              if (seq == window_table[i] + 1)
+                {
+                  if (seq == window_table[i+1])
+                    return -1;
+                  window_table[i+1] = seq;
+                  return 0;
+                }
+            }
           return -1;
         }
 
       offset = window_size-1-diff;
 
       if (window_table[offset] == seq)
-        {
-          return -1;
-        }
+        return -1;
       else
-        {
-          window_table[offset] = seq;
-        }
+        window_table[offset] = seq;
     }
   else /* seq >= last */
     {
diff --git a/lib/gnutls_dtls.h b/lib/gnutls_dtls.h
index 99a230d..a188336 100644
--- a/lib/gnutls_dtls.h
+++ b/lib/gnutls_dtls.h
@@ -33,6 +33,17 @@ int _dtls_record_check(gnutls_session_t session, uint64 * 
_seq);
 
 #define MAX_DTLS_TIMEOUT 60000
 
+#define RETURN_DTLS_EAGAIN_OR_TIMEOUT(session) \
+  if (gnutls_time(0) - session->internals.dtls.handshake_start_time > \
+      session->internals.dtls.total_timeout_ms/1000) \
+    return gnutls_assert_val(GNUTLS_E_TIMEDOUT); \
+  else \
+    { \
+      if (session->internals.dtls.blocking != 0) \
+        millisleep(50); \
+      return gnutls_assert_val(GNUTLS_E_AGAIN); \
+    }
+
 /* returns true or false depending on whether we need to
  * handle asynchronously handshake data.
  */
diff --git a/lib/gnutls_record.c b/lib/gnutls_record.c
index 17cad7f..7510fbf 100644
--- a/lib/gnutls_record.c
+++ b/lib/gnutls_record.c
@@ -669,6 +669,12 @@ record_add_to_buffers (gnutls_session_t session,
            */
           if (IS_DTLS(session))
             {
+              if (type == GNUTLS_CHANGE_CIPHER_SPEC)
+                {
+                  ret = gnutls_assert_val(GNUTLS_E_UNEXPECTED_PACKET);
+                  goto unexpected_packet;
+                }
+                
               if (_dtls_is_async(session) && _dtls_async_timer_active(session))
                 {
                   ret = _dtls_retransmit(session);
@@ -996,6 +1002,8 @@ begin:
   if (ret < 0)
     {
       gnutls_assert();
+      _gnutls_audit_log(session, "Discarded message[%u] due to invalid 
decryption\n", 
+            (unsigned int)_gnutls_uint64touint32 (packet_sequence));
       goto sanity_check_error;
     }
 
@@ -1008,8 +1016,8 @@ begin:
       ret = _dtls_record_check(session, packet_sequence);
       if (ret < 0)
         {
-          _gnutls_audit_log(session, "Discarded duplicate message[%u]\n",
-            (unsigned int) _gnutls_uint64touint32 (packet_sequence));
+          _gnutls_audit_log(session, "Discarded duplicate message[%u]: %s\n",
+            (unsigned int) _gnutls_uint64touint32 (packet_sequence), 
_gnutls_packet2str (record.type));
           goto sanity_check_error;
         }
     }
@@ -1077,8 +1085,6 @@ sanity_check_error:
   if (IS_DTLS(session))
     {
       session->internals.dtls.packets_dropped++;
-      _gnutls_audit_log(session, "Discarded message[%u] due to invalid 
decryption\n", 
-            (unsigned int)_gnutls_uint64touint32 (packet_sequence));
       ret = gnutls_assert_val(GNUTLS_E_AGAIN);
       goto cleanup;
     }
diff --git a/maint.mk b/maint.mk
index 2668655..1dd6493 100644
--- a/maint.mk
+++ b/maint.mk
@@ -276,17 +276,17 @@ sc_avoid_if_before_free:
            exit 1; } || :
 
 sc_cast_of_argument_to_free:
-       @prohibit='\<free *\( *\(' halt='don'\''t cast free argument'   \
+       @prohibit='\<free *\( *\(' halt="don't cast free argument"      \
          $(_sc_search_regexp)
 
 sc_cast_of_x_alloc_return_value:
        @prohibit='\*\) *x(m|c|re)alloc\>'                              \
-       halt='don'\''t cast x*alloc return value'                       \
+       halt="don't cast x*alloc return value"                          \
          $(_sc_search_regexp)
 
 sc_cast_of_alloca_return_value:
        @prohibit='\*\) *alloca\>'                                      \
-       halt='don'\''t cast alloca return value'                        \
+       halt="don't cast alloca return value"                           \
          $(_sc_search_regexp)
 
 sc_space_tab:
@@ -516,7 +516,7 @@ sc_prohibit_argmatch_without_use:
 
 sc_prohibit_canonicalize_without_use:
        @h='canonicalize.h' \
-       
re='CAN_(EXISTING|ALL_BUT_LAST|MISSING)|canonicalize_(mode_t|filename_mode)' \
+       
re='CAN_(EXISTING|ALL_BUT_LAST|MISSING)|canonicalize_(mode_t|filename_mode|file_name)'
 \
          $(_sc_header_without_use)
 
 sc_prohibit_root_dev_ino_without_use:
@@ -1015,8 +1015,8 @@ update-NEWS-hash: NEWS
 # setting this to ' && !/PRAGMA_SYSTEM_HEADER/'.
 _makefile_at_at_check_exceptions ?=
 sc_makefile_at_at_check:
-       @perl -ne '/address@hidden@/'                                   \
-          -e ' && !/([A-Z_0-9]+)address@hidden@$$/'                    \
+       @perl -ne '/address@hidden@/'                                           
\
+          -e ' && !/(\w+)address@hidden@$$/'                           \
           -e ''$(_makefile_at_at_check_exceptions)                     \
          -e 'and (print "$$ARGV:$$.: $$_"), $$m=1; END {exit !$$m}'    \
            $$($(VC_LIST_EXCEPT) | grep -E '(^|/)(Makefile\.am|[^/]+\.mk)$$') \
@@ -1079,7 +1079,7 @@ sc_po_check:
 # Sometimes it is useful to change the PATH environment variable
 # in Makefiles.  When doing so, it's better not to use the Unix-centric
 # path separator of ':', but rather the automake-provided '$(PATH_SEPARATOR)'.
-msg = '$(ME): Do not use '\'':'\'' above; use $$(PATH_SEPARATOR) instead'
+msg = '$(ME): Do not use ":" above; use $$(PATH_SEPARATOR) instead'
 sc_makefile_path_separator_check:
        @prohibit='PATH[=].*:'                                          \
        in_vc_files='akefile|\.mk$$'                                    \
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 30ceb9f..99532d3 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -65,7 +65,7 @@ ctests = mini-deflate simple gc set_pkcs12_cred certder 
certuniqueid  \
         crq_key_id x509sign-verify cve-2009-1415 cve-2009-1416         \
         crq_apis init_roundtrip pkcs12_s2k_pem dn2 mini-eagain         \
         nul-in-x509-names x509_altname pkcs12_encode mini-x509         \
-        mini-x509-rehandshake rng-fork mini-eagain-dtls        \
+        mini-x509-rehandshake rng-fork mini-eagain-dtls mini-loss      \
         x509cert x509cert-tl infoaccess rsa-encrypt-decrypt
 
 if ENABLE_OCSP
diff --git a/tests/loss-common.h b/tests/loss-common.h
new file mode 100644
index 0000000..2843273
--- /dev/null
+++ b/tests/loss-common.h
@@ -0,0 +1,215 @@
+#define min(x,y) ((x)<(y)?(x):(y))
+
+char tmpbuf[128];
+extern const char* prefix;
+
+#define HANDSHAKE_EXPECT(c, s, clierr, serverr) \
+  sret = cret = GNUTLS_E_AGAIN; \
+  do \
+    { \
+      if (cret == GNUTLS_E_AGAIN) \
+        { \
+          prefix = "client"; \
+          cret = gnutls_handshake (c); \
+        } \
+      else if (cret >= 0) \
+        { \
+          prefix = "client"; \
+          ret = gnutls_record_recv(c, tmpbuf, sizeof(tmpbuf)); \
+        } \
+      if (sret == GNUTLS_E_AGAIN) \
+        { \
+          prefix = "server"; \
+          sret = gnutls_handshake (s); \
+        } \
+      else if (sret >= 0) \
+        { \
+          prefix = "server"; \
+          ret = gnutls_record_recv(s, tmpbuf, sizeof(tmpbuf)); \
+        } \
+    } \
+  while ((cret == GNUTLS_E_AGAIN || (cret == 0 && sret == GNUTLS_E_AGAIN)) && 
(sret == GNUTLS_E_AGAIN || (sret == 0 && cret == GNUTLS_E_AGAIN))); \
+  if (cret != clierr || sret != serverr) \
+    { \
+      fprintf(stderr, "client: %s\n", gnutls_strerror(cret)); \
+      fprintf(stderr, "server: %s\n", gnutls_strerror(sret)); \
+      fail("Handshake failed\n"); \
+      exit(1); \
+    }
+
+#define HANDSHAKE(c, s) \
+  HANDSHAKE_EXPECT(c,s,0,0)
+
+#define TRANSFER(c, s, msg, msglen, buf, buflen) \
+  sret = cret = GNUTLS_E_AGAIN; \
+  do \
+    { \
+      if (cret == GNUTLS_E_AGAIN) \
+        { \
+          prefix = "client"; \
+          cret = gnutls_record_send (c, msg, msglen); \
+        } \
+      if (sret == GNUTLS_E_AGAIN) \
+        { \
+          prefix = "server"; \
+          sret = gnutls_record_recv (s, buf, buflen); \
+        } \
+    } \
+  while ((cret == GNUTLS_E_AGAIN || (cret >= 0 && sret == GNUTLS_E_AGAIN)) && 
(sret == GNUTLS_E_AGAIN || (sret >= 0 && cret == GNUTLS_E_AGAIN))); \
+  \
+  if (cret < 0) fail ("client send error: %s\n", gnutls_strerror (ret)); \
+  if (sret < 0) fail ("server send error: %s\n", gnutls_strerror (ret))
+
+static char to_server[64*1024];
+static size_t to_server_len = 0;
+
+static char to_client[64*1024];
+static size_t to_client_len = 0;
+
+extern int counter;
+extern int packet_to_lose;
+
+#ifdef LOSS_DEBUG
+# define RETURN_RND_LOSS(session, len) { \
+  if (counter++ == packet_to_lose) \
+    { \
+    int t = gnutls_handshake_get_last_out(session); \
+    fprintf(stderr, "Discarding packet (%d) with seq %d\n", \
+        t, counter); \
+      return len; \
+    } \
+  }
+#else
+# define RETURN_RND_LOSS(session, len) { \
+  if (counter++ == packet_to_lose) \
+    { \
+      return len; \
+    } \
+  }
+#endif
+
+static void reset_counters(void)
+{
+  to_client_len = to_server_len = 0;
+}
+
+static ssize_t
+client_push (gnutls_transport_ptr_t tr, const void *data, size_t len)
+{
+  size_t newlen;
+
+  len = min(len, sizeof(to_server)-to_server_len);
+//  RETURN_RND_LOSS(tr, len);
+
+  newlen = to_server_len + len;
+  memcpy (to_server + to_server_len, data, len);
+  to_server_len = newlen;
+#ifdef LOSS_DEBUG
+  fprintf(stderr, "loss: pushed %d bytes to server (avail: %d)\n", (int)len, 
(int)to_server_len);
+#endif
+  return len;
+}
+
+static ssize_t
+client_pull (gnutls_transport_ptr_t tr, void *data, size_t len)
+{
+  if (to_client_len == 0)
+    {
+#ifdef LOSS_DEBUG2
+      fprintf(stderr, "loss: Not enough data by server (asked for: %d, have: 
%d)\n", (int)len, (int)to_client_len);
+#endif
+      return -1;
+    }
+
+  len = min(len, to_client_len);
+
+  memcpy (data, to_client, len);
+  memmove (to_client, to_client + len, to_client_len - len);
+  to_client_len -= len;
+#ifdef LOSS_DEBUG
+  fprintf(stderr, "loss: pulled %d bytes by client (avail: %d)\n", (int)len, 
(int)to_client_len);
+#endif
+  return len;
+}
+
+static ssize_t
+server_pull (gnutls_transport_ptr_t tr, void *data, size_t len)
+{
+  if (to_server_len == 0)
+    {
+#ifdef LOSS_DEBUG2
+      fprintf(stderr, "loss: Not enough data by client (asked for: %d, have: 
%d)\n", (int)len, (int)to_server_len);
+#endif
+      return -1;
+    }
+
+  len = min(len, to_server_len);
+#ifdef LOSS_DEBUG
+  fprintf(stderr, "loss: pulled %d bytes by server (avail: %d)\n", (int)len, 
(int)to_server_len);
+#endif
+  memcpy (data, to_server, len);
+
+  memmove (to_server, to_server + len, to_server_len - len);
+  to_server_len -= len;
+
+  return len;
+}
+
+static ssize_t
+server_push (gnutls_transport_ptr_t tr, const void *data, size_t len)
+{
+  size_t newlen;
+
+//  hexprint (data, len);
+
+  len = min(len, sizeof(to_client)-to_client_len);
+  RETURN_RND_LOSS(tr, len);
+
+  newlen = to_client_len + len;
+  memcpy (to_client + to_client_len, data, len);
+  to_client_len = newlen;
+#ifdef LOSS_DEBUG
+  fprintf(stderr, "loss: pushed %d bytes to client (avail: %d)\n", (int)len, 
(int)to_client_len);
+#endif
+
+  return len;
+}
+
+/* inline is used to avoid a gcc warning if used in mini-loss */
+inline static int server_pull_timeout_func(gnutls_transport_ptr_t ptr, 
unsigned int ms)
+{
+int ret;
+
+  if (to_server_len > 0)
+    ret = 1; /* available data */
+  else
+    ret = 0; /* timeout */
+
+#ifdef LOSS_DEBUG
+  fprintf(stderr, "loss: server_pull_timeout: %d\n", ret);
+#endif
+
+  return ret;
+}
+
+inline static int client_pull_timeout_func(gnutls_transport_ptr_t ptr, 
unsigned int ms)
+{
+int ret;
+
+  if (to_client_len > 0)
+    ret = 1;
+  else
+    ret = 0;
+
+#ifdef LOSS_DEBUG
+  fprintf(stderr, "loss: client_pull_timeout: %d\n", ret);
+#endif
+
+  return ret;
+}
+
+inline static void reset_buffers(void)
+{
+  to_server_len = 0;
+  to_client_len = 0;
+}
diff --git a/tests/mini-eagain-dtls.c b/tests/mini-loss.c
similarity index 68%
copy from tests/mini-eagain-dtls.c
copy to tests/mini-loss.c
index aeb2f44..21e0132 100644
--- a/tests/mini-eagain-dtls.c
+++ b/tests/mini-loss.c
@@ -31,63 +31,48 @@
 #include <gnutls/gnutls.h>
 #include <gnutls/crypto.h>
 #include "utils.h"
-#define RANDOMIZE
-#include "eagain-common.h"
+#include "loss-common.h"
+
+const char * prefix = NULL;
+int counter;
+int packet_to_lose;
 
 static void
 tls_log_func (int level, const char *str)
 {
-  fprintf (stderr, "|<%d>| %s", level, str);
+  fprintf (stderr, "%s|<%d>| %s", prefix, level, str);
 }
 
-static int handshake = 0;
-
-#define MAX_BUF 1024
-#define MSG "Hello TLS, and hi and how are you and more data here... and 
more... and even more and even more more data..."
+static gnutls_anon_server_credentials_t s_anoncred;
+static gnutls_anon_client_credentials_t c_anoncred;
 
-void
-doit (void)
+static void try1 (int packet)
 {
   /* Server stuff. */
-  gnutls_anon_server_credentials_t s_anoncred;
-  const gnutls_datum_t p3 = { (void *) pkcs3, strlen (pkcs3) };
-  static gnutls_dh_params_t dh_params;
   gnutls_session_t server;
   int sret, cret;
   /* Client stuff. */
-  gnutls_anon_client_credentials_t c_anoncred;
   gnutls_session_t client;
   /* Need to enable anonymous KX specifically. */
-  char buffer[MAX_BUF + 1];
-  ssize_t ns;
-  int ret, transferred = 0, msglen;
-
-  /* General init. */
-  gnutls_global_init ();
-  gnutls_global_set_log_function (tls_log_func);
-  if (debug)
-    gnutls_global_set_log_level (99);
+  int ret;
 
-  /* Init server */
-  gnutls_anon_allocate_server_credentials (&s_anoncred);
-  gnutls_dh_params_init (&dh_params);
-  gnutls_dh_params_import_pkcs3 (dh_params, &p3, GNUTLS_X509_FMT_PEM);
-  gnutls_anon_set_server_dh_params (s_anoncred, dh_params);
+  counter = 0;
+  packet_to_lose = packet;
+  reset_counters();
+  
   gnutls_init (&server, GNUTLS_SERVER|GNUTLS_DATAGRAM|GNUTLS_NONBLOCK);
-  ret = gnutls_priority_set_direct (server, 
"NONE:+VERS-DTLS1.0:+CIPHER-ALL:+MAC-ALL:+SIGN-ALL:+COMP-ALL:+ANON-DH", NULL);
+  ret = gnutls_priority_set_direct (server, 
"NONE:+VERS-DTLS1.0:+CIPHER-ALL:+MAC-ALL:+SIGN-ALL:+COMP-ALL:+ANON-ECDH:+CURVE-ALL",
 NULL);
   if (ret < 0)
     exit(1);
   gnutls_credentials_set (server, GNUTLS_CRD_ANON, s_anoncred);
-  gnutls_dh_set_prime_bits (server, 1024);
   gnutls_transport_set_push_function (server, server_push);
   gnutls_transport_set_pull_function (server, server_pull);
   gnutls_transport_set_pull_timeout_function (server, 
server_pull_timeout_func);
   gnutls_transport_set_ptr (server, (gnutls_transport_ptr_t)server);
 
   /* Init client */
-  gnutls_anon_allocate_client_credentials (&c_anoncred);
   gnutls_init (&client, GNUTLS_CLIENT|GNUTLS_DATAGRAM|GNUTLS_NONBLOCK);
-  cret = gnutls_priority_set_direct (client, 
"NONE:+VERS-DTLS1.0:+CIPHER-ALL:+MAC-ALL:+SIGN-ALL:+COMP-ALL:+ANON-DH", NULL);
+  cret = gnutls_priority_set_direct (client, 
"NONE:+VERS-DTLS1.0:+CIPHER-ALL:+MAC-ALL:+SIGN-ALL:+COMP-ALL:+ANON-ECDH:+CURVE-ALL",
 NULL);
   if (cret < 0)
     exit(1);
   gnutls_credentials_set (client, GNUTLS_CRD_ANON, c_anoncred);
@@ -96,36 +81,40 @@ doit (void)
   gnutls_transport_set_pull_timeout_function (client, 
client_pull_timeout_func);
   gnutls_transport_set_ptr (client, (gnutls_transport_ptr_t)client);
 
-  handshake = 1;
   HANDSHAKE(client, server);
 
-  handshake = 0;
   if (debug)
     success ("Handshake established\n");
 
-  do
-    {
-      ret = gnutls_record_send (client, MSG, strlen (MSG));
-    }
-  while(ret == GNUTLS_E_AGAIN);
-  //success ("client: sent %d\n", ns);
-
-  msglen = strlen(MSG);
-  TRANSFER(client, server, MSG, msglen, buffer, MAX_BUF);
-
-  if (debug)
-    fputs ("\n", stdout);
-
   gnutls_bye (client, GNUTLS_SHUT_WR);
   gnutls_bye (server, GNUTLS_SHUT_WR);
 
   gnutls_deinit (client);
   gnutls_deinit (server);
+}
+
+void
+doit (void)
+{
+  /* General init. */
+  gnutls_global_init ();
+  if (debug)
+    {
+      gnutls_global_set_log_function (tls_log_func);
+      gnutls_global_set_log_level (9);
+    }
+
+  gnutls_anon_allocate_server_credentials (&s_anoncred);
+  gnutls_anon_allocate_client_credentials (&c_anoncred);
+
+  try1(1);
+  try1(2);
+  try1(3);
+  try1(4);
+  try1(5);
 
   gnutls_anon_free_client_credentials (c_anoncred);
   gnutls_anon_free_server_credentials (s_anoncred);
 
-  gnutls_dh_params_deinit (dh_params);
-
   gnutls_global_deinit ();
 }


hooks/post-receive
-- 
GNU gnutls



reply via email to

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