tech-net archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Socket options KPI



Iain Hibbert wrote:

I'm looking into this some more but finding some trouble. Its not really
possible to separate the 'sockopt' from the netbt protocol layers because
it is necessary to know the length of the data before you extract
anything. So, the sockopt will have to be passed down.

I don't see sockopt_get/sockopt_set in the FreeBSD code (that I have), are
you willing to consider changing sockopt_get() from

void *
sockopt_get(const struct sockopt *sopt, size_t len)
{
        if (sopt->sopt_un == NULL || sopt->sopt_size != len)
                return NULL;

        return (void *)sopt->sopt_un;
}

to

int
sockopt_get(const struct sockopt *sopt, void *buf, size_t len)
{

        if (sopt->sopt_un == NULL || sopt->sopt_size != len)
                return EINVAL;

        memcpy(buf, sopt->sopt_un, sopt->sopt_size);
        return 0;
}

?

IMHO this results in cleaner code (see below for what I've made in the
L2CAP case). It also mirrors sockopt_set() which also does the copy and
returns an errno(2). It means that you have to have a (probably stack
based) variable but I prefer to do that as it removes any alignment
issues. (If you wanted to provide a sockopt_getptr() also I would not
object)

Sure, this sounds good to me and I'll do it unless others object or have
different opinions.

Thanks!

-e.



Home | Main Index | Thread Index | Old Index