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 12*905f910eSStefano Ceccherini #include <ObjectList.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 2497ef73e0SAxel Dörfler status_t SetTo(const BNetworkInterface& interface, 25c2808ea7SAxel Dörfler int32 index); 26c2808ea7SAxel Dörfler 2797ef73e0SAxel Dörfler void SetAddress(const BNetworkAddress& address); 2897ef73e0SAxel Dörfler void SetMask(const BNetworkAddress& mask); 2997ef73e0SAxel Dörfler void SetBroadcast(const BNetworkAddress& broadcast); 3097ef73e0SAxel Dörfler void SetDestination( 3197ef73e0SAxel Dörfler const BNetworkAddress& destination); 32ff1b1ac7SAxel Dörfler 33ff1b1ac7SAxel Dörfler BNetworkAddress& Address() { return fAddress; } 34ff1b1ac7SAxel Dörfler BNetworkAddress& Mask() { return fMask; } 35ff1b1ac7SAxel Dörfler BNetworkAddress& Broadcast() { return fBroadcast; } 3697ef73e0SAxel Dörfler BNetworkAddress& Destination() { return fBroadcast; } 37ff1b1ac7SAxel Dörfler 38ff1b1ac7SAxel Dörfler const BNetworkAddress& Address() const { return fAddress; } 39ff1b1ac7SAxel Dörfler const BNetworkAddress& Mask() const { return fMask; } 40ff1b1ac7SAxel Dörfler const BNetworkAddress& Broadcast() const { return fBroadcast; } 4197ef73e0SAxel Dörfler const BNetworkAddress& Destination() const { return fBroadcast; } 42ff1b1ac7SAxel Dörfler 43ff1b1ac7SAxel Dörfler void SetFlags(uint32 flags); 44ff1b1ac7SAxel Dörfler uint32 Flags() const { return fFlags; } 45ff1b1ac7SAxel Dörfler 46c2808ea7SAxel Dörfler int32 Index() const { return fIndex; } 47c2808ea7SAxel Dörfler 48ff1b1ac7SAxel Dörfler private: 49c2808ea7SAxel Dörfler int32 fIndex; 50ff1b1ac7SAxel Dörfler BNetworkAddress fAddress; 51ff1b1ac7SAxel Dörfler BNetworkAddress fMask; 52ff1b1ac7SAxel Dörfler BNetworkAddress fBroadcast; 53ff1b1ac7SAxel Dörfler uint32 fFlags; 54ff1b1ac7SAxel Dörfler }; 55ff1b1ac7SAxel Dörfler 56ff1b1ac7SAxel Dörfler 57ff1b1ac7SAxel Dörfler class BNetworkInterface { 58ff1b1ac7SAxel Dörfler public: 59ff1b1ac7SAxel Dörfler BNetworkInterface(); 60ff1b1ac7SAxel Dörfler BNetworkInterface(const char* name); 61ff1b1ac7SAxel Dörfler BNetworkInterface(uint32 index); 62ff1b1ac7SAxel Dörfler ~BNetworkInterface(); 63ff1b1ac7SAxel Dörfler 64c2808ea7SAxel Dörfler void Unset(); 65c2808ea7SAxel Dörfler void SetTo(const char* name); 66c2808ea7SAxel Dörfler status_t SetTo(uint32 index); 67c2808ea7SAxel Dörfler 68ff1b1ac7SAxel Dörfler bool Exists() const; 69ff1b1ac7SAxel Dörfler 70ff1b1ac7SAxel Dörfler const char* Name() const; 71c2808ea7SAxel Dörfler uint32 Index() const; 72ff1b1ac7SAxel Dörfler uint32 Flags() const; 73ff1b1ac7SAxel Dörfler uint32 MTU() const; 7497ef73e0SAxel Dörfler int32 Media() const; 759de96be3SAxel Dörfler uint32 Metric() const; 76ff1b1ac7SAxel Dörfler uint32 Type() const; 77ff1b1ac7SAxel Dörfler status_t GetStats(ifreq_stats& stats); 78ff1b1ac7SAxel Dörfler bool HasLink() const; 79ff1b1ac7SAxel Dörfler 80ff1b1ac7SAxel Dörfler status_t SetFlags(uint32 flags); 81ff1b1ac7SAxel Dörfler status_t SetMTU(uint32 mtu); 8297ef73e0SAxel Dörfler status_t SetMedia(int32 media); 839de96be3SAxel Dörfler status_t SetMetric(uint32 metric); 84ff1b1ac7SAxel Dörfler 85bf58f252SAxel Dörfler int32 CountAddresses() const; 86c2808ea7SAxel Dörfler status_t GetAddressAt(int32 index, 87c2808ea7SAxel Dörfler BNetworkInterfaceAddress& address); 8897ef73e0SAxel Dörfler int32 FindAddress(const BNetworkAddress& address); 8997ef73e0SAxel Dörfler int32 FindFirstAddress(int family); 90ff1b1ac7SAxel Dörfler 91ff1b1ac7SAxel Dörfler status_t AddAddress( 92ff1b1ac7SAxel Dörfler const BNetworkInterfaceAddress& address); 9397ef73e0SAxel Dörfler status_t AddAddress(const BNetworkAddress& address); 94c2808ea7SAxel Dörfler status_t SetAddress( 95c2808ea7SAxel Dörfler const BNetworkInterfaceAddress& address); 96ff1b1ac7SAxel Dörfler status_t RemoveAddress( 97ff1b1ac7SAxel Dörfler const BNetworkInterfaceAddress& address); 9897ef73e0SAxel Dörfler status_t RemoveAddress(const BNetworkAddress& address); 99bf58f252SAxel Dörfler status_t RemoveAddressAt(int32 index); 100ff1b1ac7SAxel Dörfler 101ff1b1ac7SAxel Dörfler status_t GetHardwareAddress(BNetworkAddress& address); 102ff1b1ac7SAxel Dörfler 1032087545cSAxel Dörfler status_t AddRoute(const route_entry& route); 1042087545cSAxel Dörfler status_t AddDefaultRoute(const BNetworkAddress& gateway); 1052087545cSAxel Dörfler status_t RemoveRoute(const route_entry& route); 1062087545cSAxel Dörfler status_t RemoveRoute(int family, 1072087545cSAxel Dörfler const route_entry& route); 1082087545cSAxel Dörfler status_t RemoveDefaultRoute(int family); 109*905f910eSStefano Ceccherini status_t GetRoutes(BObjectList<route_entry>& routes) const; 110*905f910eSStefano Ceccherini status_t GetDefaultRoute(BNetworkAddress& gateway) const; 1112087545cSAxel Dörfler 1122087545cSAxel Dörfler status_t AutoConfigure(int family); 1132087545cSAxel Dörfler 114ff1b1ac7SAxel Dörfler private: 115ff1b1ac7SAxel Dörfler char fName[IF_NAMESIZE]; 116ff1b1ac7SAxel Dörfler BList fAddresses; 117ff1b1ac7SAxel Dörfler }; 118ff1b1ac7SAxel Dörfler 119ff1b1ac7SAxel Dörfler 120ff1b1ac7SAxel Dörfler #endif // _NETWORK_INTERFACE_H 121