Valhalla Legends Archive

Programming => Battle.net Bot Development => Topic started by: I_Smell_Tuna on February 14, 2005, 09:33 PM

Title: Question about SOCKS4
Post by: I_Smell_Tuna on February 14, 2005, 09:33 PM
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?
Title: Re: Question about SOCKS4
Post by: shout on February 14, 2005, 09:37 PM
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.
Title: Re: Question about SOCKS4
Post by: I_Smell_Tuna on February 14, 2005, 09:41 PM
Visual Basic
Title: Re: Question about SOCKS4
Post by: tA-Kane on February 15, 2005, 02:39 AM
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.
Title: Re: Question about SOCKS4
Post by: NetNX on February 18, 2005, 09:27 AM
endianness? explain...
Title: Re: Question about SOCKS4
Post by: tA-Kane on February 18, 2005, 06:45 PM
0x0001 is 1 on one platform, whereas it's 65536 on another platform.
Title: Re: Question about SOCKS4
Post by: Kp on February 18, 2005, 08:17 PM
No, it isn't. ;)  65536 = 2**16 = 0x10000.  You forgot a zero. :)
Title: Re: Question about SOCKS4
Post by: tA-Kane on February 19, 2005, 03:09 AM
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.