mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 09:00:22 +00:00
LibC: Use IPv4Address::from_string() in gethostbyname().
This commit is contained in:
parent
dddcedfd11
commit
b6dcb5e7ae
Notes:
sideshowbarker
2024-07-19 13:22:25 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/b6dcb5e7ae2
1 changed files with 4 additions and 8 deletions
|
@ -51,17 +51,13 @@ static int connect_to_lookup_server()
|
|||
|
||||
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);
|
||||
auto ipv4_address = IPv4Address::from_string(name);
|
||||
if (ipv4_address.has_value()) {
|
||||
sprintf(__gethostbyname_name_buffer, "%s", ipv4_address.value().to_string().characters());
|
||||
__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);
|
||||
new (&__gethostbyname_address) IPv4Address(ipv4_address.value());
|
||||
__gethostbyname_address_list_buffer[0] = &__gethostbyname_address;
|
||||
__gethostbyname_address_list_buffer[1] = nullptr;
|
||||
__gethostbyname_buffer.h_addr_list = (char**)__gethostbyname_address_list_buffer;
|
||||
|
|
Loading…
Reference in a new issue