From owner-freebsd-questions Sat Mar 14 04:22:18 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id EAA02292 for freebsd-questions-outgoing; Sat, 14 Mar 1998 04:22:18 -0800 (PST) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from peedub.muc.de (ns1126.munich.netsurf.de [195.180.235.126]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id EAA02230 for ; Sat, 14 Mar 1998 04:22:05 -0800 (PST) (envelope-from garyj@peedub.muc.de) Received: from peedub.muc.de (localhost [127.0.0.1]) by peedub.muc.de (8.8.8/8.6.9) with ESMTP id NAA13992 for ; Sat, 14 Mar 1998 13:23:09 +0100 (CET) Message-Id: <199803141223.NAA13992@peedub.muc.de> X-Mailer: exmh version 2.0.1 12/23/97 To: freebsd-questions@FreeBSD.ORG Subject: Re: accept fails me -- why? Reply-To: Gary Jennejohn In-reply-to: Your message of "Sat, 14 Mar 1998 01:08:39 CST." <199803140708.BAA22691@pobox.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Sat, 14 Mar 1998 13:23:08 +0100 From: Gary Jennejohn Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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 >#include >#include > >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