int main(int argc, char *argv[]) { parse_arguments(argc, argv); if (mode == SERVER) { server_mode(); } else if (mode == CLIENT){ client_mode(); } exit(1); }
int main(int argc, char **argv) { const char *client_port = NULL, *master_port = NULL, *start_script = NULL; int ch, limited_scan; struct sigaction sa; setprogname("pbulk-scan"); limited_scan = 0; while ((ch = getopt(argc, argv, "I:M:lc:m:v")) != -1) { switch (ch) { case 'I': start_script = optarg; break; case 'c': client_port = optarg; break; case 'l': limited_scan = 1; break; case 'm': master_port = optarg; break; case 'M': bmake_path = optarg; break; case 'v': ++verbosity; break; default: usage(); } } #if !defined(__INTERIX) sa.sa_sigaction = NULL; #endif sa.sa_handler = SIG_IGN; sa.sa_flags = 0; (void)sigemptyset(&sa.sa_mask); (void)sigaction(SIGPIPE, (struct sigaction *)&sa, NULL); argc -= optind; argv += optind; if (bmake_path == NULL) usage(); if (client_port != NULL && master_port != NULL) { warnx("Only client mode or master mode can be active"); usage(); } if (client_port) { if (limited_scan != 0 || argc != 1) usage(); pkgsrc_tree = argv[0]; client_mode(client_port); } if (argc != 2) usage(); pkgsrc_tree = argv[0]; output_file = argv[1]; if (limited_scan == 0) find_full_tree(); else read_limited_list(); if (master_port != NULL) master_mode(master_port, start_script); else standalone_mode(); write_jobs(output_file); return 0; }
/** * Program entry point * * @param[in] argc Number of CLI arguments * @param[in] argv Array of CLI arguments */ int main(int argc, const char **argv) { /* Local variables */ struct hostent *host; /* host info container */ unsigned int port; /* Listen on (server) / connect to (client) port number */ /* Check CLI arguments count */ if (argc < 4) { /* On error print USAGE notice */ printf( "USAGE: %s <mode = client / server> <hostname> <port> [<client::filename> <...>]\n", argv[0]); /* Return with error */ return ARGUMENT_ERROR; } /* Compute port number argument */ if (sscanf(argv[3], "%u", &port) != 1) { /* Drop error message */ puts("Invalid port number argument !"); /* Return with error */ return ARGUMENT_ERROR; } /* Get host info according specified remote / local address */ if ((host = gethostbyname(argv[2])) == NULL ) { /* Drop error message */ perror("gethostbyname()"); /* Return with error */ return HOSTNAME_ERROR; } /* Switch to client mode according to the mode argument */ if (strcmp(argv[1], "client") == 0) { /* Start client runtime */ return client_mode(host, port, argv + 4, argc - 4); } else { /* Switch to server mode according to the mode argument */ if (strcmp(argv[1], "server") == 0) { /* Start server runtime */ return server_mode(host, port); } else { /* Unknown mode */ /* Drop error message */ puts("Invalid mode argument !"); /* Return with error */ return ARGUMENT_ERROR; } } /* Return without error */ return NO_ERROR; }
int main(int argc, char **argv) { char *ifname = NULL; u_int8_t *sysname = NULL, *srvname = NULL; char ifnambuf[IFNAMSIZ]; struct ether_addr ea; int bpffd, smode = 0, c; struct passwd *pw; if ((pw = getpwnam("_ppp")) == NULL) err(EX_CONFIG, "getpwnam(\"_ppp\")"); while ((c = getopt(argc, argv, "svi:n:p:")) != -1) { switch (c) { case 'i': if (ifname != NULL) { usage(); return (EX_USAGE); } ifname = optarg; break; case 'n': if (srvname != NULL) { usage(); return (EX_USAGE); } srvname = (u_int8_t *)optarg; break; case 'p': if (sysname != NULL) { usage(); return (EX_USAGE); } sysname = (u_int8_t *)optarg; break; case 's': if (smode) { usage(); return (EX_USAGE); } smode = 1; break; case 'v': option_verbose++; break; default: usage(); return (EX_USAGE); } } argc -= optind; if (argc != 0) { usage(); return (EX_USAGE); } if (getifhwaddr(ifname, ifnambuf, &ea) < 0) return (EX_IOERR); bpffd = setupfilter(ifnambuf, &ea, smode); if (bpffd < 0) return (EX_IOERR); drop_privs(pw, smode); signal_init(); if (smode) server_mode(bpffd, sysname, srvname, &ea); else client_mode(bpffd, sysname, srvname, &ea); return (0); }