Help with sockets

This is a discussion on Help with sockets within the C Programming forums, part of the General Programming Boards category; Hi, I need to open a non standard TCP (high) port though a proxy server in order to connect via ...

  1. #1
    tpe
    tpe is offline
    Registered User
    Join Date
    Nov 2010
    Posts
    21

    Help with sockets

    Hi,
    I need to open a non standard TCP (high) port though a proxy server in order to connect via company's proxy server to another server. The proxy is Squid, but allows traffic to the specific port we need to access.
    How can I open the socket from my C program in order to connect via the proxy server? My suspicion is to use 2 connections, one to the proxy server and then to the target server. If that is correct, how can I do that?
    Cheers,
    Peter

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,175
    It should just be one connection to the proxy server. The proxy server in turn will contact the target server for you.
    If you understand what you're doing, you're not learning anything.

  3. #3
    tpe
    tpe is offline
    Registered User
    Join Date
    Nov 2010
    Posts
    21
    Code:
    open_stream (const char *host, unsigned int  port)
    {
    	struct addrinfo *res, *addr, hints;
    	static char      service[6];
    	int              sock, ret;
    
    	sprintf (service, "%hu", port);
    
    	memset (&hints, 0, sizeof (hints));
    	hints.ai_socktype = SOCK_STREAM;
    	hints.ai_flags = AI_CANONNAME;
    
    	ret = getaddrinfo (hostname, service, &hints, &res);
    	if (ret != 0) {
    		return -1;
    	}
            sock = -1;
    	for (addr = res; addr; addr = addr->ai_next) {
    		sock = socket (addr->ai_family, addr->ai_socktype, addr->ai_protocol);
    This is the code in question. Now, if I open the stream to the proxy server, then, how will I instruct the proxy to open a connection to the target server? The socket to the proxy server, is pretty simple. But from then on, I have no clue on how to continue...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Best way to poll sockets?
    By 39ster in forum Networking/Device Communication
    Replies: 3
    Last Post: 07-22-2008, 02:43 PM
  2. multiple UDP sockets with select()
    By nkhambal in forum Networking/Device Communication
    Replies: 2
    Last Post: 01-17-2006, 07:36 PM
  3. Raw Sockets and SP2...
    By Devil Panther in forum Networking/Device Communication
    Replies: 11
    Last Post: 08-12-2005, 05:52 AM
  4. Asynchronous sockets
    By dpro in forum Networking/Device Communication
    Replies: 4
    Last Post: 12-20-2004, 06:53 PM
  5. Starting window sockets
    By _Cl0wn_ in forum Windows Programming
    Replies: 2
    Last Post: 01-20-2003, 11:49 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21