1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:48:14 +00:00

More work on IPv4 sockets and /bin/ping.

It's now actually possible to ping other hosts on the network! :^)
I've switched the "run" script over to starting QEMU with user networking
since that works better for my testing needs right now.
This commit is contained in:
Andreas Kling 2019-03-13 03:26:01 +01:00
parent ce7c302933
commit cf250e1245
7 changed files with 125 additions and 38 deletions

View file

@ -11,9 +11,41 @@ const char* inet_ntop(int af, const void* src, char* dst, socklen_t len)
return nullptr;
}
auto* bytes = (const unsigned char*)src;
snprintf(dst, len, "%u.%u.%u.%u", bytes[3], bytes[2], bytes[1], bytes[0]);
snprintf(dst, len, "%u.%u.%u.%u", bytes[0], bytes[1], bytes[2], bytes[3]);
return (const char*)dst;
}
int inet_pton(int af, const char* src, void* dst)
{
if (af != AF_INET) {
errno = EAFNOSUPPORT;
return -1;
}
unsigned a;
unsigned b;
unsigned c;
unsigned d;
int count = sscanf(src, "%u.%u.%u.%u", &a, &b, &c, &d);
if (count != 4) {
errno = EINVAL;
return -1;
}
union {
struct {
uint8_t a;
uint8_t b;
uint8_t c;
uint8_t d;
};
uint32_t l;
} u;
u.a = a;
u.b = b;
u.c = c;
u.d = d;
*(uint32_t*)dst = u.l;
return 0;
}
}