The Linux Programming Interface

(nextflipdebug5) #1
Sockets: Internet Domains 1237

data structure pointed to by rlbuf. This structure includes space for a data buffer,
the size of that buffer, and a pointer to the next “unread” character in that buffer.
It also includes a copy of the file descriptor given in the argument fd. The second
function, readLineBuf(&rlbuf), returns the next line from the buffer associated with
rlbuf. If required, this function reads a further block of data from the file descriptor
saved in rlbuf. Implement these two functions. Modify the programs in Listing 59-6
(is_seqnum_sv.c) and Listing 59-7 (is_seqnum_cl.c) to use these functions.

59-2. Modify the programs in Listing 59-6 (is_seqnum_sv.c) and Listing 59-7 (is_seqnum_cl.c) to
use the inetListen() and inetConnect() functions provided in Listing 59-9 (inet_sockets.c).


59-3. Write a UNIX domain sockets library with an API similar to the Internet domain
sockets library shown in Section 59.12. Rewrite the programs in Listing 57-3
(us_xfr_sv.c, on page 1168) and Listing 57-4 (us_xfr_cl.c, on page 1169) to use this
library.


59-4. Write a network server that stores name-value pairs. The server should allow names
to be added, deleted, modified, and retrieved by clients. Write one or more client
programs to test the server. Optionally, implement some kind of security
mechanism that allows only the client that created the name to delete it or to
modify the value associated with it.


59-5. Suppose that we create two Internet domain datagram sockets, bound to specific
addresses, and connect the first socket to the second. What happens if we create a
third datagram socket and try to send (sendto()) a datagram via that socket to the
first socket? Write a program to determine the answer.

Free download pdf