If the third and fourth bytes are supposed to be for the destination port how do you split up the port number between those two bytes?
Very carefully with alot of practice.
You need to convert the value to a byte array, then stick it in.
Converting it depends on your langauge.
Visual Basic
A method that a lot of beginning Visual Basic users use is to convert the port (an integer) to a hexadecimal value using the Hex() function, then use Val() for each byte (meaning twice), using a different part of the result from Hex().
Dim Result As String // the result goes into here, to be written to the network stream
Dim HexStr As String // temporary buffer for hexadecimal string
Dim Port As Integer // the port you want to write to the network stream
Port = 6112
HexStr = Right("000" & Hex(Port), 4)
Result = Val("&h" & Left(HexStr, 2)) & Val("&h" & Right(HexStr, 2))
Note that this does not consider endianness, which may be incorrect for most Visual Basic implementations trying to make use of the SOCKS protocol.
endianness? explain...
0x0001 is 1 on one platform, whereas it's 65536 on another platform.
No, it isn't. ;) 65536 = 2**16 = 0x10000. You forgot a zero. :)
Oh well, I was slightly distracted when I posted that. Here's the corrected statement:
Quote from: tA-Kane on February 18, 2005, 06:45 PM0x0001 is 1 on one platform, whereas it's 256 on another platform.