Tuesday, April 26, 2011

Socket Programming in C (3): Socket to Address structure Translation

// Get address structure by sock on current side, E.g. you want to know the client port number which randomly assigned
int getsockname(int sockfd, struct sockaddr *addr, socklen_t *addrlen);

// Get address structure by sock on the other side. E.g. server wants to know client's structure.
int getpeername(int sockfd, struct sockaddr *addr, socklen_t *addrlen);

No comments: