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