Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
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;
}
Ejemplo n.º 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;
}
Ejemplo n.º 4
0
uint32_t probe_mtu(unsigned int mtu, unsigned int *new_mtu) {
	unsigned int retry = 0;
	uint32_t error;
	int ret;
	char buf[max_mtu];
	memset(buf, 0, sizeof(buf));
	while (retry < 10) {
#ifdef DEBUG
		printf("probe_mtu retry %d\n", retry);
#endif
		ret = sendto(sockfd, buf, mtu - headerlen, 0, target, target_len);
		error = get_error(new_mtu);
#ifdef DEBUG
		printf("probe_mtu error %d\n", error);
#endif
		if (error != 0) {
			if (error != EMSGSIZE && error != ECONNREFUSED) {
				++retry;
				continue;
			} else {
				return error;
			}
		}
		data_wait();
		if (recv(sockfd, buf, sizeof(buf), MSG_DONTWAIT) > 0) {
#ifdef DEBUG
			printf("probe_mtu got response -> active port -> change port");
#endif
			set_port(target, base_port + retry);
		}
		++retry;
		continue;
	}
	// return the last error
	return error;
}