I am learning how to work with raw sockets on Linux. I am trying to create a socket like this:
if ((sd = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP)) < 0) { perror("socket() failed"); exit(-1); }
But all I got after launch:
socket () failed: operation not allowed
I know that only root can create raw sockets, but if I run it with the SUID or sudo bit, the problem is the same. What's wrong? Ubuntu 11.04 system.
Perhaps I include unnecessary headers?
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <errno.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/ip.h> #include <netinet/ip_icmp.h> #include <netdb.h> #include <sys/time.h> #include <signal.h> #include <unistd.h>
And I wonder - why is SUID useless?
source share