summaryrefslogtreecommitdiff
path: root/client.c
diff options
context:
space:
mode:
authorTom Smeding <tom.smeding@gmail.com>2018-07-23 15:48:44 +0200
committerTom Smeding <tom.smeding@gmail.com>2018-07-23 15:48:44 +0200
commit5722c47aa3402f1458da9eec332153a454a540b7 (patch)
treef1bfaa8c89dc39c6b9ae0bf7ff54eb524b1468eb /client.c
Initial version
Working ping back and forth with specified data, and data arrives at the other party. Currently, the server uses nflog to get the pings, which: 1. requires iptables settings to work; 2. buffers and collects messages for a second. Both are suboptimal, and I believe raw sockets can improve on this.
Diffstat (limited to 'client.c')
-rw-r--r--client.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/client.c b/client.c
new file mode 100644
index 0000000..527375f
--- /dev/null
+++ b/client.c
@@ -0,0 +1,30 @@
+#include <stdio.h>
+#include <stddef.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netinet/ip_icmp.h>
+#include <arpa/inet.h>
+#include <unistd.h>
+#include "icmp.h"
+#include "util.h"
+
+int main(void) {
+ int sock = icmp_open_socket();
+ if (sock < 0) {
+ perror("icmp_open_socket");
+ return 1;
+ }
+
+ const char *ip_address = "127.0.0.1";
+ // const char *ip_address = "192.168.43.220";
+
+ struct icmp_reply reply = icmp_communicate(sock, ip_address, 1234, "kaashandel", 10);
+ if (reply.data == NULL) {
+ perror("icmp_communicate");
+ return 1;
+ }
+
+ printf("Received length: %zd\nPayload:\n", reply.length);
+ xxd(reply.data, reply.length);
+}