feat: added basic tcp, udp and icmp handling

This commit is contained in:
Emi Aline Boucly 2025-08-23 00:22:48 +02:00
parent a85bcc8ca2
commit 885be66d5e
5 changed files with 70 additions and 4 deletions

16
npcap.c
View file

@ -1,11 +1,13 @@
//
// Created by ako on 8/22/25.
//
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netinet/ip.h>
#include <netinet/if_ether.h>
@ -15,7 +17,10 @@
#include "nethdr.h"
#include "npcap_handle.h"
#include <netpacket/packet.h>
#include <net/if.h> // if_nametoindex()
#include <net/if.h>
#include <netinet/ip_icmp.h>
#include <netinet/tcp.h>
#include <netinet/udp.h>
void cleanup(int socket, unsigned char* buffer) {
close(socket);
@ -103,13 +108,16 @@ int main()
switch (ip->protocol) {
case 0x01:
handle_icmp();
struct icmphdr *icmp = (struct icmphdr *) (buffer + sizeof(struct ethhdr) + ip->ihl * 4);
handle_icmp(icmp);
break;
case 0x06:
handle_tcp();
struct tcphdr *tcp = (struct tcphdr *) (buffer + sizeof(struct ethhdr) + ip->ihl * 4);
handle_tcp(tcp);
break;
case 0x11:
handle_udp();
struct udphdr *udp = (struct udphdr *) (buffer + sizeof(struct ethhdr) + ip->ihl * 4);
handle_udp(udp);
break;
default:
break;