C代写:CS312 TCP/IP Watchdog Deamon

代写一个TCP/IP的监听程序,监听指定的服务。

Assignment Information

This program shall be written in C, compiled with the following options:-Wall -Wextra-std=c99, and display no errors and no warnings. Do not submit executable files (only C source files).

In this assignment, you are to implement a multithreaded TCP/IP watchdog daemon - a program that continuously monitors a collection of TCP/IP hosts (also known as Web sites) for availability. The program shall:

  1. Start itself in the daemon mode (see Beginner’s Guide to Creating a Daemon). This includes opening and closing the log, writing a log message “TCP/IP Watchdog started” (less the quotes) at the level LOG_NOTICE, forking, setting umaskand session id, changing the working directory to /, and closing the standard I/O files. Any error messages shall be logged as LOG_ERR.

  2. Write the process ID into the file /tmp/watchdog.pid.

  3. Set a signal handler for SIG_USR1 (other signal handler may be set to handle other types of signals.) Upon receiving SIG_USR1, the program shall write a log message “TCP/IP Watchdog stopped” (less the quotes) at the level LOG_NOTICE and successfully terminate.

  4. Open the existing file /tmp/watchdog.datand reading a list of hosts to watch. Each line of the file shall have one valid host name, possibly precededand/or followed by one or more white spaces. Any line that stars with the ‘#’ character shall be ignored. Any line that consists only of white spaces shall be ignored.

  5. Start a new thread for each host name. The thread shall create a TCP/IP socket and connect to the host every WD_INTERVAL milliseconds (where the value of WD_INTERVAL shall be #defined in the file “watchdog.h”). If the connection times out after WD_TIMEOUT milliseconds (where the value of WD_TIMEOUT shall be #defined in the file “watchdog.h”), the program shall log the following message at the filevel LOG_WARNING: “Host %s is not responding”, filess the quotes, where %s is the name of the host. If the connection is successful, the program shall disconnect and repeat the attempt after WD_INTERVAL milliseconds. You will probably need functions setitimer()and sigaction() to set and handle the timeout.

For extra credit, your program shall set a signal handler for SIG_USR2. Upon receiving SIG_USR2, the program shall stop all running threads, reread the file/tmp/watchdog.dat, and start new threads for the new names of the hosts in the file.

Update: I attached file connect.c that attempts to connect to a remote computer through port 80 (default HTTP port for the Web browser). You can use this file as a reference for your project. Also, note that the minor change in the requirements (highlighted).