Esempio n. 1
0
void				ft_analyse(char *buf, int cc, struct sockaddr_in *from)
{
	struct ip		*ip;
	int				hlen;
	struct icmp		*icp;
	double			triptime;
	struct timeval	tv;

	ip = (struct ip *)buf;
	hlen = ip->ip_hl << 2;
	if (cc < hlen + ICMP_MINLEN)
	{
		if (e.options & OPT_VERBOSE)
			fprintf(stderr, "packet too short (%d bytes) from %s",
					cc,
					inet_ntoa(from->sin_addr));
		return ;
	}
	cc -= hlen;
	icp = (struct icmp *)(buf + hlen);
	if (icp->icmp_type == ICMP_ECHOREPLY)
	{
		if (icp->icmp_id != e.ident)
			return ;
		e.nreceived++;
		ft_memcpy(&tv, &icp->icmp_ip, sizeof(struct timeval));
		if ((e.end_time.tv_usec -= tv.tv_usec) < 0)
		{
			--e.end_time.tv_sec;
			e.end_time.tv_usec += 1000000;
		}
		e.end_time.tv_sec -= tv.tv_sec;
		triptime = ((double)e.end_time.tv_sec) * 1000.0 +
			((double)e.end_time.tv_usec) / 1000.0;
		if (!ft_strcmp(e.srcip, "127.0.0.1"))
			triptime /= 10;
		if (triptime < e.tmin)
			e.tmin = triptime;
		if (triptime > e.tmax)
			e.tmax = triptime;
		if (!(e.options & OPT_QUIET))
		{
			printf("%d bytes from %s: icmp_seq=%u", cc,
				   print_from(from), ntohs(icp->icmp_seq));
			print_data(cc, icp, ip, triptime);
		}
	}
	else if (ft_print_err(from, icp) != 0)
		return ;
}
Esempio n. 2
0
int		slave(t_script *args, int fd_slave, int fd_master)
{
	char *tab[3];

	tab[0] = NULL;
	tab[1] = "-i";
	tab[2] = NULL;
	(void)fd_master;
	dup2(fd_slave, 0);
	dup2(fd_slave, 1);
	dup2(fd_slave, 2);
	close(fd_slave);
	setsid();
	ioctl(0, TIOCSCTTY, 1);
	if (args->command == NULL || !args->command[0])
	{
		if ((tab[0] = m_getenv("SHELL", args->env)) == NULL)
			tab[0] = DSHELL;
		return (ft_print_err(ft_getexec(tab, args->env), tab[0]));
	}
	else
		return (ft_print_err(ft_getexec(args->command, args->env),
			args->command[0]));
}