mirror of
https://github.com/Hizenberg469/Routing-Table-Manager.git
synced 2026-04-19 18:02:23 +03:00
RTM Project
This commit is contained in:
17
Routing-Table/CMakeLists.txt
Normal file
17
Routing-Table/CMakeLists.txt
Normal file
@@ -0,0 +1,17 @@
|
||||
set( RT_SRC
|
||||
"routing-table.c")
|
||||
|
||||
set( RT_HEADER
|
||||
"routing-table.h")
|
||||
|
||||
|
||||
add_library( ${RT_NAME} STATIC
|
||||
${RT_SRC}
|
||||
${RT_HEADER})
|
||||
|
||||
target_include_directories( ${RT_NAME} PUBLIC
|
||||
"./"
|
||||
)
|
||||
|
||||
target_link_libraries( ${RT_NAME} PUBLIC
|
||||
${DLL_NAME})
|
||||
59
Routing-Table/routing-table.c
Normal file
59
Routing-Table/routing-table.c
Normal file
@@ -0,0 +1,59 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "routing-table.h"
|
||||
#include "dll.h"
|
||||
|
||||
/*
|
||||
* Display each (entry) of a routing table.
|
||||
*/
|
||||
|
||||
void display_routing_table(const dll_t* routing_table) {
|
||||
|
||||
printf("Printing routing table.\n");
|
||||
|
||||
dll_node_t* node = routing_table->head->next;
|
||||
while (node != routing_table->head) {
|
||||
routing_table_entry_t entry = *((routing_table_entry_t*)node->data);
|
||||
|
||||
printf("Destination IP: %s Mask: %u Gateway IP: %s OIF: %s\n", entry.dest,
|
||||
entry.mask, entry.gw, entry.oif);
|
||||
node = node->next;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Look up entry in routing table by destination IP and subnet mask.
|
||||
*/
|
||||
|
||||
dll_node_t* find_routing_table_entry(const dll_t* routing_table, const char* dest,
|
||||
const unsigned short mask) {
|
||||
|
||||
dll_node_t* node = routing_table->head->next;
|
||||
while (node != routing_table->head) {
|
||||
|
||||
routing_table_entry_t entry = *((routing_table_entry_t*)node->data);
|
||||
if (!strcmp(entry.dest, dest) && entry.mask == mask) {
|
||||
break;
|
||||
}
|
||||
|
||||
node = node->next;
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
/*
|
||||
* Updates the entry whose destination IP is dest and subnet mask is mask.
|
||||
*/
|
||||
|
||||
void update(dll_node_t* node, const char* gw, const char* oif) {
|
||||
|
||||
routing_table_entry_t* entry = node->data;
|
||||
memset(entry->gw, 0, IP_ADDR_LEN);
|
||||
memset(entry->oif, 0, OIF_LEN);
|
||||
memcpy(entry->gw, gw, strlen(gw));
|
||||
memcpy(entry->oif, oif, strlen(oif));
|
||||
|
||||
}
|
||||
31
Routing-Table/routing-table.h
Normal file
31
Routing-Table/routing-table.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef ROUTINGTABLE_H
|
||||
#define ROUTINGTABLE_H
|
||||
|
||||
#define IP_ADDR_LEN 26
|
||||
#define OIF_LEN 32
|
||||
|
||||
typedef struct dll_ dll_t;
|
||||
typedef struct dll_node_ dll_node_t;
|
||||
|
||||
/*
|
||||
* Data structure defination for routing table entry
|
||||
*/
|
||||
typedef struct routing_table_entry_ {
|
||||
|
||||
char dest[IP_ADDR_LEN];
|
||||
unsigned short mask;
|
||||
char gw[IP_ADDR_LEN];
|
||||
char oif[OIF_LEN];
|
||||
|
||||
}routing_table_entry_t;
|
||||
|
||||
/*
|
||||
* Public API's for routing table functionality
|
||||
*/
|
||||
|
||||
void display_routing_table(const dll_t* routing_table);
|
||||
dll_node_t* find_routing_table_entry(const dll_t* routing_table, const char* dest,
|
||||
const unsigned short mask);
|
||||
void update(dll_node_t* node, const char* gw, const char* oif);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user