c - Why socklent_t * is used in accept() in socket programming? -
in c socket programming accept() declaration looks like:
int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen); i can understand uses of sockfd, struct sockaddr *addr.
but why have pass address of length of socket, have been socklen_t. because if accept() function needs length can socklen_t. why protype of function declared in such way?
so reason behind using socklen_t * type?
in code that's agnostic address/protocol family of socket it's accepting from, may using generic sockaddr_storage structure hold result. initial value of pointed-to socklen_t size of storage; value after accept returns actual size of resulting peer address. also, address/protocol families af_unix have variable length addresses, if know type may not know size.
Comments
Post a Comment