Archive for March, 2008
Socks V5 Proxy – Communicating the port number
At work I recently implemented a Socks V5 interface to a proprietary network gateway server. Anyhow, facing one side is a Socks V5 server that lives up to the standard set in RFC 1928. On the other side is our fancy network stuff. The protocol is quite simple and can pretty much be implemented just from the RFC.
One part threw me for a loop though. When Socks V5 retrieves the port number from the client application. Here is what the protocol looks like in the RFC:
The SOCKS request is formed as follows:
+----+-----+-------+------+-- --------+----------+
|VER | CMD | RSV | ATYP | DST.ADDR | DST.PORT |
+----+-----+-------+------+----------+----------+
| 1 | 1 | X'00' | 1 | Variable | 2 |
+----+-----+-------+------+----------+----------+
Where:
o VER protocol version: X'05' o CMD o CONNECT X'01' o BIND X'02' o UDP ASSOCIATE X'03' o RSV RESERVED o ATYP address type of following address o IP V4 address: X'01' o DOMAINNAME: X'03' o IP V6 address: X'04' o DST.ADDR desired destination address o DST.PORT desired destination port in network octet order
The DST.PORT field is a little tricky to encode / decode. The protocol takes an Integer port number and jams it into a two-byte field. I suspect there is some simple windows sdk function to do this, but I chose to go the hard way.
The socks server needs to Decode it. I needed a DWORD:
DWORD dwPort = ((((DWORD)portBuffer[2]) << 8) | (DWORD)portBuffer[3])
Then how the heck do you encode it, just in case you want to simulate a client? Try this:
int highByte = remotePort >> 8; //shift right to drop the bottom 8 digits int lowByte = remotePort & 0xFF; //mask with 255 to drop the high 8 digits recvdPort[2] = highByte; recvdPort[3] = lowByte;
See the bit-shift by 8? That is the same as 2^8=256. 0xFF = 255
No commentsTop 5 Reasons it sucks to be an Engineering Student
From Wired Blogs:
http://blog.wired.com/wiredscience/2008/03/top-5-reasons-i.html
I’m going to plagiarize the article a bit.
5. Awful Textbooks
4. Professors are Rarely Encouraging
During each class, a professor that would rather be tending to his research will waltz up to a blackboard or overhead projector and scribble out equations for an hour without uttering a single sentence to create some excitement.
Hi Five! The author couldn’t have been more Spot On. I remember this one prof i had for ECE 205 (Electrical and Computer Engineering). I don’t remember his name but I think it was Dr Zhao or something close. Anyway, after one particularly dull and monotonic lecture where Z scribbled formulas onto the blackboard with his back to us for a Solid Hour, I went with a friend to his apartment apartment and he wrote to the newsgroup “Hi I’m Doctor Z. I really have to go home and take a dump, so instead of teaching you anything i’ll copy the book onto the blackboard.”
Unfortunately he didn’t cover up his name or anything. Stupid! He called him into his office and asked if he had any problems with his teaching methods. Not like he would have cared anyway! Luckily he was a fair guy, perhaps he even had a sense of humor. Dr Z told him, “Ordinarily I’d give you a C in the class and forget it, but I can understand why you are frustrated”. He didn’t say he Wouldn’t give a C, and I think he did anyway. Well, lesson learned.
3. Dearth of Quality Counseling
My adviser was so uncaring and inattentive that the only advice I got from his office was from his secretary, a woman who didn’t even go to college, forget about UIUC engineering.
2. Other Disciplines Have Inflated Grades
1. Every Assignment Feels the Same
