All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Bastien Roucariès" <rouca@debian.org>
To: Alejandro Colomar <alx.manpages@gmail.com>
Cc: "linux-man@vger.kernel.org" <linux-man@vger.kernel.org>,
	eblake <eblake@redhat.com>, Zack Weinberg <zack@owlfolio.org>,
	GNU C Library <libc-alpha@sourceware.org>
Subject: Re: struct sockaddr_storage, union (was: Improve getsockname)
Date: Fri, 20 Jan 2023 21:11:28 +0000	[thread overview]
Message-ID: <1698201.vqxVuVRdHc@portable-bastien> (raw)
In-Reply-To: <528e35f3-ee79-52e0-be5b-ea5572cf3d07@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1672 bytes --]

Le jeudi 19 janvier 2023, 23:31:09 UTC Alejandro Colomar a écrit :
Hi,
> On 1/19/23 22:38, Bastien Roucariès wrote:
> 
> However... Considering that most APIs use `struct sockaddr *`, this wouldn't 
> allow the internal libc implementation of functions like getnameinfo(3) to be 
> free of UB.

libc is safe thanks to the transparent union of pointer.

> Maybe a better thing would be to do the following:
> 
> 
> struct sockaddr {
> 	union {
> 		struct {
> 			sa_family_t  sa_family;
> 			char         sa_data[];
> 		};
> 		struct sockaddr_in   sin;
> 		struct sockaddr_in6  sin6;
> 		struct sockaddr_un   sun;
> 	};
> };
> 
> struct sockaddr_storage {
> 	union {
> 		sa_family_t          ss_family;
> 		struct sockaddr      sa;
> 	};
> };
> 

No I think we could do better with recent C:
struct osockaddr
{
  unsigned short int sa_family;
  unsigned char sa_data[14];
  char _extra[];
};

> This makes sockaddr and sockaddr_storage have the same size, and also both can 
> alias any of the children types through the unions, so one can use either of 
> them for the same purpose.

We could not due to old talk protocol

Only storage is free
> 
> I'll be sending a patch soon for discussion.
> 
> Cheers,
> 
> Alex
> 
> > 
> >>
> >>>
> >>>    struct sockaddr_storage {
> >>> 	union {
> >>>    		sa_family_t          ss_family;
> >>>    		struct sockaddr      sa;
> >>>    		struct sockaddr_in   sin;
> >>>    		struct sockaddr_in6  sin6;
> >>>    		struct sockaddr_un   sun;
> >>>    	};
> >>>                          char __reserved_null;
> >>
> 
> -- 
> <http://www.alejandro-colomar.es/>
> 


[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

      parent reply	other threads:[~2023-01-20 21:11 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-17 10:22 Improve getsockname Bastien Roucariès
2023-01-19 12:42 ` Alejandro Colomar
2023-01-19 19:44   ` Bastien Roucariès
2023-01-19 20:19     ` struct sockaddr_storage, union (was: Improve getsockname) Alejandro Colomar
2023-01-19 21:00       ` Bastien Roucariès
2023-01-19 21:19         ` Alejandro Colomar
2023-01-19 21:38           ` Bastien Roucariès
2023-01-19 23:31             ` Alejandro Colomar
2023-01-20  0:12               ` Alejandro Colomar
2023-01-20 21:11               ` Bastien Roucariès [this message]

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

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

  git send-email \
    --in-reply-to=1698201.vqxVuVRdHc@portable-bastien \
    --to=rouca@debian.org \
    --cc=alx.manpages@gmail.com \
    --cc=eblake@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=linux-man@vger.kernel.org \
    --cc=zack@owlfolio.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.