On Sat, 2002-09-21 at 00:21, Hans Zaunere wrote:
> 
> 4.2.3 on FreeBSD 4.6.2....  (--enable-cli,--enable-sockets,etc)
> 
> I've been taking a look at the socket_* functions in PHP, and
> specifically using raw sockets.  I've started out with ICMP, and I can
> form the ICMP header (more or less) and send it out with an
> insufficient TTL; and as expected I get a ICMP 11 (Time Exceeded)
> response from an enroute gateway.  However, when I set a proper TTL
> (32, for example) I see the packet arrive at the remote host, however
> it is apparently dropped.
> 
> So a couple things have come up:
> 
> -- I'm guessing that the socket_* functions, except socket_read() and
> socket_write(), are not binary safe?

socket_read() and socket_write() are binary safe, but there was a binary
safety issue in socket_recvfrom that is fixed in CVS

> -- While it seems the STREAM and DGRAM sockets work as expected for the
> most part, what about RAW sockets?  I find that the underlying
> functions work fine to create the socket, etc, however I'm having a
> hard time working with the binary data in PHP.  For instance, creating
> the header and then reading it seems tortuous.  Any hints/remedies for
> this?  I think sockets, and especially raw, could be very handy in PHP,
> and would like to know how/if this functionality will be expanded (hey,
> the world needs another traceroute/ping program right?).  I was on my
> way to writing this in PHP, but have fell on hard times with binary
> manipulation.
> 

The best way to do this kind of thing is to use the pack/unpack
functions. _HOWEVER_, php internally treats all numbers as signed
values. Which will make what you are doing almost impossible. pack could
be modified to correct this, but it could be lost if you did something
like a right shift on the value. (PHP currently only supports an
arithmetic right shift).

> -- Another problem I've run into, and again concerning binary
> manipulation, is forming the correct Internet Checksum (rfc1071).  I'm
> not the handiest with bit tricks, but I tried to model the in_cksum()
> function and just couldn't get very far.  Any ideas/tips on this?

This is most likely because of the right shift problem I mentioned
above. However, it would probably be better to just make a php function
which performs an internet checksum.

 
> A clean, but at the same time low-level/raw socket interface I think
> would be extremely useful and I'd like to help in any way I can.

To be honest, I haven't spent much time on making sure that all the
functionality with RAW sockets is there. However, not considering signed
issues, pack/unpack, /ext/sockets, and that checksum function should
give you the functionality you need.

If you notice any issues with the sockets extension in this area, email
me and I will fix them. Also, if you have come up with, or are planning
on making patches in this area, I would gladly accept them : )

Thanks,

-Jason



 
> Thanks!
> 
> Hans
> 
> 
> 
> 
> 
> 
> __________________________________________________
> Do you Yahoo!?
> New DSL Internet Access from SBC & Yahoo!
> http://sbc.yahoo.com
> 
> -- 
> PHP Development Mailing List <http://www.php.net/>
> To unsubscribe, visit: http://www.php.net/unsub.php
> 



-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to