* Adapted API as needed, and implemented most of the C++ API - it's completely
untested at this point, though. * Will port ifconfig, NetworkStatus, and the Network preferences application later in order to test the API. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37988 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <Archivable.h>
|
||||
#include <String.h>
|
||||
|
||||
|
||||
class BNetworkAddress : public BArchivable {
|
||||
@@ -21,10 +22,12 @@ public:
|
||||
const char* address, uint16 port = 0);
|
||||
BNetworkAddress(const char* address,
|
||||
uint16 port = 0);
|
||||
BNetworkAddress(const sockaddr* address);
|
||||
BNetworkAddress(const sockaddr_in* address);
|
||||
BNetworkAddress(const sockaddr_in6* address);
|
||||
BNetworkAddress(const sockaddr_dl* address);
|
||||
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);
|
||||
@@ -38,10 +41,11 @@ public:
|
||||
status_t SetTo(int family, const char* address,
|
||||
uint16 port = 0);
|
||||
status_t SetTo(const char* address, uint16 port = 0);
|
||||
void SetTo(const sockaddr* address);
|
||||
void SetTo(const sockaddr_in* address);
|
||||
void SetTo(const sockaddr_in6* address);
|
||||
void SetTo(const sockaddr_dl* address);
|
||||
void SetTo(const sockaddr& address);
|
||||
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);
|
||||
@@ -63,6 +67,7 @@ public:
|
||||
int Family() const;
|
||||
uint16 Port() const;
|
||||
size_t Length() const;
|
||||
const sockaddr& SockAddr() const;
|
||||
|
||||
bool IsEmpty() const;
|
||||
bool IsWildcard() const;
|
||||
@@ -84,17 +89,20 @@ public:
|
||||
uint8* LinkLevelAddress() const;
|
||||
size_t LinkLevelAddressLength() const;
|
||||
|
||||
BNetworkAddress ResolvedForDestination(
|
||||
const BNetworkAddress& destination) const;
|
||||
void ResolveTo(const BNetworkAddress& address);
|
||||
status_t ResolveForDestination(
|
||||
const BNetworkAddress& destination);
|
||||
status_t ResolveTo(const BNetworkAddress& address);
|
||||
|
||||
BString ToString() const;
|
||||
BString ToString(bool includePort = true) const;
|
||||
BString HostName() const;
|
||||
BString PortName() 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;
|
||||
|
||||
@@ -21,9 +21,12 @@ public:
|
||||
BNetworkInterfaceAddress();
|
||||
~BNetworkInterfaceAddress();
|
||||
|
||||
status_t SetTo(BNetworkInterface& interface,
|
||||
int32 index);
|
||||
|
||||
void SetAddress(BNetworkAddress& address);
|
||||
void SetMask(BNetworkAddress& mask);
|
||||
void SetBroadcast(BNetworkAddress& mask);
|
||||
void SetBroadcast(BNetworkAddress& broadcast);
|
||||
|
||||
BNetworkAddress& Address() { return fAddress; }
|
||||
BNetworkAddress& Mask() { return fMask; }
|
||||
@@ -36,9 +39,10 @@ public:
|
||||
void SetFlags(uint32 flags);
|
||||
uint32 Flags() const { return fFlags; }
|
||||
|
||||
int32 Index() const { return fIndex; }
|
||||
|
||||
private:
|
||||
BNetworkInterface* fInterface;
|
||||
uint32 fIndex;
|
||||
int32 fIndex;
|
||||
BNetworkAddress fAddress;
|
||||
BNetworkAddress fMask;
|
||||
BNetworkAddress fBroadcast;
|
||||
@@ -53,9 +57,14 @@ public:
|
||||
BNetworkInterface(uint32 index);
|
||||
~BNetworkInterface();
|
||||
|
||||
void Unset();
|
||||
void SetTo(const char* name);
|
||||
status_t SetTo(uint32 index);
|
||||
|
||||
bool Exists() const;
|
||||
|
||||
const char* Name() const;
|
||||
uint32 Index() const;
|
||||
uint32 Flags() const;
|
||||
uint32 MTU() const;
|
||||
uint32 Type() const;
|
||||
@@ -66,10 +75,13 @@ public:
|
||||
status_t SetMTU(uint32 mtu);
|
||||
|
||||
int32 CountAddresses() const;
|
||||
BNetworkInterfaceAddress* AddressAt(int32 index);
|
||||
status_t GetAddressAt(int32 index,
|
||||
BNetworkInterfaceAddress& address);
|
||||
|
||||
status_t AddAddress(
|
||||
const BNetworkInterfaceAddress& address);
|
||||
status_t SetAddress(
|
||||
const BNetworkInterfaceAddress& address);
|
||||
status_t RemoveAddress(
|
||||
const BNetworkInterfaceAddress& address);
|
||||
status_t RemoveAddressAt(int32 index);
|
||||
@@ -78,7 +90,6 @@ public:
|
||||
|
||||
private:
|
||||
char fName[IF_NAMESIZE];
|
||||
uint32 fIndex;
|
||||
BList fAddresses;
|
||||
};
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#define _NETWORK_ROSTER_H
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
#include <Locker.h>
|
||||
|
||||
|
||||
class BMessenger;
|
||||
@@ -17,14 +17,14 @@ class BNetworkRoster {
|
||||
public:
|
||||
static BNetworkRoster& Default();
|
||||
|
||||
int32 CountInterfaces();
|
||||
BNetworkInterface* InterfaceAt(int32 index);
|
||||
size_t CountInterfaces() const;
|
||||
status_t GetNextInterface(uint32* cookie,
|
||||
BNetworkInterface& interface) const;
|
||||
|
||||
status_t AddInterface(
|
||||
const BNetworkInterface& interface);
|
||||
status_t RemoveInterface(
|
||||
const BNetworkInterface& interface);
|
||||
status_t RemoveInterfaceAt(int32 index);
|
||||
|
||||
status_t StartWatching(const BMessenger& target,
|
||||
uint32 eventMask);
|
||||
@@ -33,6 +33,9 @@ public:
|
||||
private:
|
||||
BNetworkRoster();
|
||||
~BNetworkRoster();
|
||||
|
||||
private:
|
||||
static BNetworkRoster sDefault;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user