Hi Everyone

I am developing for Linux and am looking for a way to retrieve HTTP pages from the internet, I have found a couple of tutorials that have shown me how to get the basics sorted out:

Code:
    
    int sockid;
    int bufsize;
    char buffer[2048];

    struct sockaddr_in socketaddr;
    struct hostent *hostaddr;
    struct servent *servaddr;
    struct protoent *protocol;

    bool threadActive = true;

	while(threadActive) {

	    if (!(hostaddr = gethostbyname(my_data->seed))) {
            fprintf(stderr, "Error resolving host: %s", my_data->seed);
            exit(1);
        } // if

        else printf("%s", hostaddr->h_name);

        /* clear and initialize socketaddr */
        memset(&socketaddr, 0, sizeof(socketaddr));
        socketaddr.sin_family = AF_INET;

        /* setup the servent struct using getservbyname */
        servaddr = getservbyname(SERVICE, PROTOCOL);
        socketaddr.sin_port = servaddr->s_port;

        memcpy(&socketaddr.sin_addr, hostaddr->h_addr, hostaddr->h_length);

        protocol = getprotobyname(PROTOCOL);

        sockid = socket(AF_INET, SOCK_STREAM, protocol->p_proto);

        if (sockid < 0) {
            fprintf(stderr, "Error creating socket.");
            exit(1);
        } // if

        if(connect(sockid, (struct sockaddr*)&socketaddr, sizeof(socketaddr)) == -1) {
            fprintf(stderr, "Error connecting.");
            exit(1);
        } // if

        /* send our get request for http */
        if (send(sockid, GET, strlen(GET), 0) == -1) {
            fprintf(stderr, "Error sending data.");
            exit(1);
        } // if

        /* read the socket until its clear then exit */
        while ( (bufsize = read(sockid, buffer, sizeof(buffer) - 1))) {
            write(1, buffer, bufsize);
        } // while

        close(sockid);
Whilst this works to some degree it does not seem to actually get the http page I am after (for example Google and I get:

HTTP/1.1 302 Found
Location: Google
Cache-Control: private
Content-Type: text/html; charset=UTF-8
Set-Cookie: PREF=ID=d861ae030e872f6e:TM=1279574897:LM=12795748 97:S=nfk6koUtrUvXVYpI; expires=Wed, 18-Jul-2012 21:28:17 GMT; path=/; domain=.google.com
Set-Cookie: NID=36=a1WKldAuUvvHIjy_sBH3aI0iH1J-0KEXW5fRisfGG9jDNj_fEDs9wn3x4sF3STR6D0lbxAGWwxu7Ju Rujy4OJyfYoPGG7XaaiODMvRizwLz5CnDUL0d3YjRS62Bp4l8J ; expires=Tue, 18-Jan-2011 21:28:17 GMT; path=/; domain=.google.com; HttpOnly
Date: Mon, 19 Jul 2010 21:28:17 GMT
Server: gws
Content-Length: 221
X-XSS-Protection: 1; mode=block

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="http://www.google.co.uk/">here</A>.
</BODY></HTML>
returned instead of the actual google homepage. I think It's got something to do with the way I cam creating and directing the socket to the google address, in that its using it as a address, where in actual fact I want it to be using the http address / http protocol (perhaps).

Any suggestions would be most welcome!

David