Create the first assignment: 'timeserver'

This commit is contained in:
Charles Descamps 2025-01-24 14:36:36 -07:00
parent bc6a19ff33
commit a54d88dc70
6 changed files with 92 additions and 0 deletions

20
timeserver/Makefile Normal file
View file

@ -0,0 +1,20 @@
CC = gcc -Wall -std=c99 -pedantic
SOURCES = timeserver.c
OBJECTS = timeserver.o
all: timeserver
timeserver: $(OBJECTS)
$(CC) $(OBJECTS) -o timeserver
timeserver.o: timeserver.c
$(CC) -c timeserver.c -o timeserver.o
clean:
rm -f $(OBJECTS) timeserver timeserver.out
clean_objects:
rm -f $(OBJECTS)
run:
./timeserver

16
timeserver/README.md Normal file
View file

@ -0,0 +1,16 @@
# Running the timeserver
Use `make` to compile the timeserver.
Use `make run` to run the timeserver. This will run on an infinite loop.
Use `Ctrl+C` to stop the timeserver.
## timeserver communication
Communicating with the server can happen using netcat in UDP mode (-u flag).
## timeserver information
The timeserver runs on UDP port 8888.
The timeserver will wait for `time\r\n` to be sent on this port, and if received,
will send back a response of the time (in ms) since January 1st, 1970 (UNIX Epoch).
## pcap information
A demonstration of the timeserver has been captured with Wireshark in the
included `demo.pcap` file.

BIN
timeserver/timeserver Executable file

Binary file not shown.

33
timeserver/timeserver.c Normal file
View file

@ -0,0 +1,33 @@
// header files
#include "timeserver.h"
// constants
// timeserver port is 8888
#define TIMEPORT "8888"
// prototypes
// main function
int main(int argc, char **argv)
{
// initialize program (variables and structs)
// define a UDP socket
// bind the UDP socket to port 8888 / TIMEPORT
// while loop to see if the "time\r\n" has been received (recv call?)
// if "time\r\n" is received, then send() back the linux epoch.
// profit???
return 0;
}
// function definitions
/*
Name: ???
Process: ???
Function Input/Parameters: ???
Function Output/Parameters: ???
Function Output/Returned: ???
Device Input/Device: ???
Device Output/Device: ???
Dependencies: ???
*/

23
timeserver/timeserver.h Normal file
View file

@ -0,0 +1,23 @@
#ifndef TIMESERVER
#define TIMESERVER
// included libraries
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <time.h>
#include <unistd.h>
#include <errno.h>
#include <netinet/in.h>
#include <arpa/inet.h>
// data structures
// function prototypes
#endif // TIMESERVER

BIN
timeserver/timeserver.o Normal file

Binary file not shown.