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
15struct ifreq;
16struct iwreq;
17struct 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);
40public:
41 WvString name;
42 bool valid;
43
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
122DeclareWvDict2(WvInterfaceDictBase, WvInterface, WvString, name);
123
125{
126public:
127 WvLog log;
128 static WvInterfaceDictBase slist;
129 static int links;
130
131 class Iter : public WvInterfaceDictBase::Iter
132 {
133 public:
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
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
Base class for different address types, each of which will have the ability to convert itself to/from...
Definition: wvaddr.h:119
A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to a...
Definition: wvstring.h:94
An IP address is made up of a "dotted quad" – four decimal numbers in the form www....
Definition: wvaddr.h:250
An IP network comprises two WvIPAddr structures: an address and a netmask.
Definition: wvaddr.h:313
A WvInterface manages a particular network interface.
Definition: wvinterface.h:25
int setflags(int clear, int set)
toggle kernel flags on this netdevice.
Definition: wvinterface.cc:157
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
const WvIPAddr dstaddr()
get the point-to-point IP address of this interface
Definition: wvinterface.cc:136
bool isarp()
add an ARP entry on this interface
Definition: wvinterface.cc:581
const WvIPNet & ipaddr()
get the local IP net of this interface
Definition: wvinterface.cc:117
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
int ptp(bool enable, const WvIPNet &addr)
turn point-to-point mode on or off.
Definition: wvinterface.cc:195
int req(int ioctl_num, struct ifreq *ifr)
get/set information about an interface
Definition: wvinterface.cc:51
bool isup()
set the interface state up or down.
Definition: wvinterface.cc:183
const WvAddr & hwaddr()
get the hardware address of this interface
Definition: wvinterface.cc:101
int getflags()
get the current kernel flags
Definition: wvinterface.cc:147
void rescan()
forget all stored information about the address(es) of this interface
Definition: wvinterface.cc:84
int setmtu(int mtu)
Sets the MTU of the interface.
Definition: wvinterface.cc:286
int sethwaddr(const WvAddr &addr)
Set the hardware address of this interface.
Definition: wvinterface.cc:297
bool ispromisc()
turn promiscuous (see-all-packets) mode on or off.
Definition: wvinterface.cc:212
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
A WvLog stream accepts log messages from applications and forwards them to all registered WvLogRcv's.
Definition: wvlog.h:57
WvString is an implementation of a simple and efficient printable-string class.
Definition: wvstring.h:330