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_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();
|
|
|
|
|
2010-08-12 17:50:32 +04:00
|
|
|
status_t SetTo(const BNetworkInterface& interface,
|
2010-08-09 20:31:40 +04:00
|
|
|
int32 index);
|
|
|
|
|
2010-08-12 17:50:32 +04:00
|
|
|
void SetAddress(const BNetworkAddress& address);
|
|
|
|
void SetMask(const BNetworkAddress& mask);
|
|
|
|
void SetBroadcast(const BNetworkAddress& broadcast);
|
|
|
|
void SetDestination(
|
|
|
|
const BNetworkAddress& destination);
|
2010-08-06 12:08:02 +04:00
|
|
|
|
|
|
|
BNetworkAddress& Address() { return fAddress; }
|
|
|
|
BNetworkAddress& Mask() { return fMask; }
|
|
|
|
BNetworkAddress& Broadcast() { return fBroadcast; }
|
2010-08-12 17:50:32 +04:00
|
|
|
BNetworkAddress& Destination() { return fBroadcast; }
|
2010-08-06 12:08:02 +04:00
|
|
|
|
|
|
|
const BNetworkAddress& Address() const { return fAddress; }
|
|
|
|
const BNetworkAddress& Mask() const { return fMask; }
|
|
|
|
const BNetworkAddress& Broadcast() const { return fBroadcast; }
|
2010-08-12 17:50:32 +04:00
|
|
|
const BNetworkAddress& Destination() const { return fBroadcast; }
|
2010-08-06 12:08:02 +04:00
|
|
|
|
|
|
|
void SetFlags(uint32 flags);
|
|
|
|
uint32 Flags() const { return fFlags; }
|
|
|
|
|
2010-08-09 20:31:40 +04:00
|
|
|
int32 Index() const { return fIndex; }
|
|
|
|
|
2010-08-06 12:08:02 +04:00
|
|
|
private:
|
2010-08-09 20:31:40 +04:00
|
|
|
int32 fIndex;
|
2010-08-06 12:08:02 +04:00
|
|
|
BNetworkAddress fAddress;
|
|
|
|
BNetworkAddress fMask;
|
|
|
|
BNetworkAddress fBroadcast;
|
|
|
|
uint32 fFlags;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class BNetworkInterface {
|
|
|
|
public:
|
|
|
|
BNetworkInterface();
|
|
|
|
BNetworkInterface(const char* name);
|
|
|
|
BNetworkInterface(uint32 index);
|
|
|
|
~BNetworkInterface();
|
|
|
|
|
2010-08-09 20:31:40 +04:00
|
|
|
void Unset();
|
|
|
|
void SetTo(const char* name);
|
|
|
|
status_t SetTo(uint32 index);
|
|
|
|
|
2010-08-06 12:08:02 +04:00
|
|
|
bool Exists() const;
|
|
|
|
|
|
|
|
const char* Name() const;
|
2010-08-09 20:31:40 +04:00
|
|
|
uint32 Index() const;
|
2010-08-06 12:08:02 +04:00
|
|
|
uint32 Flags() const;
|
|
|
|
uint32 MTU() const;
|
2010-08-12 17:50:32 +04:00
|
|
|
int32 Media() const;
|
2010-08-11 17:18:36 +04:00
|
|
|
uint32 Metric() const;
|
2010-08-06 12:08:02 +04:00
|
|
|
uint32 Type() const;
|
|
|
|
status_t GetStats(ifreq_stats& stats);
|
|
|
|
bool HasLink() const;
|
|
|
|
|
|
|
|
status_t SetFlags(uint32 flags);
|
|
|
|
status_t SetMTU(uint32 mtu);
|
2010-08-12 17:50:32 +04:00
|
|
|
status_t SetMedia(int32 media);
|
2010-08-11 17:18:36 +04:00
|
|
|
status_t SetMetric(uint32 metric);
|
2010-08-06 12:08:02 +04:00
|
|
|
|
2010-08-06 17:22:25 +04:00
|
|
|
int32 CountAddresses() const;
|
2010-08-09 20:31:40 +04:00
|
|
|
status_t GetAddressAt(int32 index,
|
|
|
|
BNetworkInterfaceAddress& address);
|
2010-08-12 17:50:32 +04:00
|
|
|
int32 FindAddress(const BNetworkAddress& address);
|
|
|
|
int32 FindFirstAddress(int family);
|
2010-08-06 12:08:02 +04:00
|
|
|
|
|
|
|
status_t AddAddress(
|
|
|
|
const BNetworkInterfaceAddress& address);
|
2010-08-12 17:50:32 +04:00
|
|
|
status_t AddAddress(const BNetworkAddress& address);
|
2010-08-09 20:31:40 +04:00
|
|
|
status_t SetAddress(
|
|
|
|
const BNetworkInterfaceAddress& address);
|
2010-08-06 12:08:02 +04:00
|
|
|
status_t RemoveAddress(
|
|
|
|
const BNetworkInterfaceAddress& address);
|
2010-08-12 17:50:32 +04:00
|
|
|
status_t RemoveAddress(const BNetworkAddress& address);
|
2010-08-06 17:22:25 +04:00
|
|
|
status_t RemoveAddressAt(int32 index);
|
2010-08-06 12:08:02 +04:00
|
|
|
|
|
|
|
status_t GetHardwareAddress(BNetworkAddress& address);
|
|
|
|
|
2010-11-24 00:03:11 +03:00
|
|
|
status_t AddRoute(const route_entry& route);
|
|
|
|
status_t AddDefaultRoute(const BNetworkAddress& gateway);
|
|
|
|
status_t RemoveRoute(const route_entry& route);
|
|
|
|
status_t RemoveRoute(int family,
|
|
|
|
const route_entry& route);
|
|
|
|
status_t RemoveDefaultRoute(int family);
|
|
|
|
|
|
|
|
status_t AutoConfigure(int family);
|
|
|
|
|
2010-08-06 12:08:02 +04:00
|
|
|
private:
|
|
|
|
char fName[IF_NAMESIZE];
|
|
|
|
BList fAddresses;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // _NETWORK_INTERFACE_H
|