Changeset 18803 in vbox for trunk/src/apps
- Timestamp:
- Apr 7, 2009 11:23:53 AM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 45796
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/apps/adpctl/VBoxNetAdpCtl.cpp
r18802 r18803 31 31 #include <unistd.h> 32 32 #include <sys/wait.h> 33 #include <sys/ioctl.h>34 #include <fcntl.h>35 36 /* @todo Error codes must be moved to some header file */37 #define ADPCTLERR_NO_CTL_DEV 338 #define ADPCTLERR_IOCTL_FAILED 439 40 /* @todo These are duplicates from src/VBox/HostDrivers/VBoxNetAdp/VBoxNetAdpInternal.h */41 #define VBOXNETADP_CTL_DEV_NAME "/dev/vboxnetctl"42 #define VBOXNETADP_NAME "vboxnet"43 #define VBOXNETADP_MAX_NAME_LEN 3244 #define VBOXNETADP_CTL_ADD _IOR('v', 1, VBOXNETADPREQ)45 #define VBOXNETADP_CTL_REMOVE _IOW('v', 2, VBOXNETADPREQ)46 typedef struct VBoxNetAdpReq47 {48 char szName[VBOXNETADP_MAX_NAME_LEN];49 } VBOXNETADPREQ;50 typedef VBOXNETADPREQ *PVBOXNETADPREQ;51 52 33 53 34 #define VBOXADPCTL_IFCONFIG_PATH "/sbin/ifconfig" … … 62 43 { 63 44 fprintf(stderr, "Usage: VBoxNetAdpCtl <adapter> <address> ([netmask <address>] | remove)\n"); 64 fprintf(stderr, " | VBoxNetAdpCtl add\n");65 fprintf(stderr, " | VBoxNetAdpCtl <adapter> remove\n");66 45 } 67 46 … … 152 131 } 153 132 154 int doIOCtl(unsigned long uCmd, void *pData)155 {156 int fd = open(VBOXNETADP_CTL_DEV_NAME, O_RDWR);157 if (fd == -1)158 {159 perror("VBoxNetAdpCtl: failed to open " VBOXNETADP_CTL_DEV_NAME);160 return ADPCTLERR_NO_CTL_DEV;161 }162 163 int rc = ioctl(fd, uCmd, pData);164 if (rc == -1)165 {166 perror("VBoxNetAdpCtl: ioctl failed for " VBOXNETADP_CTL_DEV_NAME);167 rc = ADPCTLERR_IOCTL_FAILED;168 }169 170 close(fd);171 172 return rc;173 }174 133 175 134 int main(int argc, char *argv[]) … … 182 141 int rc = EXIT_SUCCESS; 183 142 bool fRemove = false; 184 VBOXNETADPREQ Req;185 143 186 144 switch (argc) … … 212 170 pszAdapterName = argv[1]; 213 171 pszAddress = argv[2]; 214 if (strcmp("remove", pszAddress) == 0) 215 { 216 strncpy(Req.szName, pszAdapterName, sizeof(Req.szName)); 217 return doIOCtl(VBOXNETADP_CTL_REMOVE, &Req); 218 } 219 break; 220 case 2: 221 if (strcmp("add", argv[1]) == 0) 222 { 223 rc = doIOCtl(VBOXNETADP_CTL_ADD, &Req); 224 if (rc == 0) 225 puts(Req.szName); 226 return rc; 227 } 228 /* Fall through */ 172 break; 229 173 default: 230 174 fprintf(stderr, "Invalid number of arguments.\n\n"); … … 235 179 } 236 180 237 if (str ncmp("vboxnet", pszAdapterName, 7))181 if (strcmp("vboxnet0", pszAdapterName)) 238 182 { 239 183 fprintf(stderr, "Setting configuration for %s is not supported.\n", pszAdapterName);
Note:
See TracChangeset
for help on using the changeset viewer.