error with accept function and socket
I have an error at accept function: invalid argument. My code is:
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
int main(int argc, char*argv[])
{
int sockfd, connectFd, portn, clientlen, nbyte;
char buffer[256];
struct sockaddr_in addrserv, addrclient;
int listenFd;
int cltlen;
if (argc < 2) printf("Devi inserire il numero di porta");
listenFd = socket(AF_INET, SOCK_STREAM, 0);
if (listenFd < 0)
perror("Errore nella apertura del socket");
bzero(&addrserv, sizeof(addrserv));
portn = atoi(argv[1]);
addrserv.sin_family = AF_INET;
addrserv.sin_addr.s_addr = htonl(INADDR_ANY);
addrserv.sin_port = htons(portn);
if (bind(listenFd, (struct sockaddr*)&addrserv, sizeof(addrserv)) < 0)
perror("Errore nella operazione di bind sul server");
listen(sockfd, 5);
cltlen = sizeof(addrclient);
printf("%d", accept(listenFd, (struct sockaddr*)&addrclient, &cltlen));
return 0;
}
What is the problem?
Can anyone help me, I am desperated and I must to finish
|