3
0

create_icmp6_socket.c 829 B

123456789101112131415161718192021222324252627282930313233343536
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Utility routines.
  4. *
  5. * create raw socket for icmp (IPv6 version) protocol
  6. * and drop root privileges if running setuid
  7. */
  8. #include "libbb.h"
  9. #if ENABLE_FEATURE_IPV6
  10. int FAST_FUNC create_icmp6_socket(void)
  11. {
  12. int sock;
  13. #if 0
  14. struct protoent *proto;
  15. proto = getprotobyname("ipv6-icmp");
  16. /* if getprotobyname failed, just silently force
  17. * proto->p_proto to have the correct value for "ipv6-icmp" */
  18. sock = socket(AF_INET6, SOCK_RAW,
  19. (proto ? proto->p_proto : IPPROTO_ICMPV6));
  20. #else
  21. sock = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
  22. #endif
  23. if (sock < 0) {
  24. if (errno == EPERM)
  25. bb_error_msg_and_die(bb_msg_perm_denied_are_you_root);
  26. bb_perror_msg_and_die(bb_msg_can_not_create_raw_socket);
  27. }
  28. /* drop root privs if running setuid */
  29. xsetuid(getuid());
  30. return sock;
  31. }
  32. #endif