Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

wvinterface.h

Go to the documentation of this file.
00001 /* -*- Mode: C++ -*- 00002 * Worldvisions Weaver Software: 00003 * Copyright (C) 1997-2002 Net Integration Technologies, Inc. 00004 * 00005 * Provides support for managing network interfaces. 00006 */ 00007 00008 #ifndef __WVINTERFACE_H 00009 #define __WVINTERFACE_H 00010 00011 #include "wvaddr.h" 00012 #include "wvhashtable.h" 00013 #include "wvlog.h" 00014 00015 struct ifreq; 00016 struct iwreq; 00017 struct rtentry; 00018 00019 /** 00020 * A WvInterface manages a particular network interface. It is _allowed_ 00021 * to have more than one WvInterface instance referring to the same 00022 * physical interface, because that is more convenient. 00023 */ 00024 class WvInterface 00025 { 00026 WvAddr *my_hwaddr; 00027 WvIPNet *my_ipaddr; 00028 00029 WvLog err; 00030 00031 00032 /** used by addroute()/delroute() */ 00033 void fill_rte(struct rtentry *rte, char ifname[17], 00034 const WvIPNet &dest, const WvIPAddr &gw, 00035 int metric); 00036 00037 int really_addroute(const WvIPNet &dest, const WvIPAddr &gw, 00038 const WvIPAddr &src, int metric, 00039 WvStringParm table, bool shutup); 00040 public: 00041 WvString name; 00042 bool valid; 00043 00044 WvInterface(WvStringParm _name); 00045 ~WvInterface(); 00046 00047 /** forget all stored information about the address(es) of this interface */ 00048 void rescan(); 00049 00050 /** get the hardware address of this interface */ 00051 const WvAddr &hwaddr(); 00052 00053 /** get the local IP net of this interface */ 00054 const WvIPNet &ipaddr(); 00055 00056 /** get the point-to-point IP address of this interface */ 00057 const WvIPAddr dstaddr(); 00058 00059 /** get the current kernel flags */ 00060 int getflags(); 00061 00062 /** toggle kernel flags on this netdevice. Be careful! */ 00063 int setflags(int clear, int set); 00064 00065 /** set the interface state up or down. */ 00066 bool isup(); 00067 void up(bool enable); 00068 00069 /** turn promiscuous (see-all-packets) mode on or off. */ 00070 bool ispromisc(); 00071 void promisc(bool enable); 00072 00073 /** 00074 * Sets the local address, netmask, and broadcast of this interface 00075 * and set a route to the local net. 00076 * 00077 * Returns 0 on success, else an error code. 00078 */ 00079 int setipaddr(const WvIPNet &addr); 00080 00081 /** 00082 * Sets the MTU of the interface. 00083 * 00084 * Returns 0 on success, else an error code. 00085 */ 00086 int setmtu(int mtu); 00087 00088 /** 00089 * Set the hardware address of this interface 00090 * 00091 * Returns 0 on success, else an error code. 00092 */ 00093 int sethwaddr(const WvAddr &addr); 00094 00095 /** add a route to the given network through this interface. */ 00096 int addroute(const WvIPNet &dest, int metric = 0, 00097 WvStringParm table = "default"); 00098 int addroute(const WvIPNet &dest, const WvIPAddr &gw, 00099 const WvIPAddr &src, int metric = 0, 00100 WvStringParm table = "default"); 00101 00102 /** delete a route to the given network through this interface. */ 00103 int delroute(const WvIPNet &dest, int metric = 0, 00104 WvStringParm table = "default"); 00105 int delroute(const WvIPNet &dest, const WvIPAddr &gw, int metric = 0, 00106 WvStringParm table = "default"); 00107 00108 /** add an ARP entry on this interface */ 00109 bool isarp(); 00110 int addarp(const WvIPNet &proto, const WvAddr &hw, bool proxy); 00111 00112 /** get/set information about an interface */ 00113 int req(int ioctl_num, struct ifreq *ifr); 00114 00115 /** get/set information about a wireless interface */ 00116 int req(int ioctl_num, struct iwreq *ifr); 00117 }; 00118 00119 DeclareWvDict2(WvInterfaceDictBase, WvInterface, WvString, name); 00120 00121 class WvInterfaceDict 00122 { 00123 public: 00124 WvLog log; 00125 static WvInterfaceDictBase slist; 00126 static int links; 00127 00128 class Iter : public WvInterfaceDictBase::Iter 00129 { 00130 public: 00131 Iter(WvInterfaceDict &l) 00132 : WvInterfaceDictBase::Iter(l.slist) 00133 { } 00134 }; 00135 00136 WvInterfaceDict(); 00137 ~WvInterfaceDict(); 00138 00139 void update(); 00140 bool islocal(const WvAddr &addr); 00141 bool on_local_net(const WvIPNet &addr); 00142 00143 WvInterface *operator[] (WvStringParm str) 00144 { return slist[str]; } 00145 00146 //operator WvInterfaceDictBase () 00147 // { return slist; } 00148 }; 00149 00150 #endif // __WVINTERFACE_H

Generated on Tue Oct 5 01:09:20 2004 for WvStreams by doxygen 1.3.7