WvStreams
wvinterface.h
1 /* -*- Mode: C++ -*-
2  * Worldvisions Weaver Software:
3  * Copyright (C) 1997-2005 Net Integration Technologies, Inc.
4  *
5  * Provides support for managing network interfaces.
6  */
7 
8 #ifndef __WVINTERFACE_H
9 #define __WVINTERFACE_H
10 
11 #include "wvaddr.h"
12 #include "wvhashtable.h"
13 #include "wvlog.h"
14 
15 struct ifreq;
16 struct iwreq;
17 struct rtentry;
18 
25 {
26  WvAddr *my_hwaddr;
27  WvIPNet *my_ipaddr;
28 
29  WvLog err;
30 
31 
33  void fill_rte(struct rtentry *rte, char ifname[17],
34  const WvIPNet &dest, const WvIPAddr &gw,
35  int metric);
36 
37  int really_addroute(const WvIPNet &dest, const WvIPAddr &gw,
38  const WvIPAddr &src, int metric,
39  WvStringParm table, bool shutup);
40 public:
41  WvString name;
42  bool valid;
43 
44  WvInterface(WvStringParm _name);
45  ~WvInterface();
46 
48  void rescan();
49 
51  const WvAddr &hwaddr();
52 
54  const WvIPNet &ipaddr();
55 
57  const WvIPAddr dstaddr();
58 
60  int getflags();
61 
63  int setflags(int clear, int set);
64 
66  bool isup();
67  void up(bool enable);
68 
70  bool ispromisc();
71  void promisc(bool enable);
72 
74  int ptp(bool enable, const WvIPNet &addr);
75 
82  int setipaddr(const WvIPNet &addr);
83 
89  int setmtu(int mtu);
90 
96  int sethwaddr(const WvAddr &addr);
97 
99  int addroute(const WvIPNet &dest, int metric = 0,
100  WvStringParm table = "default");
101  int addroute(const WvIPNet &dest, const WvIPAddr &gw,
102  const WvIPAddr &src, int metric = 0,
103  WvStringParm table = "default");
104 
106  int delroute(const WvIPNet &dest, int metric = 0,
107  WvStringParm table = "default");
108  int delroute(const WvIPNet &dest, const WvIPAddr &gw, int metric = 0,
109  WvStringParm table = "default");
110 
112  bool isarp();
113  int addarp(const WvIPNet &proto, const WvAddr &hw, bool proxy);
114 
116  int req(int ioctl_num, struct ifreq *ifr);
117 
119  int req(int ioctl_num, struct iwreq *ifr);
120 };
121 
122 DeclareWvDict2(WvInterfaceDictBase, WvInterface, WvString, name);
123 
125 {
126 public:
127  WvLog log;
128  static WvInterfaceDictBase slist;
129  static int links;
130 
131  class Iter : public WvInterfaceDictBase::Iter
132  {
133  public:
134  Iter(WvInterfaceDict &l)
135  : WvInterfaceDictBase::Iter(l.slist)
136  { }
137  };
138 
139  class Sorter : public WvInterfaceDictBase::Sorter
140  {
141  public:
143  WvInterfaceDictBase::Sorter::RealCompareFunc *f)
144  : WvInterfaceDictBase::Sorter(l.slist, f)
145  { }
146  };
147 
148  WvInterfaceDict();
149  ~WvInterfaceDict();
150 
151  void update();
152  WvString islocal(const WvAddr &addr);
153  bool on_local_net(const WvIPNet &addr);
154 
155  WvInterface *operator[] (WvStringParm str)
156  { return slist[str]; }
157 
158  //operator WvInterfaceDictBase ()
159  // { return slist; }
160 };
161 
162 #endif // __WVINTERFACE_H
WvInterface::ispromisc
bool ispromisc()
turn promiscuous (see-all-packets) mode on or off.
Definition: wvinterface.cc:212
WvInterface::isup
bool isup()
set the interface state up or down.
Definition: wvinterface.cc:183
WvInterface::req
int req(int ioctl_num, struct ifreq *ifr)
get/set information about an interface
Definition: wvinterface.cc:51
WvIPNet
An IP network comprises two WvIPAddr structures: an address and a netmask.
Definition: wvaddr.h:312
WvInterfaceDict::Iter
Definition: wvinterface.h:131
WvInterfaceDict
Definition: wvinterface.h:124
WvInterface::hwaddr
const WvAddr & hwaddr()
get the hardware address of this interface
Definition: wvinterface.cc:101
WvInterfaceDict::Sorter
Definition: wvinterface.h:139
WvInterface::ptp
int ptp(bool enable, const WvIPNet &addr)
turn point-to-point mode on or off.
Definition: wvinterface.cc:195
WvString
WvString is an implementation of a simple and efficient printable-string class.
Definition: wvstring.h:329
WvInterface::getflags
int getflags()
get the current kernel flags
Definition: wvinterface.cc:147
WvLog
A WvLog stream accepts log messages from applications and forwards them to all registered WvLogRcv's.
Definition: wvlog.h:56
WvInterface::setflags
int setflags(int clear, int set)
toggle kernel flags on this netdevice.
Definition: wvinterface.cc:157
WvInterface::rescan
void rescan()
forget all stored information about the address(es) of this interface
Definition: wvinterface.cc:84
WvInterface::setmtu
int setmtu(int mtu)
Sets the MTU of the interface.
Definition: wvinterface.cc:286
WvInterface::ipaddr
const WvIPNet & ipaddr()
get the local IP net of this interface
Definition: wvinterface.cc:117
WvInterface::dstaddr
const WvIPAddr dstaddr()
get the point-to-point IP address of this interface
Definition: wvinterface.cc:136
WvInterface::addroute
int addroute(const WvIPNet &dest, int metric=0, WvStringParm table="default")
add a route to the given network through this interface.
Definition: wvinterface.cc:472
WvAddr
Base class for different address types, each of which will have the ability to convert itself to/from...
Definition: wvaddr.h:118
WvInterface
A WvInterface manages a particular network interface.
Definition: wvinterface.h:24
WvInterface::sethwaddr
int sethwaddr(const WvAddr &addr)
Set the hardware address of this interface.
Definition: wvinterface.cc:297
WvIPAddr
An IP address is made up of a "dotted quad" – four decimal numbers in the form www....
Definition: wvaddr.h:249
WvInterface::delroute
int delroute(const WvIPNet &dest, int metric=0, WvStringParm table="default")
delete a route to the given network through this interface.
Definition: wvinterface.cc:532
WvInterface::setipaddr
int setipaddr(const WvIPNet &addr)
Sets the local address, netmask, and broadcast of this interface and set a route to the local net.
Definition: wvinterface.cc:218
WvInterface::isarp
bool isarp()
add an ARP entry on this interface
Definition: wvinterface.cc:581