The serve_resource() function sends a connected client a requested resource. Our server expects all hosted files to be in a subdirectory called public. Ideally, our server should not allow access to any files outside of this public directory. However, as we shall see, enforcing this restriction may be more difficult than it first appears.

Our serve_resource() function takes as arguments a connected client and a requested resource path. The function begins as follows:

/*web_server.c except*/void serve_resource(struct client_info *client, const char *path) {    printf("serve_resource %s %s\n", get_client_address(client), path);

The connected client's IP address and the requested path are printed to aid in debugging. In a production ...

Get Hands-On Network Programming with C now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.