VirtualBox

source: vbox/trunk/src/VBox/Main/generic/DhcpServerRunner.cpp@ 17981

Last change on this file since 17981 was 17940, checked in by vboxsync, 16 years ago

dhcp runner fixes + disabled launching code

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.3 KB
Line 
1/* $Id: DhcpServerRunner.cpp 17940 2009-03-16 14:47:42Z vboxsync $ */
2/** @file
3 * VirtualBox Main - interface for VBox DHCP server
4 */
5
6/*
7 * Copyright (C) 2009 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21#include "DhcpServerRunner.h"
22#include <iprt/process.h>
23#include <iprt/param.h>
24#include <iprt/env.h>
25
26struct ARGDEF
27{
28 DHCPCFG Type;
29 const char * Name;
30};
31
32#ifdef RT_OS_WINDOWS
33# define DHCP_EXECUTABLE_NAME "VBoxNetDHCP.exe"
34#else
35# define DHCP_EXECUTABLE_NAME "VBoxNetDHCP"
36#endif
37
38static const ARGDEF g_aArgDefs[] = {
39 {DHCPCFG_NAME, "--name "},
40 {DHCPCFG_NETNAME, "--network "},
41 {DHCPCFG_TRUNKTYPE, "--trunk-type "},
42 {DHCPCFG_TRUNKNAME, "--trunk-name "},
43 {DHCPCFG_MACADDRESS, "--mac-address "},
44 {DHCPCFG_IPADDRESS, "--ip-address "},
45 {DHCPCFG_LEASEDB, "--lease-db"},
46 {DHCPCFG_VERBOSE, "--verbose"},
47 {DHCPCFG_BEGINCONFIG, "--begin-config"},
48 {DHCPCFG_GATEWAY, "--gateway "},
49 {DHCPCFG_LOWERIP, "--lower-ip "},
50 {DHCPCFG_UPPERIP, "--upper-ip "},
51 {DHCPCFG_NETMASK, "--netmask "},
52 {DHCPCFG_HELP, "--help"},
53 {DHCPCFG_VERSION, "--version"}
54};
55
56static const ARGDEF * getArgDef(DHCPCFG type)
57{
58 for (unsigned i = 0; i < RT_ELEMENTS(g_aArgDefs); i++)
59 {
60 if (g_aArgDefs[i].Type == type)
61 return &g_aArgDefs[i];
62 }
63 return NULL;
64}
65
66void DhcpServerRunner::detachFromServer()
67{
68 mProcess = NIL_RTPROCESS;
69}
70
71int DhcpServerRunner::start()
72{
73 if(isRunning())
74 return VINF_ALREADY_INITIALIZED;
75
76 const char * args[DHCPCFG_NOTOPT_MAXVAL * 2];
77
78 /* get the path to the executable */
79 const char *exePath = DHCP_EXECUTABLE_NAME;
80
81 int index = 0;
82
83 args[index++] = exePath;
84
85 for(int i = 0; i < DHCPCFG_NOTOPT_MAXVAL; i++)
86 {
87 if(!mOptions[i].isNull())
88 {
89 const ARGDEF * pArgDef = getArgDef((DHCPCFG)i);
90 args[index++] = pArgDef->Name;
91 if(!mOptions[i].isEmpty())
92 {
93 args[index++] = mOptions[i].raw();
94 }
95 }
96 }
97
98 args[index++] = NULL;
99
100 int rc = RTProcCreate (exePath, args, RTENV_DEFAULT, 0, &mProcess);
101 if (RT_FAILURE (rc))
102 {
103 mProcess = NIL_RTPROCESS;
104 }
105 return rc;
106}
107
108int DhcpServerRunner::stop()
109{
110 if(!isRunning())
111 return VINF_OBJECT_DESTROYED;
112
113 int rc = RTProcTerminate(mProcess);
114 mProcess = NIL_RTPROCESS;
115 return rc;
116}
117
118bool DhcpServerRunner::isRunning()
119{
120 if(mProcess == NIL_RTPROCESS)
121 return false;
122
123 RTPROCSTATUS status;
124 int rc = RTProcWait(mProcess, RTPROCWAIT_FLAGS_NOBLOCK, &status);
125
126 if(rc == VERR_PROCESS_RUNNING)
127 return true;
128
129 mProcess = NIL_RTPROCESS;
130 return false;
131}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette