Re: Sockets in C unter Unix
Dierk Fröhling <[email protected]>
| Newsgroups | gmane.linux.suse.programming |
|---|---|
| Organization | aycan |
| Message-ID | <[email protected]> |
Nils Meinert wrote:
> Hallo,
>
> die Datei im Anahng hat die Reise wohl nicht angetreten, daher den
> Source-Coude hier im Text:
> ----snip-----
> #include <stdio.h>
> #include <sys/socket.h>
> #include <sys/types.h>
> #include <netinet/in.h>
> #include <netdb.h>
> int main(argc, argv)
> int argc;
> char *argv[];
> {
> int s;
> struct sockaddr_in server;
> struct hostent *hp;
>
> if(argc !=2) {
> fprintf(stderr, "usage: client <hostname>\n");
> exit(2);
> }
> s = socket(AF_INET, SOCK_STREAM, 0);
> if(s < 0){
> perror("open stream socket");
> exit(1);
> }
>
> server.sin_family = AF_INET;
> hp = gethostbyname(argv[1]);
> if(hp == NULL) {
> fprintf(stderr, "%s unknown host. \n", argv[1]);
> }
> bcopy(hp->h_addr, &server.sin_family, hp->h_length);
Das muß heißen:
bcopy(hp->h_addr, &server.sin_addr, hp->h_length);
> server.sin_port = 12006;
> if(connect(s, &server, sizeof(struct sockaddr_in)) <0) {
> perror("connecting stream socket");
> exit(1);
> }
> write(s, "testitagain", strlen("testitagain"),0);
> close(s);
>
> exit(0);
> }
> ---snap------
>
--
Mit freundlichen Grüßen
Best regards
// Dierk Froehling
// aycan Digitalsysteme GmbH
// Innere Aumuehlstrasse 5
// 97076 Wuerzburg
// Germany
// phone: +49.931.270 40 90
// fax: +49.931.270 40 91
// mailto:[email protected]
// http://www.aycan.de
--
Um die Liste abzubestellen, schicken Sie eine Mail an:
[email protected]
Um eine Liste aller verfügbaren Kommandos zu bekommen, schicken
Sie eine Mail an: [email protected]