Skip to content

Latest commit

 

History

History
58 lines (37 loc) · 3.83 KB

server_design.md

File metadata and controls

58 lines (37 loc) · 3.83 KB

Overview This code is designed for a server-side program that handles a simple network protocol with its clients. The software manages a routing table and a MAC address list, and interacts with multiple clients, keeping them synchronized with its data structures. It uses UNIX domain sockets for communication.

Details Headers errno.h, stdio.h, etc.: These are standard C headers. They provide a set of functionality for things like error handling, standard input-output, data types, string manipulation, and character checks.

sys/shm.h, sys/mman.h, etc.: These headers provide functionalities related to system calls, shared memory, memory mapping, and sockets.

signal.h: Provides functionalities to handle signals, which are a form of software interrupts.

DLL/dll.h, Mac-List/mac-list.h, etc.: These are custom header files which probably define the structures and functionalities for doubly linked lists, MAC list, routing tables, and synchronization.

Constants and Global Variables MAX_CLIENTS, OP_LEN, MAX_MASK: Constants defining maximum clients the server can handle, length of an operation string, and the maximum subnet mask value.

store_IP: An external function probably responsible for storing IP addresses.

synchronized, connection_socket, loop: Variables indicating server states and the main socket for connections.

routing_table, mac_list: Doubly linked lists storing routing table entries and MAC addresses respectively.

monitored_fd_set, client_pid_set: Arrays to track file descriptors of client connections and their process IDs.

Functions intitiaze_monitor_fd_and_client_pid_set(): Initializes the arrays used to track file descriptors and client process IDs.

add_to_monitored_fd_set() and add_to_client_pid_set(): Functions to add file descriptors and process IDs to the respective arrays.

remove_from_monitored_fd_set() and remove_from_client_pid_set(): Functions to remove file descriptors and process IDs from the respective arrays.

refresh_fd_set(): Refreshes the file descriptor set (important for select call).

flush_clients(): Informs all clients to refresh their data structures.

digits_only(), isValidIP(), isValidMask(), isValidMAC(): Validation functions to check the validity of strings as numbers, IP addresses, masks, and MAC addresses.

get_max_fd(): Gets the maximum file descriptor value from the monitored set. Useful for the select function.

create_sync_message(): Parses a string command to create a synchronization message for clients.

signal_handler(): Handles external interrupts, like when a user presses Ctrl+C to stop the server.

update_new_client(): When a new client connects, this function sends it all necessary data so that the client can be in sync with the server's current data structures.

Main Function The main() function sets up the server:

  • It initializes the routing table and MAC list.
  • Sets up the UNIX domain socket for communication.
  • Listens for connections and adds them to the monitored set.
  • Registers a signal handler for SIGINT.
  • Enters an infinite loop where it:
    • Waits for user input to select an option like CREATE, UPDATE, DELETE, etc.
    • Handles client connections, receives messages from them, and broadcasts updates to the routing table or MAC list. In simpler words, this server lets you manage a table of IP routes and a list of MAC addresses. Clients can connect to this server, and the server ensures they always have the current versions of these tables.

What does it actually do? In a network setting, routing tables are crucial. They determine how data packets should traverse a network to reach their destination. MAC addresses, on the other hand, are unique identifiers assigned to network interfaces for communications at the data link layer. This software seems to simulate a central server that manages these crucial pieces of information, and it can synchronize its data with multiple client systems.