Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 14 Mar 1998 13:23:08 +0100
From:      Gary Jennejohn <garyj@peedub.muc.de>
To:        freebsd-questions@FreeBSD.ORG
Subject:   Re: accept fails me -- why? 
Message-ID:  <199803141223.NAA13992@peedub.muc.de>
In-Reply-To: Your message of "Sat, 14 Mar 1998 01:08:39 CST." <199803140708.BAA22691@pobox.com> 

next in thread | previous in thread | raw e-mail | index | archive | help
Tony Kimball writes:
>
>I thought I understood this stuff cold... but now I wonder...
>In this trivial program, the accept call fails with EINVAL.  Go
>figure.  Any suggestions?
>
>#include <sys/types.h>
>#include <sys/socket.h>
>#include <netinet/in.h>
>
>int 
>main(int ac, char **av) {
>   int server_port;
>   int server_fd;
>   int client_fd;
>   struct sockaddr_in sname;
>   int arg = sizeof(sname);
>   int one = 1;
>
>   server_port = 2001;
>   server_fd = socket(AF_INET, SOCK_STREAM, 0);
>   if (server_fd == -1) 
>       perror("server socket failed");
>   setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, (void *)&one, sizeof(one));
>    
>   sname.sin_family = AF_INET;
>   sname.sin_port = htons((u_short)server_port);
>   sname.sin_addr.s_addr = INADDR_ANY;
>   if (bind(server_fd,(struct sockaddr *)&sname,sizeof(sname))) 
>       perror("server bind failed");
>   client_fd = accept(server_fd,(struct sockaddr *)&sname,&arg);
>   if (client_fd == -1)
>       perror("client accept failed");
>}
>

where's the listen(2) call ? See the accept manpage.

---
Gary Jennejohn
Home - garyj@muc.de
Work - garyj@fkr.dec.com



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199803141223.NAA13992>