The bind() function accepts a pointer to a sockaddr
, but in all examples I've seen, a sockaddr_in
structure is used instead, and is cast to sockaddr
:
struct sockaddr_in name;
...
if (bind (sock, (struct sockaddr *) &name, sizeof (name)) < 0)
...
I can't wrap my head around why is a sockaddr_in
struct used. Why not just prepare and pass a sockaddr
?
Is it just convention?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…