mfunyu / ft_traceroute

Recoding the traceroute command to deepen the knowledge of the network (TCP/IP) by following the paths that an IP packet will take between two machines.
0 stars 0 forks source link

[feature] try SOCK_DGRAM on SOCK_RAW permission error #3

Open mfunyu opened 3 months ago

mfunyu commented 3 months ago
      t->icmpfd = socket (PF_INET, SOCK_RAW, protocol->p_proto);
      if (t->icmpfd < 0 && (errno == EPERM || errno == EACCES))
        {
          /* A subprivileged user on GNU/Linux might be allowed
           * to create ICMP packets from a datagram socket.
           * Such packets are always severely crippled.
           */
          errno = 0;
          t->icmpfd = socket (PF_INET, SOCK_DGRAM, protocol->p_proto);
          t->no_ident++;

          /* Recover error message for non-Linux systems.  */
          if (errno == EPROTONOSUPPORT)
        errno = EPERM;
        }

      if (t->icmpfd < 0)
        error (EXIT_FAILURE, errno, "socket");