How do I add a proxy to tcpclient code? Thank you.

Source: Internet
Author: User
How do I add a proxy to tcpclient code? Thank you-general Linux technology-Linux programming and kernel information. For more information, see the following. First write a tcp socket C/S program
Now I want to write a program command line to give the network address to get the webpage content, but to access the specified Webpage Through the proxy, the webpage content is also returned by the proxy


How should I add code?

Below is the tcp client code
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include

# Define SERVERPORT 8888
# Define maxbuckets 1024

Int main (int argc, char * argv [])
{
Int sockd;
Int counter;
Int fd;
Struct sockaddr_in xferServer;
Char buf [MAXBUF];
Int returnStatus;

If (argc <3)
{
Fprintf (stderr, "Usage: % s [Dest filename] \ n ",
Argv [0]);
Exit (1 );
}
/* Create a socket */
Sockd = socket (AF_INET, SOCK_STREAM, 0 );
If (sockd =-1)
{
Fprintf (stderr, "cocould not create socket! \ N ");
Exit (1 );
}
/* Set up the server information */
XferServer. sin_family = AF_INET;
XferServer. sin_addr.s_addr = inet_addr (argv [1]);
XferServer. sin_port = htons (SERVERPORT );
/* Connect to the server */
ReturnStatus = connect (sockd,
(Struct sockaddr *) & xferServer,
Sizeof (xferServer ));
If (returnStatus =-1)
{
Fprintf (stderr, "cocould not connect to server! \ N ");
Exit (1 );
}

/* Send the name of the file we want to the server */
ReturnStatus = write (sockd, argv [2], strlen (argv [2]) + 1 );
If (returnStatus =-1)
{
Fprintf (stderr, "cocould not send filename to server! \ N ");
Exit (1 );
}

/* Call shutdown to set our socket to read-only */
Shutdown (sockd, SHUT_WR );

/* Open up a handle to our destination file to receive the contents */
/* From the server */
Fd = open (argv [3], O_WRONLY | O_CREAT | O_APPEND );
If (fd =-1)
{
Fprintf (stderr, "cocould not open destination file, using stdout. \ n ");
Fd = 1;
}

/* Read the file from the socket as long as there is data */
Int I = 0;
While (counter = read (sockd, buf, MAXBUF)> 0)
{
/* Send the contents to stdout */
Fprintf (stdout, "write for the % d time \ n", ++ I );
Write (fd, buf, counter );
}
If (counter =-1)
{
Fprintf (stderr, "cocould not read file from socket! \ N ");
Exit (1 );
}
Close (sockd );
Return 0;
}

Please help. Thank you.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.