000
23.04.2009, 19:48 Uhr
~sokcetzman
Gast
|
Code: |
/*server function*/ #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/socket.h> #include <netdb.h> #include <netinet/in.h> #include <arpa/inet.h> #include <unistd.h> #include <string.h>
#define BUFFER_SIZE 1024
/* int server (int port) { int s, c, cli_size; struct sockaddr_in srv, cli;
s = socket(AF_INET, SOCK_STREAM, 0); if (s == -1) return -1; srv.sin_addr.s_addr = INADDR_ANY; srv.sin_port = htons( (unsigned short int) port); srv.sin_family = AF_INET; if (bind(s, (struct sockaddr*)&srv, sizeof(srv)) == -1) return -1; if (listen(s, 3) == -1) return -1;
cli_size = sizeof(cli); c = accept(s, &cli, &cli_size); return s; }*/
int s (int test) { int s, c, cli_size; struct sockaddr_in srv, cli;
s = socket(AF_INET, SOCK_STREAM, 0); if (s == -1) { perror("socket() failed"); return 2; } srv.sin_addr.s_addr = INADDR_ANY; srv.sin_port = htons( (unsigned short int)80); srv.sin_family = AF_INET; if (bind(s, (struct sockaddr*)&srv, sizeof(srv)) == -1) { perror("bind() failed"); return 3; } if (listen(s, 3) == -1) { perror("listen() failed"); return 4; } for(;;) { cli_size = sizeof(cli); c = accept(s, (struct sockaddr*)&cli, &cli_size); printf("client from %s", inet_ntoa(cli.sin_addr)); //close(c); } return 0; }
|
Zitat: |
g++ server.cpp -o server In file included from server.cpp:4: sockets.h: In function »int s(int)«: sockets.h:73: Fehler: ungültige Umwandlung von »int*« in »socklen_t*« sockets.h:73: Fehler: Argument 3 von »int accept(int, sockaddr*, socklen_t*)« wird initialisiert
|
Vielen Dank schon mal für die Hilfen! |