Here are the new lines added after the call to
connect:
len = sizeof(cliaddr);
Getsockname(sockfd, (SA *) &cliaddr, &len);
printf("local addr: %s\n",
Sock_ntop((SA *) &cliaddr, len));
This requires a declaration of len as a
socklen_t and a declaration of cliaddr as a
struct sockaddr_in. Notice that the value-result argument
for getsockname (len) must be initialized before
the call to the size of the variable pointed to by the second
argument. The most common programming error with value-result
arguments is to forget this initialization.
|