From owner-freebsd-current@FreeBSD.ORG Fri Jun 28 06:47:51 2013 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 5519A3F9 for ; Fri, 28 Jun 2013 06:47:51 +0000 (UTC) (envelope-from trond@fagskolen.gjovik.no) Received: from smtp.fagskolen.gjovik.no (smtp.fagskolen.gjovik.no [IPv6:2001:700:1100:1:200:ff:fe00:b]) by mx1.freebsd.org (Postfix) with ESMTP id A2A401841 for ; Fri, 28 Jun 2013 06:47:50 +0000 (UTC) Received: from mail.fig.ol.no (localhost [127.0.0.1]) by mail.fig.ol.no (8.14.7/8.14.7) with ESMTP id r5S6lgh4002508 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 28 Jun 2013 08:47:42 +0200 (CEST) (envelope-from trond@fagskolen.gjovik.no) Received: from localhost (trond@localhost) by mail.fig.ol.no (8.14.7/8.14.7/Submit) with ESMTP id r5S6lf3J002505; Fri, 28 Jun 2013 08:47:42 +0200 (CEST) (envelope-from trond@fagskolen.gjovik.no) X-Authentication-Warning: mail.fig.ol.no: trond owned process doing -bs Date: Fri, 28 Jun 2013 08:47:41 +0200 (CEST) From: =?ISO-8859-1?Q?Trond_Endrest=F8l?= Sender: Trond.Endrestol@fagskolen.gjovik.no To: Sreenivasa Honnur Subject: RE: IPv6 - sobind fails with 49 In-Reply-To: Message-ID: References: User-Agent: Alpine 2.00 (BSF 1167 2008-08-23) Organization: Fagskolen Innlandet OpenPGP: url=http://fig.ol.no/~trond/trond.key MIME-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="2055831798-1377063132-1372402062=:1345" X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on mail.fig.ol.no Cc: "'freebsd-current@freebsd.org'" X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Jun 2013 06:47:51 -0000 This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --2055831798-1377063132-1372402062=:1345 Content-Type: TEXT/PLAIN; charset=ISO-8859-1 Content-Transfer-Encoding: 8BIT On Fri, 28 Jun 2013 04:05-0000, Sreenivasa Honnur wrote: > I am writing a kernel socket program which binds to a IPv6 address, so bind always fails with 49. Below is the code snippet I am using, is something wrong here? > > roundhay# uname -a > FreeBSD roundhay 9.1-RELEASE FreeBSD 9.1-RELEASE #2: Mon Apr 8 16:15:06 IST 2013 root@roundhay:/usr/obj/home/freebsd.org/sys/TOED amd64 > > Ifconfig/ping6 output: > ====================== > cxgbe1: flags=8843 metric 0 mtu 1500 > options=6c07bb > ether 00:07:43:11:89:88 > inet6 2010::102 prefixlen 64 > inet6 fe80::207:43ff:fe11:8988%cxgbe1 prefixlen 64 scopeid 0xd > inet6 fe80::1%cxgbe1 prefixlen 64 scopeid 0xd > nd6 options=21 > media: Ethernet 10Gbase-SR > status: active > > roundhay# ping6 2010::101 > PING6(56=40+8+8 bytes) 2010::102 --> 2010::101 > 16 bytes from 2010::101, icmp_seq=0 hlim=64 time=0.915 ms > 16 bytes from 2010::101, icmp_seq=1 hlim=64 time=0.168 ms > ^C > --- 2010::101 ping6 statistics --- > 2 packets transmitted, 2 packets received, 0.0% packet loss > round-trip min/avg/max/std-dev = 0.168/0.541/0.915/0.374 ms Warning: I haven't dabbled in programming FreeBSD kernel internals, but I have done some socket programming some years ago. You failed to present the line declaring sock. The prototype for socreate is: int socreate(int dom, struct socket **aso, int type, int proto, struct ucred *cred, struct thread *td); The second argument expects a pointer to a pointer to a socket (a struct socket). The memory for the socket will be allocated by socreate() and a pointer returned through the formal argument aso. I only hope you declared sock as: struct socket *sock; Next, it would probably be wise to clear saddr6 before assigning values to its members, something along: memset((void *)&saddr6, 0, sizeof(saddr6)); or even: bzero((void *)&saddr6, sizeof(saddr6)); That's all I can think of atm. Maybe someone more knowledgeable on FreeBSD internals can assist you further. > Code: > > struct sockaddr_in6 saddr6; > rv = socreate(AF_INET6, &sock, SOCK_STREAM, IPPROTO_TCP, > td->td_ucred, td); > > if (rv != 0) { > printf("sock create ipv6 %s failed %d.\n", > tbuf, rv); > return NULL; > } > > saddr6.sin6_family = AF_INET6; > rv = inet_pton(AF_INET6, "2010::102", &saddr6.sin6_addr); ==> returns 1, which indicates it's a valid IPV6 address > printf("inet_pton retunred:%d\n", rv); > > saddr6.sin6_port = htons(3260); > saddr6.sin6_len = sizeof(saddr6); > > rv = sobind(sock, (struct sockaddr *)&saddr6, td); ==> fails with return value of 49 -- +-------------------------------+------------------------------------+ | Vennlig hilsen, | Best regards, | | Trond Endrestøl, | Trond Endrestøl, | | IT-ansvarlig, | System administrator, | | Fagskolen Innlandet, | Gjøvik Technical College, Norway, | | tlf. mob. 952 62 567, | Cellular...: +47 952 62 567, | | sentralbord 61 14 54 00. | Switchboard: +47 61 14 54 00. | +-------------------------------+------------------------------------+ --2055831798-1377063132-1372402062=:1345--