bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* socklen_t data type
@ 2020-06-29 17:23 Eli Zaretskii
  2020-06-30  1:07 ` Bruno Haible
  0 siblings, 1 reply; 3+ messages in thread
From: Eli Zaretskii @ 2020-06-29 17:23 UTC (permalink / raw)
  To: bug-gnulib

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?  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.

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?


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: socklen_t data type
  2020-06-29 17:23 socklen_t data type Eli Zaretskii
@ 2020-06-30  1:07 ` Bruno Haible
  2020-06-30  2:29   ` Eli Zaretskii
  0 siblings, 1 reply; 3+ messages in thread
From: Bruno Haible @ 2020-06-30  1:07 UTC (permalink / raw)
  To: bug-gnulib; +Cc: Rahul Das, Keith Marshall, Eli Zaretskii

[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



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: socklen_t data type
  2020-06-30  1:07 ` Bruno Haible
@ 2020-06-30  2:29   ` Eli Zaretskii
  0 siblings, 0 replies; 3+ messages in thread
From: Eli Zaretskii @ 2020-06-30  2:29 UTC (permalink / raw)
  To: Bruno Haible; +Cc: bokul_4u, keith.d.marshall, bug-gnulib

> From: Bruno Haible <bruno@clisp.org>
> Cc: Eli Zaretskii <eliz@gnu.org>, Keith Marshall <keith.d.marshall@ntlworld.com>, Rahul Das <bokul_4u@yahoo.com>
> Date: Tue, 30 Jun 2020 03:07:39 +0200
> 
> >   <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.

Right, the "unsigned" part disappeared in the later versions.

> 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.

Thanks.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-06-30  2:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-29 17:23 socklen_t data type Eli Zaretskii
2020-06-30  1:07 ` Bruno Haible
2020-06-30  2:29   ` Eli Zaretskii

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).