bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Bruno Haible <bruno@clisp.org>
To: bug-gnulib@gnu.org
Cc: Rahul Das <bokul_4u@yahoo.com>,
	Keith Marshall <keith.d.marshall@ntlworld.com>,
	Eli Zaretskii <eliz@gnu.org>
Subject: Re: socklen_t data type
Date: Tue, 30 Jun 2020 03:07:39 +0200	[thread overview]
Message-ID: <2247884.BChNpACfHN@omega> (raw)
In-Reply-To: <83eepx23cd.fsf@gnu.org>

[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



  reply	other threads:[~2020-06-30  1:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-29 17:23 socklen_t data type Eli Zaretskii
2020-06-30  1:07 ` Bruno Haible [this message]
2020-06-30  2:29   ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2247884.BChNpACfHN@omega \
    --to=bruno@clisp.org \
    --cc=bokul_4u@yahoo.com \
    --cc=bug-gnulib@gnu.org \
    --cc=eliz@gnu.org \
    --cc=keith.d.marshall@ntlworld.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).