WvStreams
wvinterface.h
00001 /* -*- Mode: C++ -*-
00002  * Worldvisions Weaver Software:
00003  *   Copyright (C) 1997-2005 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 
00024 class WvInterface
00025 {
00026     WvAddr *my_hwaddr;
00027     WvIPNet *my_ipaddr;
00028     
00029     WvLog err;
00030     
00031     
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     
00048     void rescan();
00049     
00051     const WvAddr &hwaddr();
00052     
00054     const WvIPNet &ipaddr();
00055     
00057     const WvIPAddr dstaddr();
00058     
00060     int getflags();
00061     
00063     int setflags(int clear, int set);
00064 
00066     bool isup();
00067     void up(bool enable);
00068 
00070     bool ispromisc();
00071     void promisc(bool enable);
00072     
00074     int ptp(bool enable, const WvIPNet &addr);
00075     
00082     int setipaddr(const WvIPNet &addr);
00083     
00089     int setmtu(int mtu);
00090 
00096     int sethwaddr(const WvAddr &addr);
00097     
00099     int addroute(const WvIPNet &dest, int metric = 0,
00100                  WvStringParm table = "default");
00101     int addroute(const WvIPNet &dest, const WvIPAddr &gw, 
00102                  const WvIPAddr &src, int metric = 0,
00103                  WvStringParm table = "default");
00104 
00106     int delroute(const WvIPNet &dest, int metric = 0,
00107                  WvStringParm table = "default");
00108     int delroute(const WvIPNet &dest, const WvIPAddr &gw, int metric = 0,
00109                  WvStringParm table = "default");
00110     
00112     bool isarp();
00113     int addarp(const WvIPNet &proto, const WvAddr &hw, bool proxy);
00114 
00116     int req(int ioctl_num, struct ifreq *ifr);
00117 
00119     int req(int ioctl_num, struct iwreq *ifr);
00120 };
00121 
00122 DeclareWvDict2(WvInterfaceDictBase, WvInterface, WvString, name);
00123 
00124 class WvInterfaceDict
00125 {
00126 public:
00127     WvLog log;
00128     static WvInterfaceDictBase slist;
00129     static int links;
00130     
00131     class Iter : public WvInterfaceDictBase::Iter
00132     {
00133     public:
00134         Iter(WvInterfaceDict &l) 
00135             : WvInterfaceDictBase::Iter(l.slist)
00136             { }
00137     };
00138     
00139     class Sorter : public WvInterfaceDictBase::Sorter
00140     {
00141     public:
00142         Sorter(WvInterfaceDict &l,
00143                WvInterfaceDictBase::Sorter::RealCompareFunc *f)
00144             : WvInterfaceDictBase::Sorter(l.slist, f)
00145             { }
00146     };
00147     
00148     WvInterfaceDict();
00149     ~WvInterfaceDict();
00150     
00151     void update();
00152     WvString islocal(const WvAddr &addr);
00153     bool on_local_net(const WvIPNet &addr);
00154 
00155     WvInterface *operator[] (WvStringParm str)
00156         { return slist[str]; }
00157     
00158     //operator WvInterfaceDictBase ()
00159     //    { return slist; }
00160 };
00161 
00162 #endif // __WVINTERFACE_H