1 /* 2 * Copyright 2015, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _NETWORK_ROUTE_H 6 #define _NETWORK_ROUTE_H 7 8 #include <net/route.h> 9 10 #include <ObjectList.h> 11 12 13 class BNetworkRoute { 14 public: 15 BNetworkRoute(); 16 ~BNetworkRoute(); 17 18 status_t SetTo(const BNetworkRoute& other); 19 status_t SetTo(const route_entry& routeEntry); 20 21 void Adopt(BNetworkRoute& other); 22 23 const route_entry& RouteEntry() const; 24 25 const sockaddr* Destination() const; 26 status_t SetDestination(const sockaddr& destination); 27 void UnsetDestination(); 28 29 const sockaddr* Mask() const; 30 status_t SetMask(const sockaddr& mask); 31 void UnsetMask(); 32 33 const sockaddr* Gateway() const; 34 status_t SetGateway(const sockaddr& gateway); 35 void UnsetGateway(); 36 37 const sockaddr* Source() const; 38 status_t SetSource(const sockaddr& source); 39 void UnsetSource(); 40 41 uint32 Flags() const; 42 void SetFlags(uint32 flags); 43 44 uint32 MTU() const; 45 void SetMTU(uint32 mtu); 46 47 int AddressFamily() const; 48 49 static status_t GetDefaultRoute(int family, 50 const char* interfaceName, 51 BNetworkRoute& route); 52 static status_t GetDefaultGateway(int family, 53 const char* interfaceName, 54 sockaddr& gateway); 55 56 static status_t GetRoutes(int family, 57 BObjectList<BNetworkRoute>& routes); 58 static status_t GetRoutes(int family, const char* interfaceName, 59 BObjectList<BNetworkRoute>& routes); 60 static status_t GetRoutes(int family, const char* interfaceName, 61 uint32 filterFlags, 62 BObjectList<BNetworkRoute>& routes); 63 64 private: 65 BNetworkRoute(const BNetworkRoute& other); 66 // unimplemented to disallow copying 67 68 status_t _AllocateAndSetAddress(const sockaddr& from, 69 sockaddr*& to); 70 void _FreeAndUnsetAddress(sockaddr*& address); 71 72 route_entry fRouteEntry; 73 }; 74 75 #endif // _NETWORK_ROUTE_H 76