mirror of
https://github.com/Hizenberg469/Routing-Table-Manager.git
synced 2026-04-20 02:12:25 +03:00
RTM Project
This commit is contained in:
54
Mac-List/mac-list.c
Normal file
54
Mac-List/mac-list.c
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user