示例#1
0
int main(int argc, char **argv) {
#ifdef CONFIG_SVN_REV
	unsigned int rev = CONFIG_SVN_REV;
#endif
	int opt;
	getopt_init();
	while (-1 != (opt = getopt(argc, argv, "h"))) {
		switch(opt) {
		case 'h':
			print_usage();
			return 0;
		default:
			return 0;
		}
	}

        printf("\n");
        printf(".------.          _\n");
        printf("|  ____|         | | \n");
        printf("| |____ _ __ ___ | |_    _____  __\n");
        printf("|  ____| '_ ` _ \\|  _ \\ / _ \\ \\/ /\n");
        printf("| |____| | | | | | |_) | (_) >  <  \n");
        printf("|______|_| |_| |_|____/ \\___/_/\\_\\\n");
        printf("\n");
	printf("Date: %12s\n", __DATE__);
	printf("Time: %9s\n", __TIME__);
	printf("Compiler: %s\n", __VERSION__);
#ifdef CONFIG_SVN_REV
	printf("Revision: r%d\n", rev);
#endif
	return 0;
}
示例#2
0
int main(int argc, char **argv) {
	static struct ntpd_param param = {
		.running = 0
	};
	int opt;

	getopt_init();

	while (-1 != (opt = getopt(argc, argv, "hS"))) {
		switch(opt) {
		default:
			return -EINVAL;
		case 'h':
			printf("Usage: %s [-Sh] <server-ip>", argv[0]);
			return 0;
		case 'S':
			return ntpd_stop(&param);
		}
	}

	if (optind >= argc) {
		printf("%s: error: no server specified\n", argv[0]);
		return -EINVAL;
	}
	else if (!inet_aton(argv[optind],
				(struct in_addr *)&param.addr)) {
		printf("%s: error: invalid address '%s`\n",
				argv[0], argv[optind]);
		return -EINVAL;
	}

	param.poll = NTP_POLL_MIN;

	return ntpd_start(&param);
}
示例#3
0
文件: umount.c 项目: Julia117/embox
int main(int argc, char **argv) {
	int opt;
	char *dir;

	getopt_init();
	while (-1 != (opt = getopt(argc, argv, "h:"))) {
		switch (opt) {
		case '?':
			break;
		case 'h':
			print_usage();
			return 0;
			/* FALLTHROUGH */
		default:
			return 0;
		}
	}

	if (argc != 2) {
		print_usage();
		return EINVAL;
	}
	dir = argv[argc - 1];

	return umount(dir);
}
示例#4
0
int main(int argc, char **argv) {
	int opt;
	//struct timeval tv;

	getopt_init();

	while (-1 != (opt = getopt(argc, argv, "hs:"))) {
		printf("\n");
		switch (opt) {
		case 'h': /* show help */
			print_usage();
			break;
		case 's': /* set date*/
			set_date(argv[2]);
			break;
		default:
			break;
		}
	}

	/* show date and kernel time */
	if (argc == 1) {
		show_date();
		//ktime_get_timeval(&tv);
		//printf("ktime_get_timeval %d:%d (s:ms)\n", (int)tv.tv_sec, (int)tv.tv_usec/1000);
		return 0;
	}
	check_format(argv[argc-1]);

	return 0;
}
示例#5
0
/*
 * read commandline parameters into global vars
 * result: 0 = OK, 1 = error
 */
