Valhalla Legends Forums Archive | Battle.net Bot Development | Question about SOCKS4

AuthorMessageTime
I_Smell_Tuna
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?
February 15, 2005, 3:33 AM
shout
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.
February 15, 2005, 3:37 AM
I_Smell_Tuna
Visual Basic
February 15, 2005, 3:41 AM
tA-Kane
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().

[code]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))[/code]

Note that this does not consider endianness, which may be incorrect for most Visual Basic implementations trying to make use of the SOCKS protocol.
February 15, 2005, 8:39 AM
NetNX
endianness? explain...
February 18, 2005, 3:27 PM
tA-Kane
0x0001 is 1 on one platform, whereas it's 65536 on another platform.
February 19, 2005, 12:45 AM
Kp
No, it isn't. ;)  65536 = 2**16 = 0x10000.  You forgot a zero. :)
February 19, 2005, 2:17 AM
tA-Kane
Oh well, I was slightly distracted when I posted that. Here's the corrected statement:
[quote author=tA-Kane link=topic=10565.msg100467#msg100467 date=1108773907]0x0001 is 1 on one platform, whereas it's 256 on another platform.[/quote]
February 19, 2005, 9:09 AM

Search