Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.
Open C Sockets: getsockname method
- getsockname - gets socket name
int getsockname (int s, struct sockaddr * restrict name, socklen_t * restrict namelen);
The getsockname system call returns the current name for the specified socket. The namelen argument should be initialized to indicate the amount of space pointed to by name. On return it contains the actual size of the name returned (in bytes).
Following is the usage of getsockname function:
struct sockaddr_in addr,ss;
unsigned int len;
sock_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = htonl(INADDR_ANY);
addr.sin_port = htons(5000);