Skip to content

Commit

Permalink
net/SocketAddress: move code to IsInet()
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Jan 15, 2024
1 parent 18060b0 commit 016b8bf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
9 changes: 5 additions & 4 deletions src/net/AllocatedSocketAddress.hxx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// SPDX-License-Identifier: BSD-2-Clause
// author: Max Kellermann <[email protected]>

#ifndef ALLOCATED_SOCKET_ADDRESS_HXX
#define ALLOCATED_SOCKET_ADDRESS_HXX
#pragma once

#include "SocketAddress.hxx" // IWYU pragma: export
#include "Features.hxx"
Expand Down Expand Up @@ -117,6 +116,10 @@ public:
size = 0;
}

bool IsInet() const noexcept {
return GetFamily() == AF_INET || GetFamily() == AF_INET6;
}

#ifdef HAVE_UN
/**
* @see SocketAddress::GetLocalRaw()
Expand Down Expand Up @@ -191,5 +194,3 @@ public:
private:
void SetSize(size_type new_size) noexcept;
};

#endif
15 changes: 7 additions & 8 deletions src/net/SocketAddress.hxx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// SPDX-License-Identifier: BSD-2-Clause
// author: Max Kellermann <[email protected]>

#ifndef SOCKET_ADDRESS_HXX
#define SOCKET_ADDRESS_HXX
#pragma once

#include "Features.hxx"

Expand Down Expand Up @@ -95,6 +94,10 @@ public:
return GetFamily() != AF_UNSPEC;
}

constexpr bool IsInet() const noexcept {
return GetFamily() == AF_INET || GetFamily() == AF_INET6;
}

#ifdef HAVE_UN
/**
* Extract the local socket path (which may begin with a null
Expand Down Expand Up @@ -135,10 +138,8 @@ public:
/**
* Does the address family support port numbers?
*/
[[gnu::pure]]
bool HasPort() const noexcept {
return !IsNull() &&
(GetFamily() == AF_INET || GetFamily() == AF_INET6);
constexpr bool HasPort() const noexcept {
return !IsNull() && IsInet();
}

/**
Expand Down Expand Up @@ -173,5 +174,3 @@ public:
return !(*this == other);
}
};

#endif
4 changes: 4 additions & 0 deletions src/net/StaticSocketAddress.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ public:
address.ss_family = AF_UNSPEC;
}

constexpr bool IsInet() const noexcept {
return GetFamily() == AF_INET || GetFamily() == AF_INET6;
}

#ifdef HAVE_UN
/**
* @see SocketAddress::GetLocalRaw()
Expand Down

0 comments on commit 016b8bf

Please sign in to comment.