Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 14 Feb 2002 07:00:42 -0800
From:      Terry Lambert <tlambert2@mindspring.com>
To:        Aleksander Rozman - Andy <andy@kksonline.com>
Cc:        freebsd-hackers@FreeBSD.ORG
Subject:   Re: Fwd: socket options (struct sockopt)
Message-ID:  <3C6BD11A.B8FF58F2@mindspring.com>
References:  <5.0.2.1.0.20020214143320.0665a0c0@213.161.0.10>

next in thread | previous in thread | raw e-mail | index | archive | help
Aleksander Rozman - Andy wrote:
> >Hi !
> >I am working on implementation of AX.25 on fbsd (as you probably already
> >know)... I need to know how to create socket options (for use with
> >xxx_ctlinput, xxx_ctloutput, getsockopt, setsockopt)? In which part of
> >code could I see how socket options are created...
> >
> >Andy

Are you asking this question again, or did you hit "send"
too soon?

I'll assume you are asking again.

First: probably, this question belonged on FreeBSD-net.


The answer for TCP is that the system calls setsockopt()
and getsockopt() in uipc_syscalls.c call sogetopt() and
sosetopt() in uipc_socket.c, respectively, which in turn
dereference the socket structure (see socketvar.h) to
get the so_proto struct protosw protocol switch, then
dereference that to call (*pr_ctloutput).  This structure
is a synonym for the ipprotosw structure (for no good
reason) defined in ipprotosw.h.  For a TCP SOCK_STREAM,
this results in a call of tcp_ctloutput() in tcp_usrreq.c
because it is the per protocol entry for SOCK_STREAM in 
the inetsw[] array of "struct iiprotosw" protocol
entry points in in_proto.c.

This code then handles the per protocol socket option.

To write your own code for this for X.25, you will
need to include a protosw for X.25 in the protocol
registration, with a pr_ctloutput entry.  Then
when you call setsockopt/getsockopt on the socket,
you will get the you "x25_ctloutput" called, and
you can decode the option the same way that the
tcp_ctloutput function or the other protocol specific
socket option handling code does (in other words, you
just decode the struct sockopt fields, specifically,
the direction field (SOPT_SET vs. SOPT_GET), and the
options themselves, bit values from sopt_name
...though the tcp_ctloutput() doesn't treat them
as bit values, since some of the TCP options
don't actually take parameters, and you could not
safely fetch more than one at a time, anyway... see
the end of tcp.h.

You need to treat them as bit values, anyway, since
they are set into your protocol structure flags word,
just like TCP, raw, if you do your code correctly
(this avoids a shift transform to get them set in or
masked out).

-- Terry

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?3C6BD11A.B8FF58F2>