- added instructions how to update the online documentation
[bochs-mirror.git] / iodev / eth.cc
blobad3001eb9bc1c659ede6dd92bed8ace291225f01
1 /////////////////////////////////////////////////////////////////////////
2 // $Id: eth.cc,v 1.27 2008/12/11 18:01:56 vruppert Exp $
3 /////////////////////////////////////////////////////////////////////////
4 //
5 // Copyright (C) 2001 MandrakeSoft S.A.
6 //
7 // MandrakeSoft S.A.
8 // 43, rue d'Aboukir
9 // 75002 Paris - France
10 // http://www.linux-mandrake.com/
11 // http://www.mandrakesoft.com/
13 // This library is free software; you can redistribute it and/or
14 // modify it under the terms of the GNU Lesser General Public
15 // License as published by the Free Software Foundation; either
16 // version 2 of the License, or (at your option) any later version.
18 // This library is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 // Lesser General Public License for more details.
23 // You should have received a copy of the GNU Lesser General Public
24 // License along with this library; if not, write to the Free Software
25 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 // eth.cc - helper code to find and create pktmover classes
29 // Peter Grehan (grehan@iprg.nokia.com) coded all of this
30 // NE2000/ether stuff.
32 // Define BX_PLUGGABLE in files that can be compiled into plugins. For
33 // platforms that require a special tag on exported symbols, BX_PLUGGABLE
34 // is used to know when we are exporting symbols and when we are importing.
35 #define BX_PLUGGABLE
37 #define NO_DEVICE_INCLUDES
38 #include "iodev.h"
40 #if BX_NETWORKING
42 #include "eth.h"
44 #define LOG_THIS /* not needed */
46 eth_locator_c *eth_locator_c::all;
49 // Each pktmover module has a static locator class that registers
50 // here
52 eth_locator_c::eth_locator_c(const char *type)
54 next = all;
55 all = this;
56 this->type = type;
59 #ifdef ETH_NULL
60 extern class bx_null_locator_c bx_null_match;
61 #endif
62 #ifdef ETH_FBSD
63 extern class bx_fbsd_locator_c bx_fbsd_match;
64 #endif
65 #ifdef ETH_LINUX
66 extern class bx_linux_locator_c bx_linux_match;
67 #endif
68 #ifdef ETH_WIN32
69 extern class bx_win32_locator_c bx_win32_match;
70 #endif
71 #if HAVE_ETHERTAP
72 extern class bx_tap_locator_c bx_tap_match;
73 #endif
74 #if HAVE_TUNTAP
75 extern class bx_tuntap_locator_c bx_tuntap_match;
76 #endif
77 #if HAVE_VDE
78 extern class bx_vde_locator_c bx_vde_match;
79 #endif
80 #ifdef ETH_ARPBACK
81 extern class bx_arpback_locator_c bx_arpback_match;
82 #endif
83 extern class bx_vnet_locator_c bx_vnet_match;
86 // Called by ethernet chip emulations to locate and create a pktmover
87 // object
89 eth_pktmover_c *
90 eth_locator_c::create(const char *type, const char *netif,
91 const char *macaddr,
92 eth_rx_handler_t rxh, void *rxarg, const char *script)
94 #ifdef eth_static_constructors
95 for (eth_locator_c *p = all; p != NULL; p = p->next) {
96 if (strcmp(type, p->type) == 0)
97 return (p->allocate(netif, macaddr, rxh, rxarg, script));
99 #else
100 eth_locator_c *ptr = 0;
102 #ifdef ETH_ARPBACK
104 if (!strcmp(type, "arpback"))
105 ptr = (eth_locator_c *) &bx_arpback_match;
107 #endif
108 #ifdef ETH_NULL
110 if (!strcmp(type, "null"))
111 ptr = (eth_locator_c *) &bx_null_match;
113 #endif
114 #ifdef ETH_FBSD
116 if (!strcmp(type, "fbsd"))
117 ptr = (eth_locator_c *) &bx_fbsd_match;
119 #endif
120 #ifdef ETH_LINUX
122 if (!strcmp(type, "linux"))
123 ptr = (eth_locator_c *) &bx_linux_match;
125 #endif
126 #if HAVE_TUNTAP
128 if (!strcmp(type, "tuntap"))
129 ptr = (eth_locator_c *) &bx_tuntap_match;
131 #endif
132 #if HAVE_VDE
134 if (!strcmp(type, "vde"))
135 ptr = (eth_locator_c *) &bx_vde_match;
137 #endif
138 #if HAVE_ETHERTAP
140 if (!strcmp(type, "tap"))
141 ptr = (eth_locator_c *) &bx_tap_match;
143 #endif
144 #ifdef ETH_WIN32
146 if(!strcmp(type, "win32"))
147 ptr = (eth_locator_c *) &bx_win32_match;
149 #endif
151 if (!strcmp(type, "vnet"))
152 ptr = (eth_locator_c *) &bx_vnet_match;
154 if (ptr)
155 return (ptr->allocate(netif, macaddr, rxh, rxarg, script));
156 #endif
158 return (NULL);
161 #if (HAVE_ETHERTAP==1) || (HAVE_TUNTAP==1) || (HAVE_VDE==1)
163 extern "C" {
164 #include <sys/wait.h>
167 #undef LOG_THIS
168 #define LOG_THIS bx_devices.pluginNE2kDevice->
170 // This is a utility script used for tuntap or ethertap
171 int execute_script(const char* scriptname, char* arg1)
173 int pid,status;
175 if (!(pid=fork())) {
176 char filename[BX_PATHNAME_LEN];
177 if (scriptname[0]=='/') {
178 strcpy(filename, scriptname);
180 else {
181 getcwd(filename, BX_PATHNAME_LEN);
182 strcat(filename, "/");
183 strcat(filename, scriptname);
186 // execute the script
187 BX_INFO(("Executing script '%s %s'",filename,arg1));
188 execle(filename, scriptname, arg1, NULL, NULL);
190 // if we get here there has been a problem
191 exit(-1);
194 wait (&status);
195 if (!WIFEXITED(status)) {
196 return -1;
198 return WEXITSTATUS(status);
201 #endif // (HAVE_ETHERTAP==1) || (HAVE_TUNTAP==1)
203 #endif /* if BX_NETWORKING */