serenity/Kernel/Net/LoopbackAdapter.cpp
Liav A bd7d4513bf Kernel/Net: Make the LoopbackAdapter initializer to use ErrorOr pattern
This looks much more nice, and also matches our pattern for other types
of network adapters' initializers.
2023-04-14 19:27:56 +02:00

37 lines
959 B
C++

/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Singleton.h>
#include <Kernel/Net/LoopbackAdapter.h>
namespace Kernel {
static bool s_loopback_initialized = false;
ErrorOr<NonnullRefPtr<LoopbackAdapter>> LoopbackAdapter::try_create()
{
auto interface_name = TRY(KString::try_create("loop"sv));
return TRY(adopt_nonnull_ref_or_enomem(new (nothrow) LoopbackAdapter(move(interface_name))));
}
LoopbackAdapter::LoopbackAdapter(NonnullOwnPtr<KString> interface_name)
: NetworkAdapter(move(interface_name))
{
VERIFY(!s_loopback_initialized);
s_loopback_initialized = true;
set_mtu(65536);
set_mac_address({ 19, 85, 2, 9, 0x55, 0xaa });
}
LoopbackAdapter::~LoopbackAdapter() = default;
void LoopbackAdapter::send_raw(ReadonlyBytes payload)
{
dbgln("LoopbackAdapter: Sending {} byte(s) to myself.", payload.size());
did_receive(payload);
}
}