From 612695e259405a63e70cf3470af06f4defea3aff Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Wed, 20 Dec 2017 10:32:27 +0100 Subject: [PATCH] started working on ICMP probing code --- probe.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/probe.c b/probe.c index 6752c40..a6671b3 100644 --- a/probe.c +++ b/probe.c @@ -29,6 +29,7 @@ #include #include +#include #include "ts.h" #include "timing.h" @@ -44,6 +45,45 @@ struct phdr { uint16_t length; } __attribute__((packed)); +#if 0 +#define PAYLOAD_LEN (sizeof(float) * 8); + +int probe_icmp(int sd, unsigned short dport, struct timespec *ts) +{ + struct timespec ts_req, ts_rep; + + char buf[sizeof(struct iphdr) + sizeof(struct icmphdr) + PAYLOAD_LEN]; + + struct iphdr *ihdr = (struct iphdr *) buf; + struct icmphdr *ichdr = (struct icmphdr *) (ihdr + 1); + char *payload = (char *) (ichdr + 1); + + struct msghdr msgh; + struct iovec iov = { + .iov_base = ichdr, + .iov_len = sizeof(struct icmphdr) + PAYLOAD_LEN // ICMP header + }; + + memset(buf, 0, sizeof(buf)); + + ichdr->type = ICMP_ECHO; + ichdr->code = 0; + ichdr->checksum = 0; + ichdr->echo.id = 1; + ichdr->echo.sequence = rand(); + + ichdr->checksum = chksum_rfc1071(ichdr, sizeof(struct icmphdr)); + + msgh.msg_iov = &iov; + msgh.msg_iovlen = 1; + + if (ts_sendmsg(sd, &msgh, 0, &ts_req)) + error(-1, errno, "Failed to send ICMP echo request"); + + // TODO +} +#endif + int probe_tcp(int sd, unsigned short dport, struct in_addr src, struct in_addr dst, struct timespec *ts) { struct timespec ts_syn, ts_ack;