Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP and RAW SOCKETS on linux

Is it enough to do a

sudo setcap cap_net_raw=eip /usr/bin/php5

to be able to use RAW SOCKETS in PHP (not CLI) in Linux ?

If yes, well it is not working (but started to work in CLI but not using Apache)

So I guess I have to give those permissions to Apache as well, but I couldn't find out how.

Can you help me?

errors from the PHP script : Warning: socket_create(): Unable to create socket [1]: Operation not permitted in

the php script :

$package = "\x08\x00\x7d\x4b\x00\x00\x00\x00PingHost";
        $socket = socket_create(AF_INET, SOCK_RAW, 1);
        if ($socket !== false) {
            socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => 10, 'usec' => 0));
            echo 'Creating PING Socket !';

            socket_connect($socket, gethostbyname('noczone.com'), null);
            socket_send($socket, $package, strLen($package), 0);
            if (socket_read($socket, 255)) {
                $result = microtime(true) - $ts;
            } else {
                echo 'Error Code : No PING';
            }
            socket_close($socket);
        } else {
            echo 'Failed Creating PING Socket !';
        }
like image 523
Rami Dabain Avatar asked May 22 '13 08:05

Rami Dabain


People also ask

How use raw socket in Linux?

Raw sockets allow new IPv4 protocols to be implemented in user space. A raw socket receives or sends the raw datagram not including link level headers. The IPv4 layer generates an IP header when sending a packet unless the IP_HDRINCL socket option is enabled on the socket.

What are Linux raw sockets?

RAW-sockets are an additional type of Internet socket available in addition to the well known DATAGRAM- and STREAM-sockets. They do allow the user to see and manipulate the information used for transmitting the data instead of hiding these details, like it is the case with the usually used STREAM- or DATAGRAM sockets.

What is the purpose of raw socket?

The raw socket interface provides direct access to lower layer protocols, such as the Internet Protocol (IP) and Internet Control Message Protocol (ICMP or ICMPv6). You can use raw sockets to test new protocol implementations.


Video Answer


1 Answers

Have you tried: sudo setcap cap_net_raw=eip $(which httpd) ?

What's the error you're getting?

like image 60
David Sarmiento Avatar answered Sep 22 '22 02:09

David Sarmiento