
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.

A:
"9999" is not an integer - it is a charater string. If you have an integer
variable it is already 4 bytes long (that is the internal representation
used for integers on all the platforms used on campus).
read/write/send/recv all operate on bytes, not characters - so you can
give them any collection of bytes.
Example: to write the 4 byte integer value held by the variable foo,
just give write the address of foo
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).