From owner-freebsd-current@freebsd.org Thu Aug 4 07:15:02 2016 Return-Path: Delivered-To: freebsd-current@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 50EE9BAE73F for ; Thu, 4 Aug 2016 07:15:02 +0000 (UTC) (envelope-from julian@freebsd.org) Received: from vps1.elischer.org (vps1.elischer.org [204.109.63.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "vps1.elischer.org", Issuer "CA Cert Signing Authority" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 2E3F61827; Thu, 4 Aug 2016 07:15:01 +0000 (UTC) (envelope-from julian@freebsd.org) Received: from Julian-MBP3.local (ppp121-45-226-8.lns20.per1.internode.on.net [121.45.226.8]) (authenticated bits=0) by vps1.elischer.org (8.15.2/8.15.2) with ESMTPSA id u747Esae000893 (version=TLSv1.2 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Thu, 4 Aug 2016 00:14:58 -0700 (PDT) (envelope-from julian@freebsd.org) Subject: Re: Socket sendmsg() porting question To: "Lundberg, Johannes" , Alan Somers References: Cc: FreeBSD Current From: Julian Elischer Message-ID: Date: Thu, 4 Aug 2016 15:14:49 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.22 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: Thu, 04 Aug 2016 07:15:02 -0000 On 4/08/2016 1:18 AM, Lundberg, Johannes wrote: > ​Hi Alan > > Thanks for the reply. > > Can I still use the same receiving function for sendmsg/send and tell what > kind of message is coming? > How would I tell if there is an fd attached or not? > > Even if I set cmsg_level and cmsg_type it won't let me send it. The problem > is having a zero length attachment on freebsd.... > I can't send -1 as fd because that errors to invalid file descriptor. > > > On Wed, Aug 3, 2016 at 10:12 AM, Alan Somers wrote: > >> On Wed, Aug 3, 2016 at 10:54 AM, Lundberg, Johannes >> wrote: >>> Hi >>> >>> I'm porting a project to fbsd and I have problem with this part that >> works >>> in linux but not fbsd when fd = -1. >>> >>> https://github.com/Cloudef/wlc/blob/master/src/session/fd.c#L80-L108 >>> >>> I get "invalid argument" from sendmsg() when setting CMSG_LEN(0). >>> >>> Anyone have a clue how to correctly do this on fbsd? >>> >>> Thanks! >>> >>> Johannes >>> >> It sounds like you're trying to send an empty cmsg. The error may >> happen because your msg_controllen field is inconsistent with your >> cmsg_len field. You're setting msg_controllen as if there were a full >> cmsg, but then cmsg_len says that there is no cmsg. Or maybe the >> error is because (just guessing) FreeBSD doesn't allow sending empty >> or undefined cmsgs. Notice that cmsg_level and cmsg_type are >> undefined in the case where fd == -1. POSIX doesn't say whether >> sendmsg supports empty cmsgs, but why bother? You could just use send >> instead of sendmsg if you're not sending a file descriptor. >> >> -Alan >> I think it's a standards interpretation thing. what data do you send WITH the message? I assume you have some in-band data as well. if you have no FD, just use "sendto()." the other end will still be able to do a recvmesg() but will discover no added info.