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 12905f910eSStefano Ceccherini #include <ObjectList.h> 1377206143SAxel Dörfler #include <NetworkAddress.h> 14ff1b1ac7SAxel Dörfler 15ff1b1ac7SAxel Dörfler 16ff1b1ac7SAxel Dörfler class BNetworkInterface; 17*3b7b927dSMichael Lotz class BNetworkRoute; 18ff1b1ac7SAxel Dörfler 19ff1b1ac7SAxel Dörfler 20ff1b1ac7SAxel Dörfler class BNetworkInterfaceAddress { 21ff1b1ac7SAxel Dörfler public: 22ff1b1ac7SAxel Dörfler BNetworkInterfaceAddress(); 23ff1b1ac7SAxel Dörfler ~BNetworkInterfaceAddress(); 24ff1b1ac7SAxel Dörfler 2577206143SAxel Dörfler status_t SetTo(const BNetworkInterface& interface, 26c2808ea7SAxel Dörfler int32 index); 27c2808ea7SAxel Dörfler 2877206143SAxel Dörfler void SetAddress(const BNetworkAddress& address); 2977206143SAxel Dörfler void SetMask(const BNetworkAddress& mask); 3077206143SAxel Dörfler void SetBroadcast(const BNetworkAddress& broadcast); 3177206143SAxel Dörfler void SetDestination( 3277206143SAxel Dörfler const BNetworkAddress& destination); 33ff1b1ac7SAxel Dörfler Address()3477206143SAxel Dörfler BNetworkAddress& Address() { return fAddress; } Mask()3577206143SAxel Dörfler BNetworkAddress& Mask() { return fMask; } Broadcast()3677206143SAxel Dörfler BNetworkAddress& Broadcast() { return fBroadcast; } Destination()3777206143SAxel Dörfler BNetworkAddress& Destination() { return fBroadcast; } 3877206143SAxel Dörfler Address()3977206143SAxel Dörfler const BNetworkAddress& Address() const { return fAddress; } Mask()4077206143SAxel Dörfler const BNetworkAddress& Mask() const { return fMask; } Broadcast()4177206143SAxel Dörfler const BNetworkAddress& Broadcast() const { return fBroadcast; } Destination()4277206143SAxel Dörfler const BNetworkAddress& Destination() const { return fBroadcast; } 43ff1b1ac7SAxel Dörfler 44ff1b1ac7SAxel Dörfler void SetFlags(uint32 flags); Flags()45ff1b1ac7SAxel Dörfler uint32 Flags() const { return fFlags; } 46ff1b1ac7SAxel Dörfler Index()47c2808ea7SAxel Dörfler int32 Index() const { return fIndex; } 48c2808ea7SAxel Dörfler 49ff1b1ac7SAxel Dörfler private: 50c2808ea7SAxel Dörfler int32 fIndex; 5177206143SAxel Dörfler BNetworkAddress fAddress; 5277206143SAxel Dörfler BNetworkAddress fMask; 5377206143SAxel Dörfler BNetworkAddress fBroadcast; 54ff1b1ac7SAxel Dörfler uint32 fFlags; 55ff1b1ac7SAxel Dörfler }; 56ff1b1ac7SAxel Dörfler 57ff1b1ac7SAxel Dörfler 58ff1b1ac7SAxel Dörfler class BNetworkInterface { 59ff1b1ac7SAxel Dörfler public: 60ff1b1ac7SAxel Dörfler BNetworkInterface(); 61ff1b1ac7SAxel Dörfler BNetworkInterface(const char* name); 62ff1b1ac7SAxel Dörfler BNetworkInterface(uint32 index); 63ff1b1ac7SAxel Dörfler ~BNetworkInterface(); 64ff1b1ac7SAxel Dörfler 65c2808ea7SAxel Dörfler void Unset(); 66c2808ea7SAxel Dörfler void SetTo(const char* name); 67c2808ea7SAxel Dörfler status_t SetTo(uint32 index); 68c2808ea7SAxel Dörfler 69ff1b1ac7SAxel Dörfler bool Exists() const; 70ff1b1ac7SAxel Dörfler 71ff1b1ac7SAxel Dörfler const char* Name() const; 72c2808ea7SAxel Dörfler uint32 Index() const; 73ff1b1ac7SAxel Dörfler uint32 Flags() const; 74ff1b1ac7SAxel Dörfler uint32 MTU() const; 7597ef73e0SAxel Dörfler int32 Media() const; 769de96be3SAxel Dörfler uint32 Metric() const; 77ff1b1ac7SAxel Dörfler uint32 Type() const; 78ff1b1ac7SAxel Dörfler status_t GetStats(ifreq_stats& stats); 79ff1b1ac7SAxel Dörfler bool HasLink() const; 80ff1b1ac7SAxel Dörfler 81ff1b1ac7SAxel Dörfler status_t SetFlags(uint32 flags); 82ff1b1ac7SAxel Dörfler status_t SetMTU(uint32 mtu); 8397ef73e0SAxel Dörfler status_t SetMedia(int32 media); 849de96be3SAxel Dörfler status_t SetMetric(uint32 metric); 85ff1b1ac7SAxel Dörfler 86bf58f252SAxel Dörfler int32 CountAddresses() const; 87c2808ea7SAxel Dörfler status_t GetAddressAt(int32 index, 88c2808ea7SAxel Dörfler BNetworkInterfaceAddress& address); 8997ef73e0SAxel Dörfler int32 FindAddress(const BNetworkAddress& address); 9097ef73e0SAxel Dörfler int32 FindFirstAddress(int family); 91ff1b1ac7SAxel Dörfler 92ff1b1ac7SAxel Dörfler status_t AddAddress( 93ff1b1ac7SAxel Dörfler const BNetworkInterfaceAddress& address); 9497ef73e0SAxel Dörfler status_t AddAddress(const BNetworkAddress& address); 95c2808ea7SAxel Dörfler status_t SetAddress( 96c2808ea7SAxel Dörfler const BNetworkInterfaceAddress& address); 97ff1b1ac7SAxel Dörfler status_t RemoveAddress( 98ff1b1ac7SAxel Dörfler const BNetworkInterfaceAddress& address); 9997ef73e0SAxel Dörfler status_t RemoveAddress(const BNetworkAddress& address); 100bf58f252SAxel Dörfler status_t RemoveAddressAt(int32 index); 101ff1b1ac7SAxel Dörfler 102ff1b1ac7SAxel Dörfler status_t GetHardwareAddress(BNetworkAddress& address); 103ff1b1ac7SAxel Dörfler 104*3b7b927dSMichael Lotz status_t AddRoute(const BNetworkRoute& route); 1052087545cSAxel Dörfler status_t AddDefaultRoute(const BNetworkAddress& gateway); 106*3b7b927dSMichael Lotz status_t RemoveRoute(const BNetworkRoute& route); 1072087545cSAxel Dörfler status_t RemoveRoute(int family, 108*3b7b927dSMichael Lotz const BNetworkRoute& route); 1092087545cSAxel Dörfler status_t RemoveDefaultRoute(int family); 110db6d25ceSAxel Dörfler status_t GetRoutes(int family, 111*3b7b927dSMichael Lotz BObjectList<BNetworkRoute>& routes) const; 112db6d25ceSAxel Dörfler status_t GetDefaultRoute(int family, 113*3b7b927dSMichael Lotz BNetworkRoute& route) const; 114*3b7b927dSMichael Lotz status_t GetDefaultGateway(int family, 115db6d25ceSAxel Dörfler BNetworkAddress& gateway) const; 1162087545cSAxel Dörfler 1172087545cSAxel Dörfler status_t AutoConfigure(int family); 1182087545cSAxel Dörfler 119ff1b1ac7SAxel Dörfler private: 120ff1b1ac7SAxel Dörfler char fName[IF_NAMESIZE]; 121ff1b1ac7SAxel Dörfler BList fAddresses; 122ff1b1ac7SAxel Dörfler }; 123ff1b1ac7SAxel Dörfler 124ff1b1ac7SAxel Dörfler 125ff1b1ac7SAxel Dörfler #endif // _NETWORK_INTERFACE_H 126