RE: [PHP] "Byte Array"
| From: | Ford, Mike | Date: | Tue, 14 Dec 2004 20:52:07 +0000 |
| Subject: | RE: [PHP] "Byte Array" | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-204336@lists.php.net to get a copy of this message | ||
To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm
> -----Original Message-----
> From: Ian Firla
> Sent: 14/12/04 17:52
>
> On Tue, 2004-12-14 at 08:40 -0800, Richard Lynch wrote:
> > Ian Firla wrote:
> > >
> > > Just a follow-up to myself... I decided to try packet sniffing to
see
> > > what was going on and ettercap confirms that I'm sending out strings
> > > rather than data of the type stored in my array:
> > >
> > > 16:12:26 192.168.0.101:32779 --> 192.168.0.88:32896 | UDP |
> > >
> > > 0000: 3331 31
> > >
> > > That "31" should be an integer of only one byte, not two.
> >
> > I suspect that PHP is converting your integers into strings at some
> point,
> > as you build the array...
> >
> > *WHERE* it is doing that is difficult to say, without seeing more
code.
It's not at all difficult. The definition of fwrite is:
int fwrite (resource handle, string string [, int length])
So the second parameter is converted to a string as it passes in to fwrite.
This is not at all unexpected -- it's kind of the file(/stream/whatever)
analogue of echo or print.
To get what you really want -- i.e. a 1-byte binary representation of your
value -- you'll have to encode it as the appropriate character and then send
that. Two possible ways to do that are with pack() and chr().
Cheers!
Mike