2 * Copyright 2010, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 #ifndef _NETWORK_INTERFACE_H
6 #define _NETWORK_INTERFACE_H
10 #include <net/if_types.h>
12 #include <ObjectList.h>
13 #include <NetworkAddress.h>
16 class BNetworkInterface
;
20 class BNetworkInterfaceAddress
{
22 BNetworkInterfaceAddress();
23 ~BNetworkInterfaceAddress();
25 status_t
SetTo(const BNetworkInterface
& interface
,
28 void SetAddress(const BNetworkAddress
& address
);
29 void SetMask(const BNetworkAddress
& mask
);
30 void SetBroadcast(const BNetworkAddress
& broadcast
);
32 const BNetworkAddress
& destination
);
34 BNetworkAddress
& Address() { return fAddress
; }
35 BNetworkAddress
& Mask() { return fMask
; }
36 BNetworkAddress
& Broadcast() { return fBroadcast
; }
37 BNetworkAddress
& Destination() { return fBroadcast
; }
39 const BNetworkAddress
& Address() const { return fAddress
; }
40 const BNetworkAddress
& Mask() const { return fMask
; }
41 const BNetworkAddress
& Broadcast() const { return fBroadcast
; }
42 const BNetworkAddress
& Destination() const { return fBroadcast
; }
44 void SetFlags(uint32 flags
);
45 uint32
Flags() const { return fFlags
; }
47 int32
Index() const { return fIndex
; }
51 BNetworkAddress fAddress
;
52 BNetworkAddress fMask
;
53 BNetworkAddress fBroadcast
;
58 class BNetworkInterface
{
61 BNetworkInterface(const char* name
);
62 BNetworkInterface(uint32 index
);
66 void SetTo(const char* name
);
67 status_t
SetTo(uint32 index
);
71 const char* Name() const;
76 uint32
Metric() const;
78 status_t
GetStats(ifreq_stats
& stats
);
81 status_t
SetFlags(uint32 flags
);
82 status_t
SetMTU(uint32 mtu
);
83 status_t
SetMedia(int32 media
);
84 status_t
SetMetric(uint32 metric
);
86 int32
CountAddresses() const;
87 status_t
GetAddressAt(int32 index
,
88 BNetworkInterfaceAddress
& address
);
89 int32
FindAddress(const BNetworkAddress
& address
);
90 int32
FindFirstAddress(int family
);
93 const BNetworkInterfaceAddress
& address
);
94 status_t
AddAddress(const BNetworkAddress
& address
);
96 const BNetworkInterfaceAddress
& address
);
97 status_t
RemoveAddress(
98 const BNetworkInterfaceAddress
& address
);
99 status_t
RemoveAddress(const BNetworkAddress
& address
);
100 status_t
RemoveAddressAt(int32 index
);
102 status_t
GetHardwareAddress(BNetworkAddress
& address
);
104 status_t
AddRoute(const BNetworkRoute
& route
);
105 status_t
AddDefaultRoute(const BNetworkAddress
& gateway
);
106 status_t
RemoveRoute(const BNetworkRoute
& route
);
107 status_t
RemoveRoute(int family
,
108 const BNetworkRoute
& route
);
109 status_t
RemoveDefaultRoute(int family
);
110 status_t
GetRoutes(int family
,
111 BObjectList
<BNetworkRoute
>& routes
) const;
112 status_t
GetDefaultRoute(int family
,
113 BNetworkRoute
& route
) const;
114 status_t
GetDefaultGateway(int family
,
115 BNetworkAddress
& gateway
) const;
117 status_t
AutoConfigure(int family
);
120 char fName
[IF_NAMESIZE
];
125 #endif // _NETWORK_INTERFACE_H