exercises/ex04/trout/trout.c
void loop_ttl (int max_ttl)
{
  int ttl, done;

  Pipe (pipefd);     /* the pipe for the alarm handler */

  recvfd = socket (sasend->sa_family, SOCK_RAW, IPPROTO_ICMP);
  if (recvfd == -1) {
    if (errno == EPERM) {
      printf ("\nclink was unable to open a raw socket.  The most\n");
      printf ("likely cause is that you are not running it as root.\n");
      exit (1);
    } else {
      err_sys ("opening raw socket in clink");
    }
  }

  fcntl (recvfd, F_SETFL, O_NONBLOCK);
  setuid (getuid ());

  sendfd = socket (sasend->sa_family, SOCK_DGRAM, 0);

  sabind->sa_family = sasend->sa_family;
  sport = (getpid() & 0xffff) | 0x8000;       /* source UDP port # */
  sock_set_port (sabind, salen, htons(sport));
  Bind (sendfd, sabind, salen);

  Signal (SIGALRM, sig_alrm);

  for (ttl = 1; ttl <= max_ttl; ttl++) {
    done = send_probes (ttl);
    if (done > 0) break;
  }
}
/* loop_ttl: starting with ttl=1, gradually increase ttl until
   we start getting ICMP_DEST_UNREACH instead of ICMP_TIME_EXCEEDED */
starting with ttl=1, gradually increase ttl until
we start getting ICMP_DEST_UNREACH instead of ICMP_TIME_EXCEEDED
starting with ttl = 1 gradually increase ttl until we start getting ICMP_DEST_UNREACH instead of ICMP_TIME_EXCEEDED
void loop_ttl (int max_ttl)
{
  int ttl, done;
  Pipe (pipefd);     
  recvfd = socket (sasend->sa_family, SOCK_RAW, IPPROTO_ICMP);
  if (recvfd == -1) {
    if (errno == EPERM) {
      printf ("\nclink was unable to open a raw socket.  The most\n");
      printf ("likely cause is that you are not running it as root.\n");
      exit (1);
    } else {
      err_sys ("opening raw socket in clink");
    }
  }
  fcntl (recvfd, F_SETFL, O_NONBLOCK);
  setuid (getuid ());
  sendfd = socket (sasend->sa_family, SOCK_DGRAM, 0);
  sabind->sa_family = sasend->sa_family;
  sport = (getpid() & 0xffff) | 0x8000;       
  sock_set_port (sabind, salen, htons(sport));
  Bind (sendfd, sabind, salen);
  Signal (SIGALRM, sig_alrm);
  for (ttl = 1; ttl <= max_ttl; ttl++) {
    done = send_probes (ttl);
    if (done > 0) break;
  }
}
void loop_ttl ( int max_ttl ) { int ttl , done ; Pipe ( pipefd ) ; recvfd = socket ( sasend -> sa_family , SOCK_RAW , IPPROTO_ICMP ) ; if ( recvfd == -1 ) { if ( errno == EPERM ) { printf ( " \n \n " ) ; printf ( " \n " ) ; exit ( 1 ) ; } else { err_sys ( " " ) ; } } fcntl ( recvfd , F_SETFL , O_NONBLOCK ) ; setuid ( getuid ( ) ) ; sendfd = socket ( sasend -> sa_family , SOCK_DGRAM , 0 ) ; sabind -> sa_family = sasend -> sa_family ; sport = ( getpid ( ) & 0xffff ) | 0x8000 ; sock_set_port ( sabind , salen , htons ( sport ) ) ; Bind ( sendfd , sabind , salen ) ; Signal ( SIGALRM , sig_alrm ) ; for ( ttl = 1 ; ttl <= max_ttl ; ttl ++ ) { done = send_probes ( ttl ) ; if ( done > 0 ) break ; } }
loop_ttl: starting with ttl=1, gradually increase ttl until
we start getting ICMP_DEST_UNREACH instead of ICMP_TIME_EXCEEDED
loop_ttl : starting with ttl = 1 gradually increase ttl until we start getting ICMP_DEST_UNREACH instead of ICMP_TIME_EXCEEDED
/* the pipe for the alarm handler */ /* source UDP port # */