Changeset 18859 in vbox for trunk/src/apps
- Timestamp:
- Apr 10, 2009 8:24:55 AM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 45877
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/apps/adpctl/VBoxNetAdpCtl.cpp
r18803 r18859 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 3 38 #define ADPCTLERR_IOCTL_FAILED 4 39 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 32 44 #define VBOXNETADP_CTL_ADD _IOR('v', 1, VBOXNETADPREQ) 45 #define VBOXNETADP_CTL_REMOVE _IOW('v', 2, VBOXNETADPREQ) 46 typedef struct VBoxNetAdpReq 47 { 48 char szName[VBOXNETADP_MAX_NAME_LEN]; 49 } VBOXNETADPREQ; 50 typedef VBOXNETADPREQ *PVBOXNETADPREQ; 51 33 52 34 53 #define VBOXADPCTL_IFCONFIG_PATH "/sbin/ifconfig" … … 43 62 { 44 63 fprintf(stderr, "Usage: VBoxNetAdpCtl <adapter> <address> ([netmask <address>] | remove)\n"); 64 fprintf(stderr, " | VBoxNetAdpCtl add\n"); 65 fprintf(stderr, " | VBoxNetAdpCtl <adapter> remove\n"); 45 66 } 46 67 … … 131 152 } 132 153 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 } 133 174 134 175 int main(int argc, char *argv[]) … … 141 182 int rc = EXIT_SUCCESS; 142 183 bool fRemove = false; 184 VBOXNETADPREQ Req; 143 185 144 186 switch (argc) … … 170 212 pszAdapterName = argv[1]; 171 213 pszAddress = argv[2]; 172 break; 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 */ 173 229 default: 174 230 fprintf(stderr, "Invalid number of arguments.\n\n"); … … 179 235 } 180 236 181 if (str cmp("vboxnet0", pszAdapterName))237 if (strncmp("vboxnet", pszAdapterName, 7)) 182 238 { 183 239 fprintf(stderr, "Setting configuration for %s is not supported.\n", pszAdapterName);
Note:
See TracChangeset
for help on using the changeset viewer.