I have been asked in an interview why there is a need of calculating the size of the address to which it is bound in bind system call.
bind(sockfd, (struct sockaddr *) &serv_addr,sizeof(serv_addr))
Means i would like to know what is purpose of having third argument in bind system call??
Because the
sockaddrstructure serves more or less as a “base” structure for “derived” structures likesockaddr_in. It’s almost an inheritance mechanism.sockaddrcontains variable-length data that can be used by “derived” structures likesockaddr_*, hence you need to precise the effective size of the “derived” structure.