Lars Ingebrigtsen schrieb am So., 14. Mai 2017 um 12:28 Uhr: > Philipp Stephani writes: > > > + case AF_INET: > > + port = ((struct sockaddr_in6 *) (struct sockaddr > *) &sa1)->sin6_port; > > + has_port = true; > > + break; > > + case AF_INET6: > > + port = ((struct sockaddr_in *) (struct sockaddr > *) &sa1)->sin_port; > > + has_port = true; > > Aren't these two cases in reverse? If it's AF_INET6, it's an in6 > struct, not the other way around. > Oops, thanks! > > Not that it matters, since (as Eli said) the sizes of the first elements > in the structs are identical... > > I don't know whether we can rely on that (i.e. whether Posix guarantees it) or whether it's an implementation detail. (This also needs __attribute__((may_alias)), type punning, or memcpy due to aliasing.)