[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: socklen_t data type
From: |
Bruno Haible |
Subject: |
Re: socklen_t data type |
Date: |
Tue, 30 Jun 2020 03:07:39 +0200 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-179-generic; KDE/5.18.0; x86_64; ; ) |
[Ccing Keith Marshall as the reporter of <https://savannah.gnu.org/bugs/?57725>]
Hi Eli,
> Gnulib's sys/socket.h has this:
>
> # if @HAVE_WINSOCK2_H@
> /* Include headers needed by the emulation code. */
> # include <sys/types.h>
> # include <io.h>
>
> # if !GNULIB_defined_socklen_t
> typedef int socklen_t;
> # define GNULIB_defined_socklen_t 1
> # endif
>
> # endif
>
> This unconditionally defines socklen_t on MS-Windows systems as a
> signed int data type. Why is this unconditional?
Earlier, it was unconditionally needed.
> This page:
>
> https://pubs.opengroup.org/onlinepubs/007908799/xns/syssocket.h.html
>
> says:
>
> <sys/socket.h> makes available a type, socklen_t, which is an
> unsigned opaque integral type of length of at least 32 bits.
The page you cite is part of SUSv2. It has been superseded by POSIX,
first by the 2004 edition:
https://pubs.opengroup.org/onlinepubs/009695399/basedefs/sys/socket.h.html
and then by the current edition:
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_socket.h.html
Please update your bookmarks.
> So socklen_t could be an unsigned data type, which would then conflict
> with the above.
>
> And in fact mingw.org's MinGW recently changed the socklen_t data type
> to be unsigned int, which breaks compilation of Gnulib's
> sys_socket.c. Is MinGW in error here?
Looking at the prototypes of the function inet_ntop [1]
it should be 'unsigned int' or 'size_t'.
Looking at the prototypes of the functions connect [2], accept [3], bind [4],
getpeername [5], getsockname [6], getsockopt [7], recvfrom [8], sendto [9],
setsockopt [10]
it should be 'int'.
But regardless how mingw defines 'socklen_t' (as 'int' or as 'unsigned int'),
none of these prototypes is POSIX compliant anyway, since all these prototypes
have the WSAAPI attribute.
So, gnulib should define socklen_t if and only if the system's header don't.
The code which does this is in m4/socklen.m4. I'm therefore applying the patch
below.
[1]
https://docs.microsoft.com/en-us/windows/win32/api/ws2tcpip/nf-ws2tcpip-inet_ntop
[2]
https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-connect
[3]
https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-accept
[4] https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-bind
[5]
https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getpeername
[6]
https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockname
[7]
https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt
[8]
https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-recvfrom
[9]
https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-sendto
[10]
https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-setsockopt
2020-06-29 Bruno Haible <bruno@clisp.org>
sys_socket: Don't define socklen_t if it is already defined on mingw.
Reported by Keith Marshall <keith.d.marshall@ntlworld.com> in
<https://savannah.gnu.org/bugs/?57725>,
by Rahul Das <bokul_4u@yahoo.com> in
<https://lists.gnu.org/archive/html/bug-gnulib/2020-04/msg00081.html>,
and by Eli Zaretskii <eliz@gnu.org> in
<https://lists.gnu.org/archive/html/bug-gnulib/2020-06/msg00068.html>.
* lib/sys_socket.in.h (socklen_t): Remove definition.
diff --git a/lib/sys_socket.in.h b/lib/sys_socket.in.h
index 948d689..577947d 100644
--- a/lib/sys_socket.in.h
+++ b/lib/sys_socket.in.h
@@ -195,12 +195,7 @@ struct sockaddr_storage
/* Include headers needed by the emulation code. */
# include <sys/types.h>
# include <io.h>
-
-# if !GNULIB_defined_socklen_t
-typedef int socklen_t;
-# define GNULIB_defined_socklen_t 1
-# endif
-
+/* If these headers don't define socklen_t, <config.h> does. */
# endif
/* Rudimentary 'struct msghdr'; this works as long as you don't try to