Re: Sockets in C unter Unix

"Nils Meinert" <[email protected]>
Newsgroups gmane.linux.suse.programming
Message-ID <[email protected]>
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);
	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------

-- 
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]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.