Main index | Section 4 | Options |
#include <sys/types.h>
#include <netgraph/ng_ksocket.h>
A ng_ksocket node allows at most one hook connection. Connecting to the node is equivalent to opening the associated socket. The name given to the hook determines what kind of socket the node will open (see below). When the hook is disconnected and/or the node is shutdown, the associated socket is closed.
Data received into socket is sent out via hook. Data received on hook is sent out from socket, if the latter is connected (an NGM_KSOCKET_CONNECT was sent to node before). If socket is not connected, destination struct sockaddr must be supplied in an mbuf tag with cookie NGM_KSOCKET_COOKIE and type NG_KSOCKET_TAG_SOCKADDR attached to data. Otherwise ng_ksocket will return ENOTCONN to sender.
NGM_KSOCKET_BIND ( bind) | |
This functions exactly like the bind(2) system call. The struct sockaddr socket address parameter should be supplied as an argument. | |
NGM_KSOCKET_LISTEN ( listen) | |
This functions exactly like the listen(2) system call. The backlog parameter (a single 32 bit int) should be supplied as an argument. | |
NGM_KSOCKET_CONNECT ( connect) | |
This functions exactly like the connect(2) system call. The struct sockaddr destination address parameter should be supplied as an argument. | |
NGM_KSOCKET_ACCEPT ( accept) | |
Equivalent to the
accept(2)
system call on a non-blocking socket.
If there is a pending connection on the queue,
a new socket and a corresponding cloned node are created.
Returned are the cloned node's ID and a peer name (as
struct sockaddr).
If there are no pending connections,
this control message returns nothing,
and a connected node will receive the above message asynchronously,
when a connection is established.
A cloned node supports a single hook with an arbitrary name. If not connected, a node disappears when its parent node is destroyed. Once connected, it becomes an independent node. | |
NGM_KSOCKET_GETNAME ( getname) | |
Equivalent to the getsockname(2) system call. The name is returned as a struct sockaddr in the arguments field of the reply. | |
NGM_KSOCKET_GETPEERNAME ( getpeername) | |
Equivalent to the getpeername(2) system call. The name is returned as a struct sockaddr in the arguments field of the reply. | |
NGM_KSOCKET_SETOPT ( setopt) | |
Equivalent to the setsockopt(2) system call, except that the option name, level, and value are passed in a struct ng_ksocket_sockopt. | |
NGM_KSOCKET_GETOPT ( getopt) | |
Equivalent to the getsockopt(2) system call, except that the option is passed in a struct ng_ksocket_sockopt. When sending this command, the value field should be empty; upon return, it will contain the retrieved value. | |
Examples:
PF_LOCAL | |
local/"/tmp/foo.socket" | |
PF_INET | inet/192.168.1.1:1234 |
Other | amp;{ family=16 len=16 data=[0x70 0x00 0x01 0x23] amp;} |
For control messages that pass a struct ng_ksocket_sockopt, the normal ASCII form for that structure is used. In the future, more convenient encoding of the more common socket options may be supported.
Setting socket options example:
Set FIB 2 for a socket (SOL_SOCKET, SO_SETFIB): | |
setopt amp;{ level=0xffff name=0x1014 data=[ 2 ] amp;} | |
NG_KSOCKET (4) | January 9, 2012 |
Main index | Section 4 | Options |
Please direct any comments about this manual page service to Ben Bullock. Privacy policy.
“ | A child of 5 could understand this! Fetch me a child of 5. | ” |