Because sockaddr is actually just a placeholder data type. The actual data structure you transmit may vary. For example, the address structures for IPv4 and IPv6 differ in content and length. And this is the passing point of the size of the structure.
In general, this is a widely used technique. Any size is passed because the parameter or element of size additioanl is included directly in the structure (as a rule, as its first member). This allows the receiving function to distinguish between different known versions of this structure, in situations where the API changes over time and new members are added, but still alrady programs compiled with older API definitions have a passage with a real size smaller than that in the latest . This is a typical technique found in the Windows API. Many related Windows structures have something like a DWORD cbSize in them.
source share