| OpSys Spring 2005 - HW5 FAQ |
|   OpSys Home   |   HW5 Assignment |
+ Server port number?
|
Question: | If I tell bind the port is 0, which means "give me any available port", how do I find out what the port is (so I can print it out)? |
|
Answer: | After the call to
/* find out what port we were assigned and print it out */
length = sizeof( skaddr );
if (getsockname(ld, (struct sockaddr *) &skaddr, &length)<0) {
perror("Error getsockname\n");
exit(1);
}
printf("The Server passive socket port number is %d\n",ntohs(skaddr.sin_port));
|