haiku/headers/os/net/NetworkAddress.h
Axel Dörfler 28de0904dc * Added non-const sockaddr casts.
* Automatic whitespace cleanup.
* This also fixes the build; I wanted to commit this earlier.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38237 a95241bf-73f2-0310-859d-f6bbb57e9c96
2010-08-18 15:41:33 +00:00

139 lines
4.5 KiB
C++

/*
* 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>
#include <NetworkAddressResolver.h>
#include <String.h>
class BNetworkAddress : public BArchivable {
public:
BNetworkAddress();
BNetworkAddress(const char* address,
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);
BNetworkAddress(const sockaddr& address);
BNetworkAddress(
const sockaddr_storage& address);
BNetworkAddress(const sockaddr_in& address);
BNetworkAddress(const sockaddr_in6& address);
BNetworkAddress(const sockaddr_dl& address);
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();
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);
status_t SetTo(int family, const char* address,
const char* service, uint32 flags = 0);
void SetTo(const sockaddr& address);
void SetTo(const sockaddr& address, size_t length);
void SetTo(const sockaddr_storage& address);
void SetTo(const sockaddr_in& address);
void SetTo(const sockaddr_in6& address);
void SetTo(const sockaddr_dl& address);
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);
status_t SetPort(const char* service);
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;
const sockaddr& SockAddr() const;
sockaddr& SockAddr();
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;
ssize_t PrefixLength() const;
uint32 LinkLevelIndex() const;
BString LinkLevelInterface() const;
uint32 LinkLevelType() const;
uint32 LinkLevelFrameType() const;
uint8* LinkLevelAddress() const;
size_t LinkLevelAddressLength() const;
status_t ResolveForDestination(
const BNetworkAddress& destination);
status_t ResolveTo(const BNetworkAddress& address);
BString ToString(bool includePort = true) const;
BString HostName() const;
BString ServiceName() const;
virtual status_t Archive(BMessage* into, bool deep = true) const;
static BArchivable* Instantiate(BMessage* archive);
bool Equals(const BNetworkAddress& other,
bool includePort = true) const;
BNetworkAddress& operator=(const BNetworkAddress& other);
bool operator==(const BNetworkAddress& other) const;
bool operator!=(const BNetworkAddress& other) const;
bool operator<(const BNetworkAddress& other) const;
operator const sockaddr*() const;
operator const sockaddr&() const;
operator sockaddr*();
operator sockaddr&();
private:
sockaddr_storage fAddress;
status_t fStatus;
};
#endif // _NETWORK_ADDRESS_H