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 Type() const; 71 status_t GetStats(ifreq_stats& stats); 72 bool HasLink() const; 73 74 status_t SetFlags(uint32 flags); 75 status_t SetMTU(uint32 mtu); 76 77 int32 CountAddresses() const; 78 status_t GetAddressAt(int32 index, 79 BNetworkInterfaceAddress& address); 80 81 status_t AddAddress( 82 const BNetworkInterfaceAddress& address); 83 status_t SetAddress( 84 const BNetworkInterfaceAddress& address); 85 status_t RemoveAddress( 86 const BNetworkInterfaceAddress& address); 87 status_t RemoveAddressAt(int32 index); 88 89 status_t GetHardwareAddress(BNetworkAddress& address); 90 91 private: 92 char fName[IF_NAMESIZE]; 93 BList fAddresses; 94 }; 95 96 97 #endif // _NETWORK_INTERFACE_H 98