Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 29 Jun 2000 00:43:32 -0700
From:      Mike Smith <msmith@freebsd.org>
To:        Wilbert de Graaf <wilbertdg@hetnet.nl>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: Getting the plain void* through the generic ioctl processing 
Message-ID:  <200006290743.AAA01760@mass.osd.bsdi.com>
In-Reply-To: Your message of "Wed, 28 Jun 2000 12:21:03 PDT." <395A501F.50CA476E@hetnet.nl> 

next in thread | previous in thread | raw e-mail | index | archive | help
> Could anybody advise me on this:
> 
> For an implementation of IGMPv3, I had to extend the socket api
> following the draft(s). I had to add two ioctl commands:
> SIO_GET_MULTICAST_FILTER and SIO_SET_MULTICAST_FILTER. The argument is a
> 
> structure that has a variable size. FreeBSD uses some macros, and the
> one I added looks like
> 
> #define SIO_SET_MULTICAST_FILTER    _IOWR('s', 63, struct ip_msfilter*)
> 
> I couldn't use 'struct ip_msfilter' since this structure has a variable
> size. Now this macro makes a unsigned long from all this, where the
> length of the structure is encoded using sizeof(struct ip_msfilter*).
> This makes the ioctl pre-processing (sys_generic.c) copy 4 bytes from
> this pointer into the kernel. But this data is worthless to me, since it
> 
> is the first 4 bytes of the structure itself. What I want is the pointer
> 
> itself.

This is what this should give you - a pointer to the structure 
_in_user_space_.

> I understand that I can do this by making people pass the
> address of a pointer to ioctl(), but this is kind of ugly I think. And
> besides, the other OS'es don't need this.

The ioctl interface is standard, everyone does it this way.  If you think 
about it for a moment, when you're defining an _IOWR() ioctl, you're 
telling the macros that you want the kernel to be able to modify the 
pointer that you're passing in, so of course it has to have storage space 
in user space.

If you're passing in a pointer to a structure elsewhere, you should be 
using _IOR() anyway, since you don't want the pointer copied back out.  
In this case, the interface is the same purely for orthagonality's sake.

-- 
\\ Give a man a fish, and you feed him for a day. \\  Mike Smith
\\ Tell him he should learn how to fish himself,  \\  msmith@freebsd.org
\\ and he'll hate you for a lifetime.             \\  msmith@cdrom.com




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




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