* Introduced first draft of a C++ network API. Comments welcome (I haven't
started implementing it yet, anyway). * Note that BNetworkAddress is supposed to replace BNetAddress -- the latter does not provide enough space for a struct sockaddr_storage, and has a very IPv4 specific and incapable API, anyway. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37936 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright 2010, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _NETWORK_INTERFACE_H
|
||||
#define _NETWORK_INTERFACE_H
|
||||
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/if_types.h>
|
||||
|
||||
#include <List.h>
|
||||
#include <NetworkAddress.h>
|
||||
|
||||
|
||||
class BNetworkInterface;
|
||||
|
||||
|
||||
class BNetworkInterfaceAddress {
|
||||
public:
|
||||
BNetworkInterfaceAddress();
|
||||
~BNetworkInterfaceAddress();
|
||||
|
||||
void SetAddress(BNetworkAddress& address);
|
||||
void SetMask(BNetworkAddress& mask);
|
||||
void SetBroadcast(BNetworkAddress& mask);
|
||||
|
||||
BNetworkAddress& Address() { return fAddress; }
|
||||
BNetworkAddress& Mask() { return fMask; }
|
||||
BNetworkAddress& Broadcast() { return fBroadcast; }
|
||||
|
||||
const BNetworkAddress& Address() const { return fAddress; }
|
||||
const BNetworkAddress& Mask() const { return fMask; }
|
||||
const BNetworkAddress& Broadcast() const { return fBroadcast; }
|
||||
|
||||
void SetFlags(uint32 flags);
|
||||
uint32 Flags() const { return fFlags; }
|
||||
|
||||
private:
|
||||
BNetworkInterface* fInterface;
|
||||
uint32 fIndex;
|
||||
BNetworkAddress fAddress;
|
||||
BNetworkAddress fMask;
|
||||
BNetworkAddress fBroadcast;
|
||||
uint32 fFlags;
|
||||
};
|
||||
|
||||
|
||||
class BNetworkInterface {
|
||||
public:
|
||||
BNetworkInterface();
|
||||
BNetworkInterface(const char* name);
|
||||
BNetworkInterface(uint32 index);
|
||||
~BNetworkInterface();
|
||||
|
||||
bool Exists() const;
|
||||
|
||||
const char* Name() const;
|
||||
uint32 Flags() const;
|
||||
uint32 MTU() const;
|
||||
uint32 Type() const;
|
||||
status_t GetStats(ifreq_stats& stats);
|
||||
bool HasLink() const;
|
||||
|
||||
status_t SetFlags(uint32 flags);
|
||||
status_t SetMTU(uint32 mtu);
|
||||
|
||||
uint32 CountAddresses() const;
|
||||
BNetworkInterfaceAddress* AddressAt(uint32 index);
|
||||
|
||||
status_t AddAddress(
|
||||
const BNetworkInterfaceAddress& address);
|
||||
status_t RemoveAddress(
|
||||
const BNetworkInterfaceAddress& address);
|
||||
status_t RemoveAddressAt(uint32 index);
|
||||
|
||||
status_t GetHardwareAddress(BNetworkAddress& address);
|
||||
|
||||
private:
|
||||
char fName[IF_NAMESIZE];
|
||||
uint32 fIndex;
|
||||
BList fAddresses;
|
||||
};
|
||||
|
||||
|
||||
#endif // _NETWORK_INTERFACE_H
|
||||
Reference in New Issue
Block a user