Reputation: 179
While trying to do some socket programming I came across some interesting detail, that detail being the sockaddr_in
struct size, it's 14 bytes in size
From my understanding that extra padding is used for typecasting the different types of IP addresses but in theory, couldn't you sneak in malicious code if there's any padding left after the type casting?
Extra padding to me seems like unused memory.
Upvotes: 0
Views: 172
Reputation:
The sockaddr
and sockaddr_in
structures are typically only used for communication between an application and the kernel/runtime. They are constructed by functions like inet_aton()
, and passed to functions like bind()
. They are generally not sent over the network, or stored in files. As such, there's no way to "sneak in" a "malicious" (or otherwise faulty) value. Even if this did occur, the extra data would simply be ignored by the recipient.
The padding was probably added in an attempt to support future network address formats which might be larger than IPv4 addresses. Ironically, this was insufficient to support IPv6 addresses, which are 16 bytes long.
Upvotes: 2