blob: 9b1617311eb80143517af1933ecccb70d69a09b5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <unistd.h>
#include "icmp_server.h"
#include "util.h"
int main(void) {
int sock = icmp_server_open_socket();
if (sock < 0) {
perror("icmp_server_open_socket");
return 1;
}
while (true) {
struct icmp_server_incoming msg = icmp_server_receive(sock);
if (msg.data == NULL) {
perror("icmp_server_communicate");
return 1;
}
printf("Received: type %d id %d seqnum %d data:\n", msg.type, msg.id, msg.seqnum);
xxd(msg.data, msg.length);
if (msg.type != ICMP_ECHO) {
printf("Not an ICMP_ECHO, ignoring\n");
continue;
}
if (icmp_server_send_reply(sock, msg.source_addr, msg.id, msg.seqnum, "dank je wel", 11) < 0) {
perror("icmp_server_send_reply");
}
}
close(sock);
}
|