N

From: Date: Sat, 10 Oct 2009 23:43:29 +0000
Subject: N
Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-6685@lists.php.net to get a copy of this message
I've come across the need for the ability to ping and traceroute without making use of an exec() call. I've thoroughly examined the source code for the Linux-native ping and traceroute, and believe this is something I could, theoretically, port to PHP. The problem I've come across in my research is two-fold: 1) In order to perform traceroutes, specifically, I need to be able to manipulate the actual raw IP headers at the top of each outgoing packet. Specifically, I need to be able to manipulate the time-to-live (TTL) for outgoing packets and inspect the contents of the headers of received packets. It doesn't appear as if using the SOCK_RAW option and the IP (raw) protocol flag (0) in socket_create actually gives me control over the IP headers for each packet. It is exhibiting behavior that is not the same as what you get from similar C code. The fact that sock_connect and/or sock_sendto absolutely require an IP address, even with SOCK_RAW and 0 used in sock_create, leads me to believe that the native PHP socket functions are still adding standard internet headers to the top of the packets I'm trying to send. 2) Using the SOCK_RAW option requires being root. This obviously doesn't lend itself to using this with a web interface or anything else, for that matter, that isn't run as root. So it occurred to me that perhaps a PECL extension to allow the sending and receiving of individual packets and (controlled, for security reasons) manipulation of their headers would perhaps solve my problems and allow me to utilize this new extension for implementing ping and traceroute natively. I'm sure this would solve my first problem. However, because I'm unfamiliar with the security restrictions placed on PHP running as an Apache module and in CLI, I don't know if this solves my problem of needing to be root to use raw packet sockets. Any insights and suggestions would be greatly appreciated. Can this be accomplished through some other means in PHP? Am I missing something or doing something wrong? Would a new PECL extension that enables the direct manipulation of packets and headers be possible and work for this? Or is this simply something that's going to be impossible to implement in PHP? Thanks in advance for any responses, Nick Williams

« previous php.pecl.dev (#6685) next »