1ff1b1ac7SAxel Dörfler /* 2ff1b1ac7SAxel Dörfler * Copyright 2010, Haiku, Inc. All Rights Reserved. 3ff1b1ac7SAxel Dörfler * Distributed under the terms of the MIT License. 4ff1b1ac7SAxel Dörfler */ 5ff1b1ac7SAxel Dörfler #ifndef _NETWORK_INTERFACE_H 6ff1b1ac7SAxel Dörfler #define _NETWORK_INTERFACE_H 7ff1b1ac7SAxel Dörfler 8ff1b1ac7SAxel Dörfler 9ff1b1ac7SAxel Dörfler #include <net/if.h> 10ff1b1ac7SAxel Dörfler #include <net/if_types.h> 11ff1b1ac7SAxel Dörfler 12ff1b1ac7SAxel Dörfler #include <List.h> 13ff1b1ac7SAxel Dörfler #include <NetworkAddress.h> 14ff1b1ac7SAxel Dörfler 15ff1b1ac7SAxel Dörfler 16ff1b1ac7SAxel Dörfler class BNetworkInterface; 17ff1b1ac7SAxel Dörfler 18ff1b1ac7SAxel Dörfler 19ff1b1ac7SAxel Dörfler class BNetworkInterfaceAddress { 20ff1b1ac7SAxel Dörfler public: 21ff1b1ac7SAxel Dörfler BNetworkInterfaceAddress(); 22ff1b1ac7SAxel Dörfler ~BNetworkInterfaceAddress(); 23ff1b1ac7SAxel Dörfler 24*c2808ea7SAxel Dörfler status_t SetTo(BNetworkInterface& interface, 25*c2808ea7SAxel Dörfler int32 index); 26*c2808ea7SAxel Dörfler 27ff1b1ac7SAxel Dörfler void SetAddress(BNetworkAddress& address); 28ff1b1ac7SAxel Dörfler void SetMask(BNetworkAddress& mask); 29*c2808ea7SAxel Dörfler void SetBroadcast(BNetworkAddress& broadcast); 30ff1b1ac7SAxel Dörfler 31ff1b1ac7SAxel Dörfler BNetworkAddress& Address() { return fAddress; } 32ff1b1ac7SAxel Dörfler BNetworkAddress& Mask() { return fMask; } 33ff1b1ac7SAxel Dörfler BNetworkAddress& Broadcast() { return fBroadcast; } 34ff1b1ac7SAxel Dörfler 35ff1b1ac7SAxel Dörfler const BNetworkAddress& Address() const { return fAddress; } 36ff1b1ac7SAxel Dörfler const BNetworkAddress& Mask() const { return fMask; } 37ff1b1ac7SAxel Dörfler const BNetworkAddress& Broadcast() const { return fBroadcast; } 38ff1b1ac7SAxel Dörfler 39ff1b1ac7SAxel Dörfler void SetFlags(uint32 flags); 40ff1b1ac7SAxel Dörfler uint32 Flags() const { return fFlags; } 41ff1b1ac7SAxel Dörfler 42*c2808ea7SAxel Dörfler int32 Index() const { return fIndex; } 43*c2808ea7SAxel Dörfler 44ff1b1ac7SAxel Dörfler private: 45*c2808ea7SAxel Dörfler int32 fIndex; 46ff1b1ac7SAxel Dörfler BNetworkAddress fAddress; 47ff1b1ac7SAxel Dörfler BNetworkAddress fMask; 48ff1b1ac7SAxel Dörfler BNetworkAddress fBroadcast; 49ff1b1ac7SAxel Dörfler uint32 fFlags; 50ff1b1ac7SAxel Dörfler }; 51ff1b1ac7SAxel Dörfler 52ff1b1ac7SAxel Dörfler 53ff1b1ac7SAxel Dörfler class BNetworkInterface { 54ff1b1ac7SAxel Dörfler public: 55ff1b1ac7SAxel Dörfler BNetworkInterface(); 56ff1b1ac7SAxel Dörfler BNetworkInterface(const char* name); 57ff1b1ac7SAxel Dörfler BNetworkInterface(uint32 index); 58ff1b1ac7SAxel Dörfler ~BNetworkInterface(); 59ff1b1ac7SAxel Dörfler 60*c2808ea7SAxel Dörfler void Unset(); 61*c2808ea7SAxel Dörfler void SetTo(const char* name); 62*c2808ea7SAxel Dörfler status_t SetTo(uint32 index); 63*c2808ea7SAxel Dörfler 64ff1b1ac7SAxel Dörfler bool Exists() const; 65ff1b1ac7SAxel Dörfler 66ff1b1ac7SAxel Dörfler const char* Name() const; 67*c2808ea7SAxel Dörfler uint32 Index() const; 68ff1b1ac7SAxel Dörfler uint32 Flags() const; 69ff1b1ac7SAxel Dörfler uint32 MTU() const; 70ff1b1ac7SAxel Dörfler uint32 Type() const; 71ff1b1ac7SAxel Dörfler status_t GetStats(ifreq_stats& stats); 72ff1b1ac7SAxel Dörfler bool HasLink() const; 73ff1b1ac7SAxel Dörfler 74ff1b1ac7SAxel Dörfler status_t SetFlags(uint32 flags); 75ff1b1ac7SAxel Dörfler status_t SetMTU(uint32 mtu); 76ff1b1ac7SAxel Dörfler 77bf58f252SAxel Dörfler int32 CountAddresses() const; 78*c2808ea7SAxel Dörfler status_t GetAddressAt(int32 index, 79*c2808ea7SAxel Dörfler BNetworkInterfaceAddress& address); 80ff1b1ac7SAxel Dörfler 81ff1b1ac7SAxel Dörfler status_t AddAddress( 82ff1b1ac7SAxel Dörfler const BNetworkInterfaceAddress& address); 83*c2808ea7SAxel Dörfler status_t SetAddress( 84*c2808ea7SAxel Dörfler const BNetworkInterfaceAddress& address); 85ff1b1ac7SAxel Dörfler status_t RemoveAddress( 86ff1b1ac7SAxel Dörfler const BNetworkInterfaceAddress& address); 87bf58f252SAxel Dörfler status_t RemoveAddressAt(int32 index); 88ff1b1ac7SAxel Dörfler 89ff1b1ac7SAxel Dörfler status_t GetHardwareAddress(BNetworkAddress& address); 90ff1b1ac7SAxel Dörfler 91ff1b1ac7SAxel Dörfler private: 92ff1b1ac7SAxel Dörfler char fName[IF_NAMESIZE]; 93ff1b1ac7SAxel Dörfler BList fAddresses; 94ff1b1ac7SAxel Dörfler }; 95ff1b1ac7SAxel Dörfler 96ff1b1ac7SAxel Dörfler 97ff1b1ac7SAxel Dörfler #endif // _NETWORK_INTERFACE_H 98