mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 11:37:44 +00:00
LibC: Let gethostbyname() handle IPv4 address as input.
It would be neat to do a reverse lookup too, but for now we just parse the IPv4 address into a dword.
This commit is contained in:
parent
f47945759b
commit
696f9c5bc0
1 changed files with 19 additions and 0 deletions
|
@ -17,6 +17,25 @@ static in_addr_t* __gethostbyname_address_list_buffer[2];
|
||||||
|
|
||||||
hostent* gethostbyname(const char* name)
|
hostent* gethostbyname(const char* name)
|
||||||
{
|
{
|
||||||
|
unsigned a;
|
||||||
|
unsigned b;
|
||||||
|
unsigned c;
|
||||||
|
unsigned d;
|
||||||
|
int count = sscanf(name, "%u.%u.%u.%u", &a, &b, &c, &d);
|
||||||
|
if (count == 4 && a < 256 && b < 256 && c < 256 && d < 256) {
|
||||||
|
sprintf(__gethostbyname_name_buffer, "%u.%u.%u.%u", a, b, c, d);
|
||||||
|
__gethostbyname_buffer.h_name = __gethostbyname_name_buffer;
|
||||||
|
__gethostbyname_buffer.h_aliases = nullptr;
|
||||||
|
__gethostbyname_buffer.h_addrtype = AF_INET;
|
||||||
|
new (&__gethostbyname_address) IPv4Address(a, b, c, d);
|
||||||
|
__gethostbyname_address_list_buffer[0] = &__gethostbyname_address;
|
||||||
|
__gethostbyname_address_list_buffer[1] = nullptr;
|
||||||
|
__gethostbyname_buffer.h_addr_list = (char**)__gethostbyname_address_list_buffer;
|
||||||
|
__gethostbyname_buffer.h_length = 4;
|
||||||
|
|
||||||
|
return &__gethostbyname_buffer;
|
||||||
|
}
|
||||||
|
|
||||||
int fd = socket(AF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0);
|
int fd = socket(AF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
perror("socket");
|
perror("socket");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue