2010-08-06 12:08:02 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2010, Haiku, Inc. All Rights Reserved.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
|
|
|
#ifndef _NETWORK_ADDRESS_H
|
|
|
|
#define _NETWORK_ADDRESS_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet6/in6.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
|
|
|
#include <Archivable.h>
|
2010-08-12 15:27:14 +04:00
|
|
|
#include <NetworkAddressResolver.h>
|
2010-08-09 20:31:40 +04:00
|
|
|
#include <String.h>
|
2010-08-06 12:08:02 +04:00
|
|
|
|
|
|
|
|
|
|
|
class BNetworkAddress : public BArchivable {
|
|
|
|
public:
|
|
|
|
BNetworkAddress();
|
|
|
|
BNetworkAddress(const char* address,
|
2010-08-12 15:27:14 +04:00
|
|
|
uint16 port = 0, uint32 flags = 0);
|
|
|
|
BNetworkAddress(const char* address,
|
|
|
|
const char* service, uint32 flags = 0);
|
|
|
|
BNetworkAddress(int family, const char* address,
|
|
|
|
uint16 port = 0, uint32 flags = 0);
|
|
|
|
BNetworkAddress(int family, const char* address,
|
|
|
|
const char* service, uint32 flags = 0);
|
2010-08-09 20:31:40 +04:00
|
|
|
BNetworkAddress(const sockaddr& address);
|
|
|
|
BNetworkAddress(
|
|
|
|
const sockaddr_storage& address);
|
|
|
|
BNetworkAddress(const sockaddr_in& address);
|
|
|
|
BNetworkAddress(const sockaddr_in6& address);
|
|
|
|
BNetworkAddress(const sockaddr_dl& address);
|
2010-08-06 12:08:02 +04:00
|
|
|
BNetworkAddress(const in_addr_t address);
|
|
|
|
BNetworkAddress(const in6_addr* address);
|
|
|
|
BNetworkAddress(const BNetworkAddress& other);
|
|
|
|
BNetworkAddress(BMessage* archive);
|
|
|
|
virtual ~BNetworkAddress();
|
|
|
|
|
|
|
|
status_t InitCheck() const;
|
|
|
|
|
|
|
|
void Unset();
|
|
|
|
|
2010-08-12 15:27:14 +04:00
|
|
|
status_t SetTo(const char* address, uint16 port = 0,
|
|
|
|
uint32 flags = 0);
|
|
|
|
status_t SetTo(const char* address, const char* service,
|
|
|
|
uint32 flags = 0);
|
|
|
|
status_t SetTo(int family, const char* address,
|
|
|
|
uint16 port = 0, uint32 flags = 0);
|
2010-08-06 12:08:02 +04:00
|
|
|
status_t SetTo(int family, const char* address,
|
2010-08-12 15:27:14 +04:00
|
|
|
const char* service, uint32 flags = 0);
|
2010-08-09 20:31:40 +04:00
|
|
|
void SetTo(const sockaddr& address);
|
2010-08-12 15:27:14 +04:00
|
|
|
void SetTo(const sockaddr& address, size_t length);
|
2010-08-09 20:31:40 +04:00
|
|
|
void SetTo(const sockaddr_storage& address);
|
|
|
|
void SetTo(const sockaddr_in& address);
|
|
|
|
void SetTo(const sockaddr_in6& address);
|
|
|
|
void SetTo(const sockaddr_dl& address);
|
2010-08-06 12:08:02 +04:00
|
|
|
void SetTo(const in_addr_t address);
|
|
|
|
void SetTo(const in6_addr* address);
|
|
|
|
void SetTo(const BNetworkAddress& other);
|
|
|
|
|
|
|
|
status_t SetToBroadcast(int family, uint16 port = 0);
|
|
|
|
status_t SetToLocal();
|
|
|
|
status_t SetToLoopback();
|
|
|
|
status_t SetToMask(int family, uint32 prefixLength);
|
|
|
|
status_t SetToWildcard(int family);
|
|
|
|
void SetPort(uint16 port);
|
2010-08-12 15:27:14 +04:00
|
|
|
status_t SetPort(const char* service);
|
2010-08-06 12:08:02 +04:00
|
|
|
|
|
|
|
void SetToLinkLevel(uint8* address, size_t length);
|
|
|
|
void SetToLinkLevel(const char* name);
|
|
|
|
void SetToLinkLevel(uint32 index);
|
|
|
|
void SetLinkLevelIndex(uint32 index);
|
|
|
|
void SetLinkLevelType(uint32 type);
|
|
|
|
void SetLinkLevelFrameType(uint32 frameType);
|
|
|
|
|
|
|
|
int Family() const;
|
|
|
|
uint16 Port() const;
|
|
|
|
size_t Length() const;
|
2010-08-09 20:31:40 +04:00
|
|
|
const sockaddr& SockAddr() const;
|
2010-08-18 19:41:33 +04:00
|
|
|
sockaddr& SockAddr();
|
2010-08-06 12:08:02 +04:00
|
|
|
|
|
|
|
bool IsEmpty() const;
|
|
|
|
bool IsWildcard() const;
|
|
|
|
bool IsBroadcast() const;
|
|
|
|
bool IsMulticast() const;
|
|
|
|
bool IsMulticastGlobal() const;
|
|
|
|
bool IsMulticastNodeLocal() const;
|
|
|
|
bool IsMulticastLinkLocal() const;
|
|
|
|
bool IsMulticastSiteLocal() const;
|
|
|
|
bool IsMulticastOrgLocal() const;
|
|
|
|
bool IsLinkLocal() const;
|
|
|
|
bool IsSiteLocal() const;
|
|
|
|
bool IsLocal() const;
|
2010-08-18 19:41:33 +04:00
|
|
|
|
2010-08-11 17:53:31 +04:00
|
|
|
ssize_t PrefixLength() const;
|
|
|
|
|
2010-08-06 12:08:02 +04:00
|
|
|
uint32 LinkLevelIndex() const;
|
|
|
|
BString LinkLevelInterface() const;
|
|
|
|
uint32 LinkLevelType() const;
|
|
|
|
uint32 LinkLevelFrameType() const;
|
|
|
|
uint8* LinkLevelAddress() const;
|
|
|
|
size_t LinkLevelAddressLength() const;
|
|
|
|
|
2010-08-09 20:31:40 +04:00
|
|
|
status_t ResolveForDestination(
|
|
|
|
const BNetworkAddress& destination);
|
|
|
|
status_t ResolveTo(const BNetworkAddress& address);
|
2010-08-06 12:08:02 +04:00
|
|
|
|
2010-08-09 20:31:40 +04:00
|
|
|
BString ToString(bool includePort = true) const;
|
2010-08-06 12:08:02 +04:00
|
|
|
BString HostName() const;
|
2010-08-12 15:27:14 +04:00
|
|
|
BString ServiceName() const;
|
2010-08-06 12:08:02 +04:00
|
|
|
|
|
|
|
virtual status_t Archive(BMessage* into, bool deep = true) const;
|
|
|
|
static BArchivable* Instantiate(BMessage* archive);
|
|
|
|
|
2010-08-09 20:31:40 +04:00
|
|
|
bool Equals(const BNetworkAddress& other,
|
|
|
|
bool includePort = true) const;
|
|
|
|
|
2010-08-06 12:08:02 +04:00
|
|
|
BNetworkAddress& operator=(const BNetworkAddress& other);
|
|
|
|
|
|
|
|
bool operator==(const BNetworkAddress& other) const;
|
|
|
|
bool operator!=(const BNetworkAddress& other) const;
|
|
|
|
bool operator<(const BNetworkAddress& other) const;
|
|
|
|
|
2010-08-12 15:27:14 +04:00
|
|
|
operator const sockaddr*() const;
|
|
|
|
operator const sockaddr&() const;
|
2010-08-18 19:41:33 +04:00
|
|
|
operator sockaddr*();
|
|
|
|
operator sockaddr&();
|
2010-08-06 12:08:02 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
sockaddr_storage fAddress;
|
|
|
|
status_t fStatus;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // _NETWORK_ADDRESS_H
|