Henrik Nordstrom wrote:
tis 2008-04-01 klockan 22:59 +1300 skrev Amos Jeffries:
I started out that way (assuming ss_len was absent but sin_len was present) but a header analysis proved the assumption wrong. sin_len also proves very absent from Debian Linux 2.6.25 headers.

Somehow I doubt that linux would change the socket ABI between 2.6.24
and 2.6.25 breaking all applications..

Additinally the relevant header is not really from the kernel but
glibc..

OS that I know of and have tested the headers for all define a SOCKADDR_COMMON() macro for these types which neatly ensures they all have the same initial format within a given kernel. But not necessarily the same as other kernels.

Linux only has the family in the common part, with length being a family
specific member so you need to look in the actual definition of
sockaddr_in and sockaddr_in6 to find it.

rio:/usr/include# grep -R "sin_len" ./*
rio:/usr/include#

## bits/sockaddr.h
#
# /* POSIX.1g specifies this type name for the `sa_family' member.  */
# typedef unsigned short int sa_family_t;
#
# /* This macro is used to declare the initial common members
#    of the data types used for socket addresses, `struct sockaddr',
#    `struct sockaddr_in', `struct sockaddr_un', etc.  */
#
# #define __SOCKADDR_COMMON(sa_prefix) \
#   sa_family_t sa_prefix##family
#
#

## linux/in.h
#
# /* Structure describing an Internet (IP) socket address. */
# #define __SOCK_SIZE__   16              /* sizeof(struct sockaddr) */
# struct sockaddr_in {
#   sa_family_t           sin_family;     /* Address family    */
#   __be16                sin_port;       /* Port number       */
#   struct in_addr        sin_addr;       /* Internet address  */
#
#  /* Pad to size of `struct sockaddr'. */
#  unsigned char         __pad[__SOCK_SIZE__ - sizeof(short int) -
#                        sizeof(unsigned short int) -
#                        sizeof(struct in_addr)];
# };
# #define sin_zero        __pad           /* for BSD UNIX comp. -FvK */


## netinet/in.h
 - contains the same code with different comments.

{
  family
  port
  in_addr
  __padding
}


family
----
length
data


FreeBSD has a both length and family in the common area

length
family
---
data


AFAICT they are formally required to do so for sockaddr_in6. But not for sockaddr_in or sockaddr_storage.

sockaddr_in must have a sin_length for BSD socket implementations, which
is the common implementation seen in most OS:es...

sockaddr_storage does not have much requirements other than it being
able to store all supported sockaddr formats and there at minimum being
a ss_family member telling the address format..

Regards
Henrik


Amos
--
Please use Squid 2.6STABLE19 or 3.0STABLE3

Reply via email to