A:
You can just use sqd_numshares().
A: No - the homework description was wrong -
the number of shares held by the user makes more sense.
A: Use the telnet command, which allows you
to open a TCP connection to any tcp port.
A:
This depends on what version of telnet you are using, most allow you
to interrurt the telnet session with the control character ^[. Then
you can type quit.
A:
You need to use getsockname():
if (getsockname(ld, (struct sockaddr *) &skaddr, &length)<0) { printf("Error getsockname\n"); exit(1); } printf("The server UDP port number is %d\n",ntohs(skaddr.sin_port));
A:
Each UDP write/sendto will correspond to a read/recv - so if the reader is
expecting the tranaction ID and flag in a single message (read) - you
need to make sure it is all sent together.
For HW#2 you must match the datagrams that are in the homework assignment, so you need to construct an entire message (datagram) and then send it.
int foo; .... write(fd,&foo,4);This will send the 4 byte integer variable to the file descriptor fd, keep in mind that the representation (byte order) may be different between varius machines so that reading the same 4 bytes may not be enough. For homework #2 you need to convert to and from network byte order, so that the client and server could be running on any kind of machine.
NOTE: if fd is a UDP socket - this will result in a 4 byte UDP datagram, this is not what you want for HW#2 (see question 6).