diff options
author | Toni Uhlig <matzeton@googlemail.com> | 2022-03-20 00:14:56 +0100 |
---|---|---|
committer | Toni Uhlig <matzeton@googlemail.com> | 2022-03-20 00:14:56 +0100 |
commit | 34498f719fef5d867f23344a5a2b9e8ef08c6d57 (patch) | |
tree | a79b9b2529f36b90d0f94c0dd2433a69ec87270e /src/ppkt.c | |
parent | e42e3117e767242f4682fe9e44f8e8750b167b33 (diff) |
fourth smth
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
Diffstat (limited to 'src/ppkt.c')
-rw-r--r-- | src/ppkt.c | 42 |
1 files changed, 41 insertions, 1 deletions
@@ -1,6 +1,46 @@ #include "ppkt.h" +#include "psock.h" +#include <netinet/ip.h> +#include <netinet/ip_icmp.h> -void ppkt_process_icmp(struct psock * psock) +int ppkt_process_icmp(struct psock * psock) { + if (psock->current.peer.ss_family == AF_INET) { + psock->current.packet.icmphdr = (struct icmphdr *)(psock->current.packet.buffer + sizeof(struct iphdr)); + + psock->current.packet.icmphdr->checksum = ntohs(psock->current.packet.icmphdr->checksum); + psock->current.packet.icmphdr->un.echo.id = ntohs(psock->current.packet.icmphdr->un.echo.id); + psock->current.packet.icmphdr->un.echo.sequence = ntohs(psock->current.packet.icmphdr->un.echo.sequence); + } else { + return -1; + } + + return 0; +} + +int ppkt_process_ppkt(struct psock * psock) +{ + if (psock->current.peer.ss_family == AF_INET) { + if (psock->current.packet.used < sizeof(struct iphdr) + sizeof(*psock->current.packet.icmphdr)) { + return -1; + } + + psock->current.packet.ppkt = (struct ppkt *)(psock->current.packet.buffer + sizeof(struct iphdr) + + sizeof(*psock->current.packet.icmphdr)); + } else { + return -1; + } + + psock->current.packet.ppkt->ident = ntohl(psock->current.packet.ppkt->ident); + if (psock->current.packet.ppkt->ident != PTUNNEL_IDENT) { + return -1; + } + + psock->current.packet.ppkt->total_size = ntohs(psock->current.packet.ppkt->total_size); + if (psock->current.packet.ppkt->total_size > psock->current.packet.used) { + return -1; + } + + return 0; } |