"These men know why they are on this New Jersey hilltop." Intrigued?

Netbounce project with Apache2

by: burt rosenberg
at: february 2025

Overview

The netbounce code is in project repo.

This project is to get that code to work, and modify it and the project 1 webserver to log to the web netbounce events.

First activity: get netbounce working

The assignment as accepted has the base netbounce code. Clone the repo to both your AWS instance and your local machine. Compile in both places.
  1. Make sure the Security Group for you AWS instance is open for Custom UDP, Port 3333, from anywhere.
  2. Adjust the Makefile, or however you plan to run the client, with the public IP address of your running AWS instance.
  3. Be aware, each time you restart your AWS instance, you may have a different public IP.
  4. Run the server on the AWS instance. See the Makefile target. Run in verbose mode.
  5. Run the client on your local machine. See the Makefile target. Run in verbose mode.
You should have net bounced the message of your choice from your client to the server and back to your client.

Second activity: add logging

Modify the code of the netbounce server to write whatever it writes to stdout also to a file, if the -f option is provided on the command line.

  1. Add some new variables at the top of your code,
    	#include<time.h> // in the include section
    	
    	// in the variable declaration section
    	char * out_file_name = NULL ;
    	FILE * out_fn = NULL ;
    	time_t the_time ;
    
  2. Add a -f option to getopt. This requires two changes, f: added to the string that configures getopt and an new switch case,
    	while ((ch = getopt(argc, argv, "vp:lf:")) != -1) {  // change
    	
    	// add somewhere in the switch body
    		case 'f':
    			out_file_name = strdup(optarg) ;
    			break ;
    
  3. Update the usage message,
    	#define USAGE_MSG "usage: %s [-lv] -p port -f log_file\n"
    
  4. Opening the file for append, if the command option -f appears, and using some calls to get the time printed out,
    	if (out_file_name) {
    		out_fn = fopen(out_file_name, "a");
    		if (!out_fn) {
    			perror("fopen") ;
    			exit(1) ;
    		}
    	}
    
    	if (out_fn) {
    		time(&the_time) ;
    		fprintf(out_fn,"%sserver starting ...", ctime(&the_time)) ;
    		
    		fflush(out_fn) ;
    	}
    
  5. Decorate your code with writes, if out_fn is not null, which also writes the the log file what is written to the console. For instance,
    
    	if (out_fn) {
    		fprintf(out_fn,"packet sent, %d bytes\n", bytes_sent) ;
    		fflush(out_fn) ;
    	}
    
Test and commit. A new Makefile macro gives the name of the logfile and the option to apply for the targets run-server.

Third activity: enable shtml

I will not explain how the logfile will be presented by your web serve.

Of the several ways of doing this we will use server-side includes. There is a new starter index.shtml that you should move to your web server root, /var/www/ubuntu/index.shtml. Note that it includes the magic SSI lines,

<!--#echo var="DATE_LOCAL" -->
<!--#include file=netbounce-log.txt -->
Once we have SSI's enabled, and the .shtml suffix recognized, as the index file is being served, it is filtered through a pre-processor that looks for such lines, that are otherwise comments and invisible to the user, and performs the directives.

The two directives here are #echo and #include. Processing these replaces them with the local date and the contents of the named file.

See howto/ssi.html for more information.

  1. The ability to include files is in an apache module, code that is optional. Enable the module using,
    sudo a2enmod  include
    
    see howto apache modules for more information. Note that this command is ubuntu, not apache.
  2. Then onfigure the include module in the apache configuration files. In the file /etc/apache2/site-available/000-default.conf add
    <Directory /var/www/>
            Options +Includes
            AddType text/html .shtml
            AddOutputFilter INCLUDES .shtml
            DirectoryIndex index.html index.shtml
    </Directory>
    
  3. Restart the webserver,
    sudo systemctl restart apache2
    
Browse to your webserver, and the shtml should show the time, but will complain about not finding the file netbounce-log.txt, because we have not created that file yet.

Note that not both the html and the shtml should be present. The DirectoryIndex option means that either will be taken, but the index.html is taken in preference.

Fourth activity: the project website

Update the Makefile in your project with the correct log file location,
    LOGFILE= /var/www/ubuntu/netbounce-log.txt
Run the server; netbounce with the client; and refresh your webbrowser to see the appending log.
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.

author: burton rosenberg
created: 8 feb 2024
update: 31 jan 2025