In the C language a typical way to bind
a Socket would be the following way:
int server_socket_fd = socket(AF_INET, SOCK_STREAM, 0);
struct sockaddr_in addr;
int port_number = 55555;
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = htonl(INADDR_ANY);
addr.sin_port = htons(port_number);
int result = bind(server_socket_fd,(struct sockaddr *)&addr , sizeof(addr));
if(bind_result > 0)
{
// Stuff
}
I am wondering why the cast from sockaddr_in
to sockaddr
works since I cant find any documentation why it works.
It just seems like everyone just does it.
Why does the typecast work here?
I am not asking why we cast it, this has been answered here. I am asking why it works.