diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..197ac6a --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,13 @@ +{ + "files.associations": { + "ip_icmp.h": "c", + "tcp.h": "c", + "features-time64.h": "c", + "packet.h": "c", + "types.h": "c", + "socket.h": "c", + "stdint.h": "c", + "cstdint": "c", + "stdio.h": "c" + } +} \ No newline at end of file diff --git a/npcap b/npcap new file mode 100755 index 0000000..5352cf7 Binary files /dev/null and b/npcap differ diff --git a/npcap.c b/npcap.c index 3710d3f..9d3051a 100644 --- a/npcap.c +++ b/npcap.c @@ -1,11 +1,13 @@ // // Created by ako on 8/22/25. // +#define _GNU_SOURCE #include #include #include #include #include +#include #include #include #include @@ -15,7 +17,10 @@ #include "nethdr.h" #include "npcap_handle.h" #include -#include // if_nametoindex() +#include +#include +#include +#include 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; diff --git a/npcap_handle.c b/npcap_handle.c index a5f0fc2..a6703eb 100644 --- a/npcap_handle.c +++ b/npcap_handle.c @@ -67,3 +67,41 @@ int handle_ip(struct iphdr* ip) { return 0; } + +int handle_icmp(struct icmphdr* icmp) { + printf("\n\t\tICMP:\n"); + printf("\t\t\tType : %d\n", icmp->type); + printf("\t\t\tCode : %d\n", icmp->code); + printf("\t\t\tChecksum : %d\n", icmp->checksum); + return 0; +} + +int handle_tcp(struct tcphdr* tcp) { + printf("\n\t\tTCP:\n"); + printf("\t\t\tPort Source : %d\n", ntohs(tcp->source)); + printf("\t\t\tPort Destination : %d\n", ntohs(tcp->dest)); + printf("\t\t\tSeq Number : %u\n", ntohl(tcp->seq)); + printf("\t\t\tAck Number : %u\n", ntohl(tcp->ack_seq)); + printf("\t\t\tData Offset : %d\n", tcp->doff); + printf("\t\t\tFlags : "); + if (tcp->urg) printf("URG "); + if (tcp->ack) printf("ACK "); + if (tcp->psh) printf("PSH "); + if (tcp->rst) printf("RST "); + if (tcp->syn) printf("SYN "); + if (tcp->fin) printf("FIN "); + printf("\n"); + printf("\t\t\tWindow Size : %d\n", ntohs(tcp->window)); + printf("\t\t\tChecksum : %d\n", ntohs(tcp->check)); + printf("\t\t\tUrgent Pointer : %d\n", tcp->urg_ptr); + return 0; +} + +int handle_udp(struct udphdr* udp) { + printf("\n\t\tUDP:\n"); + printf("\t\t\tPort Source : %d\n", ntohs(udp->source)); + printf("\t\t\tPort Destination : %d\n", ntohs(udp->dest)); + printf("\t\t\tLength : %d\n", ntohs(udp->len)); + printf("\t\t\tChecksum : %d\n", ntohs(udp->check)); + return 0; +} \ No newline at end of file diff --git a/npcap_handle.h b/npcap_handle.h index 5120e2e..e368be4 100644 --- a/npcap_handle.h +++ b/npcap_handle.h @@ -4,10 +4,17 @@ #include "nethdr.h" #include #include +#include #include +#include +#include +#include int handle_eth(struct ethhdr* eth); int handle_arp(struct arphdr_c* arp); int handle_ip(struct iphdr* ip); +int handle_icmp(struct icmphdr* icmp); +int handle_tcp(struct tcphdr* tcp); +int handle_udp(struct udphdr* udp); #endif