static void parse_commandline(int argc, char **argv)
{
    int res;

    // define commandline syntax
    getopt_init(&getopt_parser, /*ignore_case*/1);
    getopt_def(&getopt_parser, "?", "help", NULL, NULL, NULL, "Print help", NULL, NULL, NULL, NULL);

    getopt_def(&getopt_parser, "b", "background", NULL, NULL, NULL,
            "background operation: print to syslog (view with dmesg)\n"
                    "Else default output is stderr",
            NULL, NULL, NULL, NULL);
    getopt_def(&getopt_parser, "v", "verbose", NULL, NULL, NULL, "verbose: tell what I'm doing",
    NULL, NULL, NULL, NULL);
    getopt_def(&getopt_parser, "t", "test", NULL, NULL, NULL, "Test mode",
    NULL, NULL, NULL, NULL);

    getopt_def(&getopt_parser, "mf", "muxfrequency", "frequency", NULL, "1000",
            "Row frequency for lamp multiplexing. There are 3 rows.\n"
                    "!! For values != 1000 (1 kHz) the lamp protection watchdog will not work correctly !!",
            "10000", "multiplex with 10 kHz, every row is shown 3333x per second", NULL, NULL);

/*    getopt_def(&getopt_parser, "sf", "switchmuxfrequency", "switchmuxfrequency", NULL, "15",
            "Row frequency for switch polling. Effective polling frequency is 1/3 of that.\n"
                    "Use low values to suppress contact bounce on some switches.",
            "30", "Poll switches with 100 Hz", NULL, NULL);
*/
    res = getopt_first(&getopt_parser, argc, argv);
    while (res > 0) {
        if (getopt_isoption(&getopt_parser, "help")) {
            help();
        } else if (getopt_isoption(&getopt_parser, "background")) {
            opt_background = 1;
        } else if (getopt_isoption(&getopt_parser, "test")) {
            opt_test = 1;
        } else if (getopt_isoption(&getopt_parser, "verbose")) {
            print_level = LOG_DEBUG;
        } else if (getopt_isoption(&getopt_parser, "muxfrequency")) {
            if (getopt_arg_i(&getopt_parser, "frequency", &opt_mux_frequency) < 0)
                commandline_option_error();
/*
        } else if (getopt_isoption(&getopt_parser, "switchmuxfrequency")) {
            if (getopt_arg_i(&getopt_parser, "switchmuxfrequency", &opt_switch_mux_frequency) < 0)
                commandline_option_error();
*/
        }
        res = getopt_next(&getopt_parser);

    }
    // start logging
    print_open(opt_background); // if background, then syslog

    if (res == GETOPT_STATUS_MINARGCOUNT || res == GETOPT_STATUS_MAXARGCOUNT)
        // known option, but wrong number of arguments
        commandline_option_error();
    else if (res < 0)
        commandline_error();
}
int cxx_app_start(int argc, char **argv) {
	int ret;

	cxx_app_startup();
	getopt_init();
	ret = main(argc,argv);
	cxx_app_termination();

	return ret;
}
示例#7
0
int main(int argc, char **argv) {
	const struct test_suite *test = NULL;
	int test_nr = -1;
	int opt;
	/* TODO it must be agreed with shell maximum command length */
	char test_name[100] = { 0 };

	getopt_init();
	while (-1 != (opt = getopt(argc, argv, "hn:t:i"))) {
		switch (opt) {
		case 'n':
			if ((optarg == NULL) || (!sscanf(optarg, "%d", &test_nr))) {
				printf("test -n: number expected\n");
				print_usage();
				return -EINVAL;
			}
			break;
		case 't':
			if ((optarg == NULL) || (!sscanf(optarg, "%s", test_name))) {
				printf("test -t: test name expected\n");
				print_usage();
				return -EINVAL;
			}
			break;
		case '?':
		case 'h':
			print_usage();
			/* FALLTHROUGH */
		default:
			return 0;
		}
	}

	if (test_nr != -1) {
		if (NULL == (test = get_test_by_nr(test_nr))) {
			return -ENOENT;
		}
	}
	if (*test_name != 0) {
		if (NULL == (test = test_lookup(test_name))) {
			printf("Can't find test named \"%s\"\n", test_name);
			return -ENOENT;
		}
	}

	if (NULL == test) {
		print_tests();
		return 0;
	}

	return test_suite_run(test);
}
示例#8
0
int main(int argc, char *argv[]) {
	int opt;
	struct utsname info;
	struct uname_args args;
	char *processor, *platform, *system;

	memset(&args, 0, sizeof args);

	getopt_init();
	while (-1 != (opt = getopt(argc, argv, "hasnrvmpio"))) {
		switch(opt) {
		default:
			printf("Try '%s -h` for more information.", argv[0]);
			return -EINVAL;
		case 'h':
			printf("Usage: %s [-hasnrvmpio]\n", argv[0]);
			return 0;
		case 'a': args.with_a = 1; break;
		case 's': args.with_s = 1; break;
		case 'n': args.with_n = 1; break;
		case 'r': args.with_r = 1; break;
		case 'v': args.with_v = 1; break;
		case 'm': args.with_m = 1; break;
		case 'p': args.with_p = 1; break;
		case 'i': args.with_i = 1; break;
		case 'o': args.with_o = 1; break;
		}
	}

	if (!uname_args_not_empty(&args))
		args.with_s = 1;

	uname(&info);
	processor = NULL;
	platform = OPTION_STRING_GET(platform);
	system = OPTION_STRING_GET(system);

	if (args.with_a || args.with_s) printf("%s ", info.sysname);
	if (args.with_a || args.with_n) printf("%s ", info.nodename);
	if (args.with_a || args.with_r) printf("%s ", info.release);
	if (args.with_a || args.with_v) printf("%s ", info.version);
	if (args.with_a || args.with_m) printf("%s ", info.machine);

	if ((args.with_a && processor) || args.with_p)
		printf("%s ", processor ? processor : "unknown");
	if ((args.with_a && platform) || args.with_i)
		printf("%s ", platform ? platform : "unknown");
	if (args.with_a || args.with_o) printf("%s ", system);
	printf("\n");

	return 0;
}
示例#9
0
int main(int argc, char *argv[]) {
	int opt;
	const char *blockname = NULL;
	const char *partname  = NULL;
	int blockoffset = -1;
	int blocklen = -1;
	node_t *bdevnode = NULL;
	node_t *root;

	getopt_init();

	while (-1 != (opt = getopt(argc, argv, "b:n:o:l:"))) {
		switch(opt) {
		case 'b':
			blockname = optarg;
			break;
		case 'n':
			partname = optarg;
			break;
		case 'o':
			blockoffset = atoi(optarg);
			break;
		case 'l':
			blocklen = atoi(optarg);
			break;
		default:
			break;
		}
	}

	if (!blockname || !partname || blockoffset < 0 || blocklen < 0) {
		return -1;
	}

	root = vfs_get_root();
	assert(root);
	if (NULL == (bdevnode = vfs_subtree_lookup(root, blockname))) {
		printf("blockdev not found\n");
		return -1;
	}

	part.bdev = bdevnode->nas->fi->privdata;
	part.start = blockoffset;
	part.len = blocklen;

	partbdev = block_dev_create("/dev/hda0", bdev_driver_part, &part);
	partbdev->size = BSIZE * blocklen;

	return 0;

}
示例#10
0
int main(int argc, char *argv[]) {
	const char *outfile = NULL;
	FILE *out;
	const struct symbol *sym_table;
	const unsigned long *cov_bitmap;
	int opt, i, sym_n;

	getopt_init();
	while (-1 != (opt = getopt(argc, argv, "o:h"))) {
		switch (opt) {
		case 'h':
			printf("Usage: %s [-h] [-o output_file]\n", argv[0]);
			return 0;
		case 'o':
			outfile = optarg;
		default:
			break;
		}
	}

	if (outfile) {
		out = fopen(outfile, "w");
		if (!out) {
			perror("fopen");
			return -errno;
		}
	} else {
		out = stdout;
	}


	sym_n = coverage_getstat(&sym_table, &cov_bitmap);
	if (sym_n <= 0) {
		if (outfile)
			fclose(out);
		return sym_n;
	}

	fprintf(out, "%32s\t%8s\n", "FUNCTION", "EXECUTED");
	for (i = 0; i < sym_n; i++) {

		fprintf(out, "%21s@0x%08lx\t%8s\n", sym_table[i].name,
				(unsigned long) sym_table[i].addr,
				bitmap_test_bit(cov_bitmap, i) ? "true" : "false");
	}

	if (outfile)
		fclose(out);

	return 0;
}
示例#11
0
文件: shell.c 项目: extraice/g-bios
// fixme: move to task.c
int exec(int argc, char *argv[])
{
	int ret;
	const struct command *exe;
	struct task *current;
	int (*main)(int, char *[]);

	// fixme
	for (exe = build_in_cmd; exe < build_in_cmd + ARRAY_ELEM_NUM(build_in_cmd); exe++) {
		if (!strncmp(exe->name, argv[0], MAX_ARG_LEN)) {
			goto L1;
		}
	}

	for (exe = g_exe_begin; exe < g_exe_end; exe++) {
		if (!strncmp(exe->name, argv[0], MAX_ARG_LEN)) {
			goto L1;
		}
	}

	printf("  command \"%s\" not found!\n"
		   "  Please use \"help\" to get g-bios command list.\n", argv[0]);
	return -ENOEXEC;

L1:
	main = exe->main;
	if (!main)
		return -EINVAL;

	current = malloc(sizeof(*current));
	if (!current)
		return -ENOMEM;

	current->argc = argc;
	current->argv = argv;
	current->exe  = exe;
	current->help = get_help(argv[0]); // fixme
	set_current_task(current);

	getopt_init();
	ret = main(argc, argv);

	set_current_task(NULL);
	free(current);

	return ret;
}
示例#12
0
int main(int argc, char **argv) {
	int opt;
	FILE *fd;
	stat_t st;
	char *addr;
	md5_state_t state;
	md5_byte_t digest[16];
	char hex_output[16*2 + 1];
	int di;
	int err;

	getopt_init();
	while (-1 != (opt = getopt(argc, argv, "h"))) {
		switch (opt) {
		case '?':
		case 'h':
			print_usage();
			/* FALLTHROUGH */
		default:
			return 0;
		}
	}

	/* Get size and file's base addr */
	if (NULL == (fd = fopen(argv[argc - 1], "r"))) {
		printf("Can't open file %s\n", argv[argc - 1]);
		return -errno;
	}
	err = fioctl(fd, 0, &addr);
	fclose(fd);

	if (err < 0)
		printf("Target filesystem not supported!\n");
	stat((char *) argv[argc - 1], &st);
	/* Compute MD5 sum */
	md5_init(&state);
	md5_append(&state, (const md5_byte_t *) addr, st.st_size);
	md5_finish(&state, digest);
	/* Prepare output */
	for (di = 0; di < 16; ++di) {
		sprintf(hex_output + di * 2, "%02x", digest[di]);
	}
	printf("%s %s\n", hex_output, argv[argc - 1]);
	return 0;
}
示例#13
0
int main(int argc, char **argv) {
	int dev_number = -1;
	func_show_bus_t show_func = show_all;
	int opt;
	getopt_init();
	while (-1 != (opt = getopt(argc, argv, "n:b:h"))) {
		switch(opt) {
		case 'h':
			print_usage();
			return 0;
		case 'b':
			if (NULL == (show_func = set_bus_type(optarg))) {
				printf("Parsing: chose right bus type '-b'\n");
				print_usage();
				return -EINVAL;
			}
			break;
		case 'n':
			if (show_all == show_func) {
				printf("Parsing: chose bus type '-b'\n");
				print_usage();
				return -EINVAL;
			}
			if (1 != sscanf(optarg,"%d", &dev_number)) {
				printf("parsing: enter validly dev_number '-n'\n");
				print_usage();
				return -EINVAL;
			}
			break;
		default:
			return 0;
		}
	}

	{
		const char **m = msg;
		for (; *m != NULL; m++) {
			printf("%s\n", *m);
		}
		return 0;
	}

	show_func(dev_number);
	return 0;
}
示例#14
0
int main(int argc, char **argv) {
	int opt, only_query, timeout;
	struct timeval timeout_tv;
	in_addr_t addr;

	only_query = 0;
	timeout = MODOPS_TIMEOUT;
	getopt_init();

	while (-1 != (opt = getopt(argc, argv, "hqt:"))) {
		switch (opt) {
		default:
			return -EINVAL;
		case 'h':
			printf("Usage: %s [-q] server", argv[0]);
			return 0;
		case 'q': /* Query only - don't set the clock */
			only_query = 1;
			break;
		case 't': /* Maximum time waiting for a server response */
			if (1 != sscanf(optarg, "%d", &timeout)) {
				printf("%s: error: wrong -t argument %s\n",
						argv[0], optarg);
				return -EINVAL;
			}
			break;
		}
	}

	if (optind >= argc) {
		printf("%s: error: no server specified\n", argv[0]);
		return -EINVAL;
	}
	else if (!inet_aton(argv[optind], (struct in_addr *)&addr)) {
		printf("%s: error: invalid address %s\n", argv[0],
				argv[optind]);
		return -EINVAL;
	}

	timeout_tv.tv_sec = timeout / MSEC_PER_SEC;
	timeout_tv.tv_usec = (timeout % MSEC_PER_SEC) * USEC_PER_MSEC;

	return ntpdate(addr, &timeout_tv, only_query);
}
示例#15
0
int main(int argc, char *argv[]) {
	/* parse params */
	const struct cmd *c_cmd;
	int c_argc = argc, opt, argnum = 1;
	FILE *out = NULL;

	getopt_init();

	while (-1 != (opt = getopt(argc, argv, "chn:ed"))) {
		argnum++;
		switch (opt) {
			case 'c':
				/* execute command */
				c_cmd = cmd_lookup(argv[argnum]);
				run_cmd(c_cmd, c_argc - argnum, argv + argnum, out);
				return 0;
				break;
			case 'n':
				sscanf(optarg, "%d", &run_count);
				argnum++;
				break;
			case 'e':
				initialize_hashtable();
				set_profiling_mode(CYG_PROFILING);
				printf("cyg_profiling enabled.\n");
				return 0;
				break;
			case 'd':
				set_profiling_mode(DISABLED);
				printf("cyg_profiling disabled.\n");
				return 0;
				break;
			case 'h':
				printf("Example: tbprof [-n count] -c [cmd]\nUse man tbprof for more info.\n");
				return 0;
				break;
		}
	}
	printf("Wrong arguments. tbprof -h for usage.\n");
	return 0;
}
示例#16
0
文件: ext3.c 项目: kandeshvari/embox
static int ext3fs_format(void *dev) {
	struct node *dev_node;
	int argc = 6;
	char *argv[6];
	char dev_path[64];

	dev_node = dev;

	strcpy(dev_path, "/dev/");
	strcat(dev_path, dev_node->name);

	argv[0] = "mke2fs";
	argv[1] = "-b";
	argv[2] = "1024";
	argv[3] = "-t";
	argv[4] = "ext3";
	argv[5] = dev_path;

	getopt_init();
	return main_mke2fs(argc, argv);
}
示例#17
0
int main(int argc, char **argv) {
	int opt;
	getopt_init();
	while (-1 != (opt = getopt(argc, argv, "hra"))) {
		switch (opt) {
		case 'h':
			print_usage();
			return 0;
		case 'r':
			show_regions();
			return 0;
		case 'a':
			show_all();
			return 0;
		default:
			show_regions();
			return 0;
		}
	}
	return 0;
}
示例#18
0
文件: stat.c 项目: Julia117/embox
int main(int argc, char **argv) {
	int opt;

	if (argc < 2) {
		printf("Please enter correct file name\n");
		return 0;
	}
	getopt_init();

	while (-1 != (opt = getopt(argc - 1, argv, "nh"))) {
		switch (opt) {
		case '?':
			printf("Invalid option `-%c'\n", optopt);
			/* FALLTHROUGH */
			argc = 0;
			break;
		case 'h':
			print_usage();
			return 0;
		default:
			return -EINVAL;
		}
	}

	if (argc < 2) {
		print_usage();
		return 0;
	}

	if (-1 == stat(argv[argc - 1], &filestat)) {
		return -errno;
	}

	print_statistic(&filestat);

	return 0;
}
示例#19
0
int main(int argc, char **argv) {
	int ret, i;
	char param_ascii, param_binary, param_get, param_put;
	int (*file_hnd)(char *, char *, char);

	/* Initialize objects */
	param_ascii = param_binary = param_get = param_put = 0;
	getopt_init();

	/* Get options */
	while ((ret = getopt(argc, argv, "habgp")) != -1) {
		switch (ret) {
		default:
		case '?':
			fprintf(stderr, "%s: error: unrecognized option '%c`\n", argv[0], (char)optopt);
			fprintf(stderr, "Try -h for more information\n");
			return -EINVAL;
		case 'h':
			fprintf(stdout, "Usage: %s [-hab] -[g|p] files destination\n", argv[0]);
			return 0;
		case 'a':
		case 'b':
			if (param_ascii || param_binary) {
				fprintf(stderr, "%s: error: already using %s mode to transfer files\n",
						argv[0], get_transfer_mode(!param_ascii));
				return -EINVAL;
			}
			*(ret == 'a' ? &param_ascii : &param_binary) = 1;
			break;
		case 'g':
		case 'p':
			if (param_get || param_put) {
				fprintf(stderr, "%s: error: %s mode already was selected\n",
						argv[0], param_get ? "forwarding" : "receiving");
				return -EINVAL;
			}
			*(ret == 'g' ? &param_get : &param_put) = 1;
			break;
		}
	}

	/* Check transfering mode options */
	if (!param_ascii && !param_binary) {
		param_binary = 1; /* default mode */
	}

	/* Check action flags */
	if (!param_get && !param_put) {
		fprintf(stderr, "%s: error: please specify action on files\n", argv[0]);
		return -EINVAL;
	}

	/* Check presence of files names and address of remote machine */
	if (argc - (--optind) < 2) {
		fprintf(stderr, "%s: erorr: please specify at least one file and address of remote host\n",
				argv[0]);
		return -EINVAL;
	}

	/* Handling */
	file_hnd = param_get ? &tftp_recv_file : &tftp_send_file;
	for (i = optind; i < argc - 1; ++i) {
		ret = (*file_hnd)(argv[i], argv[argc - 1], param_binary);
		if (ret != 0) {
			fprintf(stderr, "%s: error: error occured when handled file '%s`\n",
					argv[0], argv[i]);
			return ret;
		}
	}

	return 0;
}
示例#20
0
static int exec(int argc, char **argv) {
	getopt_init();
	return main_mke2fs(argc, argv);
}
示例#21
0
文件: hostinfo.c 项目: Julia117/embox
static int exec(int argc, char *argv[]) {
	int opt, flag_a;
	struct hostent *he;
	struct in_addr in;

	/**
	 * Initialization
	 */
	flag_a = 0;
	getopt_init();

	/**
	 * Parse command arguments
	 */
	while (-1 != (opt = getopt(argc, argv, "ha"))) {
		switch (opt) {
		case 'a':
			flag_a = 1;
			break;
		case '?':
		case 'h':
			print_usage();
			/* FALLTHROUGH */
		default:
			return 0;
		}
	}

	/**
	 * Get host name or host address
	 */
	if (optind >= argc) {
		printf("hostinfo: error: host not specified\n");
		return -EINVAL;
	}

	/**
	 * The last argument is the name or address?
	 */
	if (flag_a) {
		/**
		 * Get address of remote host which we want to discover
		 */
		if (!inet_aton(argv[optind], &in)) {
			return -EINVAL;
		}

		/**
		 * Try to get host information. As you can see,
		 * 2nd and 3th arguments specify protocol family
		 */
		he = gethostbyaddr(&in, sizeof in, AF_INET);
	}
	else {
		/**
		 * Nope, it's the name.
		 * Discover host by its name
		 */
		he = gethostbyname(argv[optind]);
	}

	/**
	 * Discovery has been successfully completed?
	 */
	if (he == NULL) {
		printf("hostinfo: error: unknown host %s\n", argv[optind]);
		return -1;
	}

	/**
	 * Print host information
	 */
	print_info(he);

	return 0;
}
示例#22
0
文件: smac_adm.c 项目: Julia117/embox
int main(int argc, char *argv[]) {
	char *label = NULL;
	char *user = NULL;
	char *subject = NULL, *object = NULL, *access = NULL;
	enum action {
		ACT_NONE,
		ACT_SET,
		ACT_GET,
		ACT_FLUSH,
		ACT_PRINT,
		ACT_RULE,
		ACT_USER,
		ACT_HELP,
	} action = ACT_NONE;
	int opt;

	getopt_init();
	while (-1 != (opt = getopt(argc, argv, "S:GFPR:U:o:a:h"))) {
		enum action act = ACT_NONE;

		switch(opt) {
		case 'S':
			act = ACT_SET;
			label = optarg;
			break;
		case 'G':
			act = ACT_GET;
			break;
		case 'F':
			act = ACT_FLUSH;
			break;
		case 'P':
			act = ACT_PRINT;
			break;
		case 'R':
			act = ACT_RULE;
			subject = optarg;
			break;
		case 'U':
			act = ACT_USER;
			user = optarg;
			label = argv[optind++];
			break;
		case 'o':
			object = optarg;
			break;
		case 'a':
			access = optarg;
			break;
		case 'h':
			act = ACT_HELP;
			break;
		default:
			printf("Unknown argument -- %c\n", optopt);
			return -EINVAL;
		}

		if (act != ACT_NONE) {
			if (action != ACT_NONE) {
				printf("Incorrect commmand line, multiplie action specified\n");
				return -EINVAL;
			}

			action = act;
		}
	}

	switch(action) {
	case ACT_SET:
		return smac_labelset(label);
	case ACT_GET:
		return print_label(optind < argc ? argv[optind] : NULL);
	case ACT_FLUSH:
		return smac_flushenv();
	case ACT_RULE:
		return new_rule(subject, object, access);
	case ACT_PRINT:
		return print_rules();
	case ACT_USER:
		return cmd_smac_adm_user_set(user, label);
	case ACT_NONE:
	default:
		break;
	}
	return 0;
}
示例#23
0
int main(int argc, char **argv) {
	int opt;
	int cnt = 4, cnt_resp = 0, i;
	struct in_device *in_dev = inetdev_get_by_name("eth0");
	struct in_addr dst;
	char dst_b[] = "xxx.xxx.xxx.xxx";
	char from_b[] = "xxx.xxx.xxx.xxx";
	struct in_addr from;
	unsigned char mac[18], hw_addr[ETH_ALEN];

	getopt_init();
	while (-1 != (opt = getopt(argc, argv, "I:c:h"))) {
		switch (opt) {
		case 'I': /* get interface */
			if (NULL == (in_dev = inetdev_get_by_name(optarg))) {
				printf("arping: unknown iface %s\n", optarg);
				return -EINVAL;
			}
			break;
		case 'c': /* get ping cnt */
			if (1 != sscanf(optarg, "%d", &cnt)) {
				printf("arping: bad number of packets to transmit.\n");
				return -EINVAL;
			}
			break;
		case '?':
			printf("Invalid option `-%c'\n", optopt);
			/* FALLTHROUGH */
		case 'h':
			print_usage();
			/* FALLTHROUGH */
		default:
			return 0;
		}
	};

	if (argc == 1) {
		print_usage();
		return 0;
	}

	/* Get destination address. */
	if (0 == inet_aton(argv[argc - 1], &dst)) {
		printf("arping: invalid IP address: %s\n", argv[argc - 1]);
		return -EINVAL;
	}

	strncpy(dst_b, inet_ntoa(dst), sizeof(dst_b));
	from.s_addr = in_dev->ifa_address;
	strncpy(from_b, inet_ntoa(from), sizeof(from_b));
	printf("ARPING %s from %s %s\n", dst_b, from_b, in_dev->dev->name);
	for (i = 1; i <= cnt; i++) {
		neighbour_del(ETH_P_IP, &dst, in_dev->dev);
		send_request(in_dev->dev, ETH_P_IP, sizeof in_dev->ifa_address,
				&in_dev->ifa_address, &dst.s_addr);
		usleep(DEFAULT_INTERVAL);
		if (0 == neighbour_get_haddr(ETH_P_IP, &dst, in_dev->dev,
					ARP_HRD_ETHERNET, sizeof hw_addr, &hw_addr[0])) {
			macaddr_print(mac, hw_addr);
			printf("Unicast reply from %s [%s]  %dms\n", dst_b, mac, 0);
			cnt_resp++;
		}
	}
	printf("Sent %d probes (%d broadcast(s))\n", cnt, 1);
	printf("Received %d response(s)\n", cnt_resp);

	return 0;
}
示例#24
0
/* Thread-safe version */
static int Rrd_Create(
    ClientData __attribute__((unused)) clientData,
    Tcl_Interp *interp,
    int argc,
    CONST84 char *argv[])
{
    int       argv_i;
    char    **argv2;
    char     *parsetime_error = NULL;
    time_t    last_up = time(NULL) - 10;
    long int  long_tmp;
    unsigned long int pdp_step = 300;
    rrd_time_value_t last_up_tv;

    argv2 = getopt_init(argc, argv);

    for (argv_i = 1; argv_i < argc; argv_i++) {
        if (!strcmp(argv2[argv_i], "--start") || !strcmp(argv2[argv_i], "-b")) {
            if (argv_i++ >= argc) {
                Tcl_AppendResult(interp, "RRD Error: option '",
                                 argv2[argv_i - 1], "' needs an argument",
                                 (char *) NULL);
                getopt_cleanup(argc, argv2);
                return TCL_ERROR;
            }
            if ((parsetime_error = rrd_parsetime(argv2[argv_i], &last_up_tv))) {
                Tcl_AppendResult(interp, "RRD Error: invalid time format: '",
                                 argv2[argv_i], "'", (char *) NULL);
                getopt_cleanup(argc, argv2);
                return TCL_ERROR;