/***********************************************************************
* Code listing from "Advanced Linux Programming," by CodeSourcery LLC  *
* Copyright (C) 2001 by New Riders Publishing                          *
* See COPYRIGHT for license information.                               *
***********************************************************************/

#include 
#include 
#include 
#include 

#include "server.h"

/* A template for the HTML page this module generates.  */

static char* page_template =
  "\n"
  " \n"
  "  \n"
  " \n"
  " \n"
  "  

The current time is %s.

\n" " \n" "\n"; void module_generate (int fd) { struct timeval tv; struct tm* ptm; char time_string[40]; FILE* fp; /* Obtain the time of day, and convert it to a tm struct. */ gettimeofday (&tv, NULL); ptm = localtime (&tv.tv_sec); /* Format the date and time, down to a single second. */ strftime (time_string, sizeof (time_string), "%H:%M:%S", ptm); /* Create a stream corresponding to the client socket file descriptor. */ fp = fdopen (fd, "w"); assert (fp != NULL); /* Generate the HTML output. */ fprintf (fp, page_template, time_string); /* All done; flush the stream. */ fflush (fp); }