mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-11 01:06:01 +03:00
GSocket: Add a connect() overload that takes a hostname instead of an IP.
This commit is contained in:
parent
ff93d3f362
commit
76ce68ac48
Notes:
sideshowbarker
2024-07-19 14:51:10 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/76ce68ac48c
@ -3,6 +3,7 @@
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <stdio.h>
|
||||
#include <netdb.h>
|
||||
|
||||
GSocket::GSocket(Type type, GObject* parent)
|
||||
: GIODevice(parent)
|
||||
@ -14,6 +15,19 @@ GSocket::~GSocket()
|
||||
{
|
||||
}
|
||||
|
||||
bool GSocket::connect(const String& hostname, int port)
|
||||
{
|
||||
auto* hostent = gethostbyname(hostname.characters());
|
||||
if (!hostent) {
|
||||
dbgprintf("GSocket::connect: Unable to resolve '%s'\n", hostname.characters());
|
||||
return false;
|
||||
}
|
||||
|
||||
IPv4Address host_address((const byte*)hostent->h_addr_list[0]);
|
||||
dbgprintf("GSocket::connect: Resolved '%s' to %s\n", hostname.characters(), host_address.to_string().characters());
|
||||
return connect(host_address, port);
|
||||
}
|
||||
|
||||
bool GSocket::connect(const GSocketAddress& address, int port)
|
||||
{
|
||||
ASSERT(!is_connected());
|
||||
|
@ -37,6 +37,7 @@ public:
|
||||
enum class Type { Invalid, TCP, UDP };
|
||||
virtual ~GSocket() override;
|
||||
|
||||
bool connect(const String& hostname, int port);
|
||||
bool connect(const GSocketAddress&, int port);
|
||||
|
||||
ByteBuffer receive(int max_size);
|
||||
|
Loading…
Reference in New Issue
Block a user