示例#1
0
int main(int argc, char *argv[])
{
	char *host = "localhost";
	struct libicmp *obj;

	if (argc >= 2)
		host = argv[1];

	if (!(obj = icmp_open(host, 0x1337, 0)))
		return 1;

	return icmp_ping(obj, 0, 0) == -1;
}
示例#2
0
文件: mtu.c 项目: ncopa/pingu
int main(int argc, char **argv)
{
	struct hostent *hp;
	void (*action)(void) = NULL;
	char *target;
	int opt;

	while ((opt = getopt(argc, argv, "DdIi:")) != -1) {
		switch (opt) {
		case 'D':
			action = do_discover_and_write;
			break;
		case 'd':
			action = do_discover;
			break;
		case 'i':
			action = do_inject;
			mtu_size = atoi(optarg);
			break;
		case 'I':
			action = do_inject_pmtu;
			break;
		default:
			usage();
		}
	}

	if (action == NULL || optind >= argc)
		usage();

	target = argv[optind];

	fd = icmp_open(1.0);
	if (fd < 0)
		exit(1);

	memset((char *) &to, 0, sizeof(to));
	to.sin_family = AF_INET;
	if (inet_aton(target, &to.sin_addr) != 1) {
		hp = gethostbyname(target);
		if (!hp) {
			fprintf(stderr, "mtu: unknown host %s\n", target);
			exit(2);
		}
		memcpy(&to.sin_addr, hp->h_addr, 4);
	}

	action();
}