1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:57:35 +00:00

Kernel+LibC+Userland: Yet more networking bringup hacking.

All ICMP sockets now receive all ICMP packets. All this buffering is gonna
need some limits and such.
This commit is contained in:
Andreas Kling 2019-03-12 17:27:07 +01:00
parent a017a77442
commit a7d5e9781a
14 changed files with 178 additions and 2 deletions

View file

@ -3,6 +3,7 @@
#include <netinet/ip_icmp.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <Kernel/NetworkOrdered.h>
NetworkOrdered<word> internet_checksum(const void* ptr, size_t count)
@ -41,9 +42,13 @@ int main(int argc, char** argv)
};
PingPacket ping_packet;
PingPacket pong_packet;
memset(&ping_packet, 0, sizeof(PingPacket));
ping_packet.header.type = 8; // Echo request
ping_packet.header.code = 0;
ping_packet.header.un.echo.id = htons(getpid());
ping_packet.header.un.echo.sequence = htons(1);
strcpy(ping_packet.msg, "Hello there!\n");
ping_packet.header.checksum = htons(internet_checksum(&ping_packet, sizeof(PingPacket)));
@ -54,5 +59,13 @@ int main(int argc, char** argv)
return 1;
}
rc = recvfrom(fd, &pong_packet, sizeof(PingPacket), 0, (const struct sockaddr*)&peer_address, sizeof(sockaddr_in));
if (rc < 0) {
perror("recvfrom");
return 1;
}
printf("received %p (%d)\n", &pong_packet, rc);
return 0;
}