LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-04-2008, 06:16 AM   #1
shifter
Member
 
Registered: May 2006
Distribution: Slackware, DragonFly
Posts: 233

Rep: Reputation: 30
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
 
Old 08-04-2008, 08:00 AM   #2
shifter
Member
 
Registered: May 2006
Distribution: Slackware, DragonFly
Posts: 233

Original Poster
Rep: Reputation: 30
ok problem solved with accept function
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
breaking out of accept() with interrupts (socket question) hatha Programming 1 07-16-2005 05:33 AM
C: Socket weirdness: select() -> fork() -> accept() maxfacta Programming 1 03-01-2005 01:33 PM
(c++) network socket programming: help with accept() Dark Carnival Programming 4 08-11-2004 04:22 PM
Function accept() and its arguments. krajzega Programming 1 01-20-2004 01:26 AM
Problem with accept() socket call which doesn't return jph Programming 4 08-06-2003 06:30 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration