00001
00002
00003
00004
00005
00006 #ifndef __WVINTERFACE_H
00007 #define __WVINTERFACE_H
00008
00009 #include "wvaddr.h"
00010 #include "wvhashtable.h"
00011 #include "wvlog.h"
00012
00013 struct ifreq;
00014 struct rtentry;
00015
00021 class WvInterface
00022 {
00023 WvAddr *my_hwaddr;
00024 WvIPNet *my_ipaddr;
00025
00026 WvLog err;
00027
00031 int getinfo(struct ifreq *ifr, int ioctl_num);
00032
00036 void fill_rte(struct rtentry *rte, char *ifname,
00037 const WvIPNet &dest, const WvIPAddr &gw,
00038 int metric);
00039
00040 public:
00041 WvString name;
00042 bool valid;
00043
00044 WvInterface(const WvString &_name);
00045 ~WvInterface();
00046
00050 void rescan();
00051
00055 const WvAddr &hwaddr();
00056
00060 const WvIPNet &ipaddr();
00061
00065 const WvIPAddr dstaddr();
00066
00070 int getflags();
00071
00075 int setflags(int clear, int set);
00076
00080 bool isup();
00081 void up(bool enable);
00082
00086 bool ispromisc();
00087 void promisc(bool enable);
00088
00093 int setipaddr(const WvIPNet &addr);
00094
00098 int setmtu(int mtu);
00099
00103 int addroute(const WvIPNet &dest, int metric = 0,
00104 const WvString &table = "default");
00105 int addroute(const WvIPNet &dest, const WvIPAddr &gw, int metric = 0,
00106 const WvString &table = "default");
00107
00111 int delroute(const WvIPNet &dest, int metric = 0,
00112 const WvString &table = "default");
00113 int delroute(const WvIPNet &dest, const WvIPAddr &gw, int metric = 0,
00114 const WvString &table = "default");
00115
00119 bool isarp();
00120 int addarp(const WvIPNet &proto, const WvAddr &hw, bool proxy);
00121 };
00122
00123 DeclareWvDict3(WvInterface, WvInterfaceDictBase, WvString, name, );
00124
00125 class WvInterfaceDict
00126 {
00127 public:
00128 WvLog log;
00129 static WvInterfaceDictBase slist;
00130 static int links;
00131
00132 class Iter : public WvInterfaceDictBase::Iter
00133 {
00134 public:
00135 Iter(WvInterfaceDict &l)
00136 : WvInterfaceDictBase::Iter(l.slist)
00137 { }
00138 };
00139
00140 WvInterfaceDict();
00141 ~WvInterfaceDict();
00142
00143 void update();
00144 bool islocal(const WvAddr &addr);
00145 bool on_local_net(const WvIPNet &addr);
00146
00147 WvInterface *operator[] (const WvString &str)
00148 { return slist[str]; }
00149
00150 operator WvInterfaceDictBase ()
00151 { return slist; }
00152 };
00153
00154 #endif // __WVINTERFACE_H