Xiwen Li Xiwen Li - 3 months ago 10
C Question

How exactly does sockaddr_storage work?

I just started to get into socket programming. I don't understand how by just declaring sockaddr_storage and then make a socket listen(), all the incoming connections just automatically get stored in sockaddr_storage. What if you declare 5 sockaddr_storage?

Answer

How exactly does sockaddr_storage work?

sockaddr_storage is a type that's big enough to hold either an IPv4 socket address or an IPv6 socket address.

I don't understand how by just declaring sockaddr_storage and then make a socket listen(), all the incoming connections just automatically get stored in sockaddr_storage.

That's because they don't.

What if you declare 5 sockaddr_storage?

Then you have 5 variables of type sockaddr_storage. Nothing special happens. It's the same as if you asked "what if you declare 5 ints?"

Comments