int main(int argc, char *argv[]) { int cmd; if(init_winsock()){ err("can't init winsock"); return 0; } cmd = parse_opt(argc, argv); switch(cmd) { case CMD_ATTACH: if (optind == argc - 2) attach_device(argv[optind], argv[optind+1]); else show_help(argv[0]); break; case CMD_DETACH: while (optind < argc) detach_port(argv[optind++]); break; case CMD_PORT: show_port_status(); break; case CMD_LIST: while (optind < argc) show_exported_devices(argv[optind++]); break; case CMD_ATTACHALL: while(optind < argc) attach_devices_all(argv[optind++]); break; case CMD_VERSION: printf("%s\n", version); break; case CMD_HELP: show_help(argv[0]); break; default: show_help(argv[0]); } return 0; }
int main(int argc, char *argv[]) { int ret; enum { cmd_attach = 1, cmd_attachall, cmd_detach, cmd_port, cmd_list, cmd_help, cmd_version } cmd = 0; usbip_use_stderr = 1; if (geteuid() != 0) g_warning("running non-root?"); ret = usbip_names_init(USBIDS_FILE); if (ret) err("open usb.ids"); for (;;) { int c; int index = 0; c = getopt_long(argc, argv, "adplvhDSx", longopts, &index); if (c == -1) break; switch(c) { case 'a': if (!cmd) cmd = cmd_attach; else cmd = cmd_help; break; case 'd': if (!cmd) cmd = cmd_detach; else cmd = cmd_help; break; case 'p': if (!cmd) cmd = cmd_port; else cmd = cmd_help; break; case 'l': if (!cmd) cmd = cmd_list; else cmd = cmd_help; break; case 'v': if (!cmd) cmd = cmd_version; else cmd = cmd_help; break; case 'x': if(!cmd) cmd = cmd_attachall; else cmd = cmd_help; break; case 'h': cmd = cmd_help; break; case 'D': usbip_use_debug = 1; break; case 'S': usbip_use_syslog = 1; break; case '?': break; default: err("getopt"); } } switch(cmd) { case cmd_attach: if (optind == argc - 2) attach_device(argv[optind], argv[optind+1]); else show_help(); break; case cmd_detach: while (optind < argc) detach_port(argv[optind++]); break; case cmd_port: show_port_status(); break; case cmd_list: while (optind < argc) show_exported_devices(argv[optind++]); break; case cmd_attachall: while(optind < argc) attach_devices_all(argv[optind++]); break; case cmd_version: printf("%s\n", version); break; case cmd_help: show_help(); break; default: show_help(); } usbip_names_free(); return 0; }
int main(int argc, char *argv[]) { int ret; enum { cmd_attach = 1, cmd_attachall, cmd_detach, cmd_port, cmd_list, cmd_help, cmd_version } cmd = 0; usbip_use_stderr = 1; #ifdef __linux__ if (geteuid() != 0) notice("running non-root?"); #endif if (init_socket()) return EXIT_FAILURE; ret = usbip_names_init(USBIDS_FILE); if (ret) notice("failed to open %s", USBIDS_FILE); for (;;) { int c; int index = 0; c = getopt_long(argc, argv, "adplvhDSx", longopts, &index); if (c == -1) break; switch(c) { case 'a': if (!cmd) cmd = cmd_attach; else cmd = cmd_help; break; case 'd': if (!cmd) cmd = cmd_detach; else cmd = cmd_help; break; case 'p': if (!cmd) cmd = cmd_port; else cmd = cmd_help; break; case 'l': if (!cmd) cmd = cmd_list; else cmd = cmd_help; break; case 'v': if (!cmd) cmd = cmd_version; else cmd = cmd_help; break; #ifdef __linux__ case 'x': if(!cmd) cmd = cmd_attachall; else cmd = cmd_help; break; #endif case 'h': cmd = cmd_help; break; case 'D': usbip_use_debug = 1; break; case 'S': usbip_use_syslog = 1; break; case '?': break; default: err("getopt"); } } /* disable output buffering (needed to read the pipe when launched from another program) */ setbuf(stderr, NULL); ret = 0; switch(cmd) { case cmd_attach: if (optind == argc - 2) ret = attach_device(argv[optind], argv[optind+1]); else show_help(); break; case cmd_detach: while (optind < argc) ret = detach_port(argv[optind++]); break; case cmd_port: ret = show_port_status(); break; case cmd_list: while (optind < argc) ret = show_exported_devices(argv[optind++]); break; case cmd_attachall: while(optind < argc) ret = attach_devices_all(argv[optind++]); break; case cmd_version: printf("%s\n", version); break; case cmd_help: show_help(); break; default: show_help(); } usbip_names_free(); cleanup_socket(); exit((ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE); }