In this network programming homework, we are asked to build SOCKS4 server and client and combine HW3 to demo.

Spec is not included; however, the basic architecture can be illustrated as follows: rbs_diagram

There are some notable ideas I came up with:

For SOCKS client (CGI):

  • Same as HW3. Just need to send SOCK4 requset and handle SOCK4 reply.

For SOCKS Server:

- CONNECT mode procedure:

accept → read SOCKS req → check firewall rules →
connect to dest host → send SOCKS reply → redirect data

- BIND mode procedure:

accept → read SOCKS req → check firewall rules →
bind socket → listen → send SOCKS reply → 
accpet from server → send SOCKS reply (to original client) → redirect data

- When redirecting data, should avoid using strncpy since it may contain '\0' in data, which occasionally leads to data error (less bytes are copied than expected).
- When bind with system-assigned port, give 0 to sockaddr_in.sin_port.

Demo video:
np_hw4_demo

Source → cyhuang1230/NetworkProgramming

For SOCKS client (CGI):
Please look for NP_project4_Server.cpp.
To try: make hw4_cgi , upload to a HTTP server and run <BASE_URL>/hw4.cgi.

For SOCKS server:
Please look for NP_project4_Server.cpp.
To try: make hw4_server and run ./np_hw4.