예제 #1
0
파일: tracepath6.c 프로젝트: gygy/asuswrt
int probe_ttl(int fd, int ttl)
{
	int i;
	char sndbuf[mtu];
	struct probehdr *hdr = (struct probehdr*)sndbuf;

	memset(sndbuf, 0, mtu);

restart:

	for (i=0; i<10; i++) {
		int res;

		hdr->ttl = ttl;
		switch (family) {
		case AF_INET6:
			((struct sockaddr_in6 *)&target)->sin6_port = htons(base_port + hisptr);
			break;
		case AF_INET:
			((struct sockaddr_in *)&target)->sin_port = htons(base_port + hisptr);
			break;
		}
		gettimeofday(&hdr->tv, NULL);
		his[hisptr].hops = ttl;
		his[hisptr].sendtime = hdr->tv;
		if (sendto(fd, sndbuf, mtu-overhead, 0, (struct sockaddr *)&target, targetlen) > 0)
			break;
		res = recverr(fd, ttl);
		his[hisptr].hops = 0;
		if (res==0)
			return 0;
		if (res > 0)
			goto restart;
	}
	hisptr = (hisptr + 1) & 63;

	if (i<10) {
		data_wait(fd);
		if (recv(fd, sndbuf, sizeof(sndbuf), MSG_DONTWAIT) > 0) {
			printf("%2d?: reply received 8)\n", ttl);
			return 0;
		}
		return recverr(fd, ttl);
	}

	printf("%2d:  send failed\n", ttl);
	return 0;
}
예제 #2
0
파일: tracepath6.c 프로젝트: 274914765/C
int probe_ttl (int fd, int ttl)
{
    int i;

    char sndbuf[mtu];

    struct probehdr *hdr = (struct probehdr *) sndbuf;

  restart:

    for (i = 0; i < 10; i++)
    {
        int res;

        hdr->ttl = ttl;
        gettimeofday (&hdr->tv, NULL);
        if (send (fd, sndbuf, mtu - overhead, 0) > 0)
            break;
        res = recverr (fd, ttl);
        if (res == 0)
            return 0;
        if (res > 0)
            goto restart;
    }

    if (i < 10)
    {
        int res;

        data_wait (fd);
        if (recv (fd, sndbuf, sizeof (sndbuf), MSG_DONTWAIT) > 0)
        {
            printf ("%2d?: reply received 8)\n", ttl);
            return 0;
        }
        res = recverr (fd, ttl);
        if (res == 1)
            goto restart;
        return res;
    }

    printf ("%2d:  send failed\n", ttl);
    return 0;
}
예제 #3
0
int probe_ttl(int fd, int ttl)
{
	int i;
	struct probehdr *hdr = pktbuf;

	memset(pktbuf, 0, mtu);
restart:
	for (i=0; i<10; i++) {
		int res;

		hdr->ttl = ttl;
		target.sin_port = htons(base_port + hisptr);
		gettimeofday(&hdr->tv, NULL);
		his[hisptr].hops = ttl;
		his[hisptr].sendtime = hdr->tv;
		if (sendto(fd, pktbuf, mtu-overhead, 0, (struct sockaddr*)&target, sizeof(target)) > 0)
			break;
		res = recverr(fd, ttl);
		his[hisptr].hops = 0;
		if (res==0)
			return 0;
		if (res > 0)
			goto restart;
	}
	hisptr = (hisptr + 1)&63;

	if (i<10) {
		data_wait(fd);
		if (recv(fd, pktbuf, mtu, MSG_DONTWAIT) > 0) {
			printf("%2d?: reply received 8)\n", ttl);
			return 0;
		}
		return recverr(fd, ttl);
	}

	printf("%2d:  send failed\n", ttl);
	return 0;
}