RTM Project

This commit is contained in:
2024-05-07 22:02:08 +05:30
commit f7d7a53ade
20 changed files with 2033 additions and 0 deletions

16
Mac-List/CMakeLists.txt Normal file
View File

@@ -0,0 +1,16 @@
set(MAC_LIST_SRC
"mac-list.c")
set(MAC_LIST_HEADER
"mac-list.h")
add_library( ${ML_NAME} STATIC
${MAC_LIST_SRC}
${MAC_LIST_HEADER})
target_include_directories( ${ML_NAME} PUBLIC
"./")
target_link_libraries( ${ML_NAME} PUBLIC
${DLL_NAME}
${RT_NAME})

54
Mac-List/mac-list.c Normal file
View File

@@ -0,0 +1,54 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mac-list.h"
#include "dll.h"
#include "routing-table.h"
extern int get_IP(const char* mac, char* ip);
/*
* Display each row (entry) of a routing table.
*/
void display_mac_list(const dll_t* mac_list) {
printf("Printing MAC list\n");
dll_node_t* node = mac_list->head->next;
while (node != mac_list->head) {
mac_list_entry_t entry = *((mac_list_entry_t*) node->data);
printf("MAC: %s ", entry.mac);
char ip[IP_ADDR_LEN];
if (get_IP(entry.mac, ip) != -1) {
printf("IP: %s", ip);
}
putchar('\n');
node = node->next;
}
}
/*
* Look up entry in MAC list by MAC address.
*/
dll_node_t* find_mac(const dll_t* mac_list, const char* mac) {
dll_node_t* node = mac_list->head->next;
while (node != mac_list->head) {
mac_list_entry_t entry = *((mac_list_entry_t*)node->data);
if (!strcmp(entry.mac, mac)) {
break;
}
node = node->next;
}
return node;
}

26
Mac-List/mac-list.h Normal file
View File

@@ -0,0 +1,26 @@
#ifndef MAC_LIST_H
#define MAC_LIST_H
#define MAC_ADDR_LEN 18
typedef struct dll_ dll_t;
typedef struct dll_node_ dll_node_t;
/*
* Data structure defination for MAC
* address list entry.
*/
typedef struct mac_list_entry_ {
char mac[MAC_ADDR_LEN];
}mac_list_entry_t;
/*
* Public API's for MAC list functionality.
*/
void display_mac_list(const dll_t* mac_list);
dll_node_t* find_mac(const dll_t* mac_list, const char* mac);
#endif