From owner-freebsd-net@FreeBSD.ORG Wed Oct 27 11:46:05 2010 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9661E1065672 for ; Wed, 27 Oct 2010 11:46:05 +0000 (UTC) (envelope-from marius@nuenneri.ch) Received: from mail-qy0-f182.google.com (mail-qy0-f182.google.com [209.85.216.182]) by mx1.freebsd.org (Postfix) with ESMTP id 5C2668FC16 for ; Wed, 27 Oct 2010 11:46:05 +0000 (UTC) Received: by qyk33 with SMTP id 33so609816qyk.13 for ; Wed, 27 Oct 2010 04:46:04 -0700 (PDT) Received: by 10.229.184.68 with SMTP id cj4mr8838256qcb.48.1288178342480; Wed, 27 Oct 2010 04:19:02 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.221.7 with HTTP; Wed, 27 Oct 2010 04:18:42 -0700 (PDT) In-Reply-To: References: From: =?UTF-8?Q?Marius_N=C3=BCnnerich?= Date: Wed, 27 Oct 2010 13:18:42 +0200 Message-ID: To: dave jones Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: freebsd-net@freebsd.org Subject: Re: UDP socket disconnect problem X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 Oct 2010 11:46:05 -0000 On Tue, Sep 28, 2010 at 11:58, dave jones wrote: > Hello, > > In Linux, I can disconnect the socket using: > sa.sin_family =3D AF_UNSPEC; > val =3D connect(sockfd, (struct sockaddr *)&sa, sizeof(sa)); > > the return value of val is 0; on freebsd, the return value of connect() i= s -1. > According to Linux's connect(2) man page: > > Connectionless sockets may dissolve > the association by connecting to an address with the =C2=A0sa_family =C2= =A0member > of sockaddr set to AF_UNSPEC > > but FreeBSD's connect says: > Datagram sockets may dissolve the association by connecting > =C2=A0to an invalid address, such as a null address. > > I try to convert above code to > memset(&sa, 0, sizeof(sa)); > sa.sin_addr.s_addr =3D htonl(INADDR_ANY); > val =3D connect(sockfd, (struct sockaddr *)&sa, sizeof(sa)); > > the return value of val still -1. Any idea? Thanks. Just curious, why are you not using close()?