Article View: de.comp.os.unix.programming
Article #3Re: socket -1 Problem
From: Stefan Taferner
Date: Tue, 15 Apr 2003 09:44
Date: Tue, 15 Apr 2003 09:44
57 lines
2315 bytes
2315 bytes
Bau mal folgendes ein....
Michael Gschwandtner wrote:
> #include <sys/socket.h>
> #include <netdb.h>
> #include <netinet/in.h>
> #include <stdio.h>
> #include <unistd.h>
> #include <string.h>
> #include <arpa/inet.h>
#include <errno.h>
>
> int main(int argc,char *argv[])
> {
> hostent *h;
> struct sockaddr_in sad;
> int sock,received;
> char *req="GET / HTTP/1.0\n\n",inbuff[65000];
>
> h = gethostbyname ( argv[1] );
>
> sad.sin_port=htons(80);
> memcpy ( &sad.sin_addr.s_addr, h->h_addr_list[0],4 );
> sad.sin_family=AF_INET;
>
> sock = socket ( AF_INET, SOCK_STREAM, 0 );
if (sock < 0)
{
printf("cannot create socket: %s\n", strerror(errno));
exit(1);
}
> if ( connect ( sock, (struct sockaddr *)&sad, sizeof(struct
> sockaddr_in) ) != -1 )
> {
> printf ("Connected\n");
> write ( sock , req, 16 );
> printf ("Wrote Request\n");
>
> while ( ( received = read ( sock, inbuff, 65000 ) ) != -1 )
> {
> printf ( "received: %i\n", received );
> }
> }
else
printf("cannot connect to %s: %s\n", argv[1], strerror(errno));
>
>
> close ( sock );
>
> return 0;
> }
Technical Details
Message-ID:
<b7gk97$98l$1@paperboy.Austria.EU.net>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!newsfeed.vmunix.org!newsfeed.eunet.at!newsfeed.eunet.at!paperboy.Austria.EU.net!not-for-mailReferences:
<3E9B28B2.70902@tznetz.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1101c9,b26a14702a46d53e X-Google-Attributes: gid1101c9,public X-Google-Thread: f8ff7,b26a14702a46d53e X-Google-Attributes: gidf8ff7,public X-Google-ArrivalTime: 2003-04-15 02:44:08 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!newsfeed.vmunix.org!newsfeed.eunet.at!newsfeed.eunet.at!paperboy.Austria.EU.net!not-for-mail From: Stefan Taferner <taferner@nospam-please.kde.org> Newsgroups: de.comp.os.unix.programming,at.linux Subject: Re: socket -1 Problem Followup-To: de.comp.os.unix.programming Date: Tue, 15 Apr 2003 11:44:07 +0200 Organization: EUnet-AG.at EDV and Internet Service AG Lines: 58 Message-ID: <b7gk97$98l$1@paperboy.Austria.EU.net> References: <3E9B28B2.70902@tznetz.com> NNTP-Posting-Host: gatekeeper.porsche.co.at Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: paperboy.Austria.EU.net 1050399847 9493 193.109.74.10 (15 Apr 2003 09:44:07 GMT) X-Complaints-To: abuse@EUnet-AG.at NNTP-Posting-Date: Tue, 15 Apr 2003 09:44:07 +0000 (UTC) User-Agent: KNode/0.7.2