--- libdnet-1.12/man/dnet.3.orig 2012-05-23 08:31:15.785689693 -0700
+++ libdnet-1.12/man/dnet.3 2012-05-23 08:46:23.327040849 -0700
@@ -1,206 +1,296 @@
-.\"
+.\"
.\" Copyright (c) 2000 Dug Song <dugsong@monkey.org>
-.\"
+.\"
.\" $Id: dnet.3 604 2005-02-25 22:59:04Z dugsong $
.\"
-.Dd August 21, 2001
-.Dt DNET 3
-.Sh NAME
-.Nm dnet
-.Nd dumb networking library
-.Sh SYNOPSIS
-.Ss Network addressing
-.Ft int
-.Fn addr_cmp "const struct addr *a" "const struct addr *b"
-.Ft int
-.Fn addr_bcast "const struct addr *a" "struct addr *b"
-.Ft int
-.Fn addr_net "const struct addr *a" "struct addr *b"
-.Ft char *
-.Fn addr_ntop "const struct addr *src" "char *dst" "size_t size"
-.Ft int
-.Fn addr_pton "const char *src" "struct addr *dst"
-.Ft char *
-.Fn addr_ntoa "const struct addr *a"
-.Ft int
-.Fn addr_aton "const char *src" "struct addr *dst"
-.Ft int
-.Fn addr_ntos "const struct addr *a" "struct sockaddr *sa"
-.Ft int
-.Fn addr_ston "const struct sockaddr *sa" "struct addr *a"
-.Ft int
-.Fn addr_btos "uint16_t bits" "struct sockaddr *sa"
-.Ft int
-.Fn addr_stob "const struct sockaddr *sa" "uint16_t *bits"
-.Ft int
-.Fn addr_btom "uint16_t bits" "void *mask" "size_t size"
-.Ft int
-.Fn addr_mtob "const void *mask" "size_t size" "uint16_t *bits"
-.Ss Address Resolution Protocol
-.Li typedef Ar int Fn (*arp_handler) "const struct arp_entry *entry" "void *arg"
-.Ft arp_t *
-.Fn arp_open "void"
-.Ft int
-.Fn arp_add "arp_t *a" "const struct arp_entry *entry"
-.Ft int
-.Fn arp_delete "arp_t *a" "const struct arp_entry *entry"
-.Ft int
-.Fn arp_get "arp_t *a" "struct arp_entry *entry"
-.Ft int
-.Fn arp_loop "arp_t *a" "arp_handler callback" "void *arg"
-.Ft arp_t *
-.Fn arp_close "arp_t *a"
-.Ss Binary buffers
-.Ft blob_t *
-.Fn blob_new "void"
-.Ft int
-.Fn blob_read "blob_t *b" "void *buf" "int len"
-.Ft int
-.Fn blob_write "blob_t *b" "const void *buf" "int len"
-.Ft int
-.Fn blob_seek "blob_t *b" "int off" "int whence"
-.Ft int
-.Fn blob_index "blob_t *b" "const void *buf" "int len"
-.Ft int
-.Fn blob_rindex "blob_t *b" "const void *buf" "int len"
-.Ft int
-.Fn blob_pack "blob_t *b" "const void *fmt" "..."
-.Ft int
-.Fn blob_unpack "blob_t *b" "const void *fmt" "..."
-.Ft int
-.Fn blob_print "blob_t *b" "char *style" "int len"
-.Ft blob_t *
-.Fn blob_free "blob_t *b"
-.Ss Ethernet
-.Ft eth_t *
-.Fn eth_open "const char *device"
-.Ft int
-.Fn eth_get "eth_t *e" "eth_addr_t *ea"
-.Ft int
-.Fn eth_set "eth_t *e" "const eth_addr_t *ea"
-.Ft ssize_t
-.Fn eth_send "eth_t *e" "const void *buf" "size_t len"
-.Ft eth_t *
-.Fn eth_close "eth_t *e"
-.Ss Firewalling
-.Li typedef Ar int Fn (*fw_handler) "const struct fw_rule *rule" "void *arg"
-.Ft fw_t *
-.Fn fw_open "void"
-.Ft int
-.Fn fw_add "fw_t *f" "const struct fw_rule *rule"
-.Ft int
-.Fn fw_delete "fw_t *f" "const struct fw_rule *rule"
-.Ft int
-.Fn fw_loop "fw_t *f" "fw_handler callback" "void *arg"
-.Ft fw_t *
-.Fn fw_close "fw_t *f"
-.Ss Network interfaces
-.Li typedef Ar int Fn (*intf_handler) "const struct intf_entry *entry" "void *arg"
-.Ft intf_t *
-.Fn intf_open "void"
-.Ft int
-.Fn intf_get "intf_t *i" "struct intf_entry *entry"
-.Ft int
-.Fn intf_get_src "intf_t *i" "struct intf_entry *entry" "struct addr *src"
-.Ft int
-.Fn intf_get_dst "intf_t *i" "struct intf_entry *entry" "struct addr *dst"
-.Ft int
-.Fn intf_set "intf_t *i" "const struct intf_entry *entry"
-.Ft int
-.Fn intf_loop "intf_t *i" "intf_handler callback" "void *arg"
-.Ft intf_t *
-.Fn intf_close "intf_t *i"
-.Ss Internet Protocol
-.Ft ip_t *
-.Fn ip_open "void"
-.Ft ssize_t
-.Fn ip_add_option "void *buf" "size_t len" "int proto" "const void *optbuf" "size_t optlen"
-.Ft void
-.Fn ip_checksum "void *buf" "size_t len"
-.Ft ssize_t
-.Fn ip_send "ip_t *i" "const void *buf" "size_t len"
-.Ft ip_t *
-.Fn ip_close "ip_t *i"
-.Ss Internet Protocol Version 6
-.Ft void
-.Fn ip6_checksum "void *buf" "size_t len"
-.Ss Random number generation
-.Ft rand_t *
-.Fn rand_open "void"
-.Ft int
-.Fn rand_get "rand_t *r" "void *buf" "size_t len"
-.Ft int
-.Fn rand_set "rand_t *r" "const void *seed" "size_t len"
-.Ft int
-.Fn rand_add "rand_t *r" "const void *buf" "size_t len"
-.Ft uint8_t
-.Fn rand_uint8 "rand_t *r"
-.Ft uint16_t
-.Fn rand_uint16 "rand_t *r"
-.Ft uint32_t
-.Fn rand_uint32 "rand_t *r"
-.Ft int
-.Fn rand_shuffle "rand_t *r" "void *base" "size_t nmemb" "size_t size"
-.Ft rand_t *
-.Fn rand_close "rand_t *r"
-.Ss Routing
-.Li typedef Ar int Fn (*route_handler) "const struct route_entry *entry" "void *arg"
-.Ft route_t *
-.Fn route_open "void"
-.Ft int
-.Fn route_add "route_t *r" "const struct route_entry *entry"
-.Ft int
-.Fn route_delete "route_t *r" "const struct route_entry *entry"
-.Ft int
-.Fn route_get "route_t *r" "struct route_entry *entry"
-.Ft int
-.Fn route_loop "route_t *r" "route_handler callback" "void *arg"
-.Ft route_t *
-.Fn route_close "route_t *r"
-.Ss Tunnel interface
-.Ft tun_t *
-.Fn tun_open "struct addr *src" "struct addr *dst" "int mtu"
-.Ft int
-.Fn tun_fileno "tun_t *t"
-.Ft const char *
-.Fn tun_name "tun_t *t"
-.Ft ssize_t
-.Fn tun_send "tun_t *t" "const void *buf" "size_t size"
-.Ft ssize_t
-.Fn tun_recv "tun_t *t" "void *buf" "size_t size"
-.Ft tun_t *
-.Fn tun_close "tun_t *t"
-.Sh DESCRIPTION
+.TH "DNET" "3" "August 21, 2001" "SunOS 5.11" "Library Functions Manual"
+.SH "NAME"
+\fBdnet\fP
+\- dumb networking library
+.SH "SYNOPSIS"
+#include <dnet.h>
+.SS "Network addressing"
+.LP
+.nf
+int
+addr_cmp(const struct addr *a, const struct addr *b);
+
+int
+addr_bcast(const struct addr *a, struct addr *b);
+
+int
+addr_net(const struct addr *a, struct addr *b);
+
+char *
+addr_ntop(const struct addr *src, char *dst size_t size);
+
+int
+addr_pton(const char *src, struct addr *dst);
+
+char *
+addr_ntoa(const struct addr *a);
+
+int
+addr_aton(const char *src, struct addr *dst);
+
+int
+addr_ntos(const struct addr *a, struct sockaddr *sa);
+
+int
+addr_ston(const struct sockaddr *sa, struct addr *a);
+
+int
+addr_btos(uint16_t bits, struct sockaddr *sa);
+
+int
+addr_stob(const struct sockaddr *sa, uint16_t *bits);
+
+int
+addr_btom(uint16_t bits, void *mask, size_t size);
+
+int
+addr_mtob(const void *mask, size_t size, uint16_t *bits);
+.fi
+.SS "Address Resolution Protocol"
+.LP
+.nf
+typedef int (*arp_handler)(const struct arp_entry *entry, void *arg);
+
+arp_t *
+arp_open(void);
+
+int
+arp_add(arp_t *a, const struct arp_entry *entry);
+
+int
+arp_delete(arp_t *a, const struct arp_entry *entry);
+
+int
+arp_get(arp_t *a, struct arp_entry *entry);
+
+int
+arp_loop(arp_t *a, arp_handler callback, void *arg);
+
+arp_t *
+arp_close(arp_t *a);
+.fi
+.SS "Binary buffers"
+.LP
+.nf
+blob_t *
+blob_new(void);
+
+int
+blob_read(blob_t *b, void *buf, int len);
+
+int
+blob_write(blob_t *b, const void *buf, int len);
+
+int
+blob_seek(blob_t *b, int off, int whence);
+
+int
+blob_index(blob_t *b, const void *buf, int len);
+
+int
+blob_rindex(blob_t *b, const void *buf, int len);
+
+int
+blob_pack(blob_t *b, const void *fmt, ...);
+
+int
+blob_unpack(blob_t *b, const void *fmt, ...);
+
+int
+blob_print(blob_t *b, char *style, int len);
+
+blob_t *
+blob_free(blob_t *b);
+.fi
+.SS "Ethernet"
+.LP
+.nf
+eth_t *
+eth_open(const char *device);
+
+int
+eth_get(eth_t *e, eth_addr_t *ea);
+
+int
+eth_set(eth_t *e, const eth_addr_t *ea);
+
+ssize_t
+eth_send(eth_t *e, const void *buf, size_t len);
+
+eth_t *
+eth_close(eth_t *e);
+.fi
+.SS "Firewalling"
+.LP
+.nf
+typedef int (*fw_handler)(const struct fw_rule *rule, void *arg);
+
+fw_t *
+fw_open void
+
+int
+fw_add(fw_t *f, const struct fw_rule *rule);
+
+int
+fw_delete(fw_t *f, const struct fw_rule *rule);
+
+int
+fw_loop(fw_t *f, fw_handler callback, void *arg);
+
+fw_t *
+fw_close(fw_t *f);
+.fi
+.SS "Network interfaces"
+.LP
+.nf
+typedef int (*intf_handler)(const struct intf_entry *entry void *arg);
+
+intf_t *
+intf_open(void);
+
+int
+intf_get(intf_t *i, struct intf_entry *entry);
+
+int
+intf_get_src(intf_t *i, struct intf_entry *entry, struct addr *src);
+
+int
+intf_get_dst(intf_t *i, struct intf_entry *entry, struct addr *dst);
+
+int
+intf_set(intf_t *i, const struct intf_entry *entry);
+
+int
+intf_loop(intf_t *i, intf_handler callback, void *arg);
+
+intf_t *
+intf_close(intf_t *i);
+.fi
+.SS "Internet Protocol"
+.LP
+.nf
+ip_t *
+ip_open(void);
+
+ssize_t
+ip_add_option(void *buf, size_t len, int proto, const void *optbuf, size_t optlen);
+
+void
+ip_checksum(void *buf, size_t len);
+
+ssize_t
+ip_send(ip_t *i, const void *buf, size_t len);
+
+ip_t *
+ip_close(ip_t *i);
+.fi
+.SS "Internet Protocol Version 6"
+.LP
+.nf
+void
+ip6_checksum(void *buf, size_t len);
+.fi
+.SS "Random number generation"
+.LP
+.nf
+rand_t *
+rand_open(void);
+
+int
+rand_get(rand_t *r, void *buf, size_t len);
+
+int
+rand_set(rand_t *r, const void *seed, size_t len);
+
+int
+rand_add(rand_t *r, const void *buf, size_t len);
+
+uint8_t
+rand_uint8(rand_t *r);
+
+uint16_t
+rand_uint16(rand_t *r);
+
+uint32_t
+rand_uint32(rand_t *r);
+
+int
+rand_shuffle(rand_t *r, void *base, size_t nmemb, size_t size);
+
+rand_t *
+rand_close(rand_t *r);
+.fi
+.SS "Routing"
+.LP
+.nf
+typedef int (*route_handler)(const struct route_entry *entry void *arg);
+
+route_t *
+route_open(void);
+
+int
+route_add(route_t *r, const struct route_entry *entry);
+
+int
+route_delete(route_t *r, const struct route_entry *entry);
+
+int
+route_get(route_t *r, struct route_entry *entry);
+
+int
+route_loop(route_t *r, route_handler callback, void *arg);
+
+route_t *
+route_close(route_t *r);
+.fi
+.SS "Tunnel interface"
+.LP
+.nf
+tun_t *
+tun_open(struct addr *src, struct addr *dst, int mtu);
+
+int
+tun_fileno(tun_t *t);
+
+const char *
+tun_name(tun_t *t);
+
+ssize_t
+tun_send(tun_t *t, const void *buf, size_t size);
+
+ssize_t
+tun_recv(tun_t *t, void *buf, size_t size);
+
+tun_t *
+tun_close(tun_t *t);
+.fi
+.SH "DESCRIPTION"
+\fBdnet\fP
provides a simplified, portable interface to several low-level
networking routines, including network address manipulation, kernel
-.Xr arp 4
-cache and
-.Xr route 4
+arp(8)
+cache and
+route(8)
table lookup and manipulation, network firewalling, network interface
lookup and manipulation, and raw IP packet and Ethernet frame
transmission. It is intended to complement the functionality provided
by
-.Xr pcap 3 .
-In addition,
+pcap(3).
+.PP
+In addition,
+\fBdnet\fP
also provides platform-independent definitions of various network
protocol formats and values for portable low-level network
programming, as well as a simple binary buffer handling API.
-.Ss Network addressing
+.PP
+.SS "Network addressing"
Network addresses are described by the following structure:
-.Bd -literal
+.nf
struct addr {
uint16_t addr_type;
uint16_t addr_bits;
@@ -208,7 +298,7 @@
eth_addr_t __eth;
ip_addr_t __ip;
ip6_addr_t __ip6;
-
+
uint8_t __data8[16];
uint16_t __data16[8];
uint32_t __data32[4];
@@ -220,279 +310,281 @@
#define addr_data8 __addr_u.__data8
#define addr_data16 __addr_u.__data16
#define addr_data32 __addr_u.__data32
+.fi
+.PP
The following values are defined for
-.Ar addr_type :
-.Bd -literal
+\fIaddr_type\fP:
+.nf
#define ADDR_TYPE_NONE 0 /* No address set */
#define ADDR_TYPE_ETH 1 /* Ethernet */
#define ADDR_TYPE_IP 2 /* Internet Protocol v4 */
#define ADDR_TYPE_IP6 3 /* Internet Protocol v6 */
+.fi
+.PP
The field
-.Ar addr_bits
+\fIaddr_bits\fP
denotes the length of the network mask in bits.
-.Fn addr_cmp
+.PP
+addr_cmp
compares network addresses
-.Fa a
+a
and
-.Fa b ,
+b,
returning an integer less than, equal to, or greater than zero if
-.Fa a
+a
is found, respectively, to be less than, equal to, or greater than
-.Fa b .
+b.
Both addresses must be of the same address type.
-.Fn addr_bcast
+.PP
+addr_bcast
computes the broadcast address for the network specified in
-.Fa a
+a
and writes it into
-.Fa b .
-.Fn addr_net
+b.
+.PP
+addr_net
computes the network address for the network specified in
-.Fa a
+a
and writes it into
-.Fa b .
-.Fn addr_ntop
+b.
+.PP
+addr_ntop
converts an address from network format to a string.
-.Fn addr_pton
+.PP
+addr_pton
converts an address (or hostname) from a string to network format.
-.Fn addr_ntoa
+.PP
+addr_ntoa
converts an address from network format to a string, returning a
pointer to the result in static memory.
-.Fn addr_aton
+.PP
+addr_aton
is a synonym for
-.Fn addr_pton .
-.Fn addr_ntos
+addr_pton.
+.PP
+addr_ntos
converts an address from network format to the appropriate struct
sockaddr.
-.Fn addr_ston
+.PP
+addr_ston
converts an address from a struct sockaddr to network format.
-.Fn addr_btos
+.PP
+addr_btos
converts a network mask length to a network mask specified as a struct
sockaddr.
-.Fn addr_stob
+.PP
+addr_stob
converts a network mask specified in a struct sockaddr to a network
mask length.
-.Fn addr_btom
+.PP
+addr_btom
converts a network mask length to a network mask in network byte
order.
-.Fn addr_mtob
+.PP
+addr_mtob
converts a network mask in network byte order to a network mask length.
-.Ss Address Resolution Protocol
+.SS "Address Resolution Protocol"
ARP cache entries are described by the following structure:
-.Bd -literal
+.nf
struct arp_entry {
struct addr arp_pa; /* protocol address */
struct addr arp_ha; /* hardware address */
};
-.Fn arp_open
+.fi
+.PP
+arp_open
is used to obtain a handle to access the kernel
-.Xr arp 4
+arp(8)
cache.
-.Fn arp_add
+.PP
+arp_add
adds a new ARP
-.Fa entry .
-.Fn arp_delete
+entry.
+.PP
+arp_delete
deletes the ARP
-.Fa entry
+entry
for the protocol address specified by
-.Fa arp_pa .
-.Fn arp_get
+arp_pa.
+.PP
+arp_get
retrieves the ARP
-.Fa entry
+entry
for the protocol address specified by
-.Fa arp_pa .
-.Fn arp_loop
+arp_pa.
+.PP
+arp_loop
iterates over the kernel
-.Xr arp 4
+arp(8)
cache, invoking the specified
-.Fa callback
+callback
with each
-.Fa entry
+entry
and the context
-.Fa arg
+arg
passed to
-.Fn arp_loop .
-.Fn arp_close
+arp_loop.
+.PP
+arp_close
closes the specified handle.
-.Ss Binary buffers
+.SS "Binary buffers"
Binary buffers are described by the following structure:
-.Bd -literal
+.nf
typedef struct blob {
u_char *base; /* start of data */
int off; /* offset into data */
int end; /* end of data */
int size; /* size of allocation */
} blob_t;
-.Fn blob_new
+.fi
+.PP
+blob_new
is used to allocate a new dynamic binary buffer, returning NULL on failure.
-.Fn blob_read
-reads
-.Fa len
+.PP
+blob_read
+reads
+len
bytes from the current offset in blob
-.Fa b
+b
into
-.Fa buf ,
+buf,
returning the total number of bytes read, or -1 on failure.
-.Fn blob_write
+.PP
+blob_write
writes
-.Fa len
+len
bytes from
-.Fa buf
+buf
to blob
-.Fa b ,
+b,
advancing the current offset. It returns the number of bytes written,
or -1 on failure.
-.Fn blob_seek
+.PP
+blob_seek
repositions the offset within blob
-.Fa b
-to
-.Fa off ,
+b
+to
+off,
according to the directive
-.Fa whence
+whence
(see
-.Xr lseek 2
+lseek(2)
for details), returning the new absolute offset, or -1 on failure.
-.Fn blob_index
-returns the offset of the first occurence in blob
-.Fa b
+.PP
+blob_index
+returns the offset of the first occurence in blob
+b
of the specified
-.Fa buf
+buf
of length
-.Fa len ,
+len,
or -1 on failure.
-.Fn blob_rindex
-returns the offset of the last occurence in blob
-.Fa b
+.PP
+blob_rindex
+returns the offset of the last occurence in blob
+b
of the specified
-.Fa buf
+buf
of length
-.Fa len ,
+len,
or -1 on failure.
-.Fn blob_pack
+.PP
+blob_pack
converts and writes, and
-.Fn blob_unpack
+blob_unpack
reads and converts data in blob
-.Fa b
+b
according to the given format
-.Fa fmt
+fmt
as described below, returning 0 on success, and -1 on failure.
+.PP
The format string is composed of zero or more directives: ordinary
characters (not
-.Cm %
+\fB%\fP
),
which are copied to / read from the blob, and conversion
specifications, each of which results in reading / writing zero or
more subsequent arguments.
+.PP
Each conversion specification is introduced by the character
-.Cm % ,
+\fB%\fP,
and may be prefixed by length specifier. The arguments must correspond
properly (after type promotion) with the length and conversion specifiers.
+.PP
The length specifier is either a a decimal digit string specifying the
length of the following argument, or the literal character
-.Cm *
+\fB*\fP
indicating that the length should be read from an integer argument for
the argument following it.
+.PP
The conversion specifiers and their meanings are:
-.Bl -tag -width indent
-.It Cm D
+.TP indent
+\fBD\fP
An unsigned 32-bit integer in network byte order.
-.It Cm H
+.TP indent
+\fBH\fP
An unsigned 16-bit integer in network byte order.
-.It Cm b
+.TP indent
+\fBb\fP
A binary buffer (length specifier required).
-.It Cm c
+.TP indent
+\fBc\fP
An unsigned character.
-.It Cm d
+.TP indent
+\fBd\fP
An unsigned 32-bit integer in host byte order.
-.It Cm h
+.TP indent
+\fBh\fP
An unsigned 16-bit integer in host byte order.
-.It Cm s
+.TP indent
+\fBs\fP
A C-style null-terminated string, whose maximum length must be
specified when unpacking.
+.PP
Custom conversion routines and their specifiers may be registered via
-.Fn blob_register_pack ,
+blob_register_pack,
currently undocumented.
-.Fn blob_print
-prints
-.Fa len
+.PP
+blob_print
+prints
+len
bytes of the contents of blob
-.Fa b
+b
from the current offset in the specified
-.Fa style ;
+style;
currently only
-.Dq hexl
+``hexl''
is available.
-.Fn blob_free
+.PP
+blob_free
deallocates the memory associated with blob
-.Fa b
+b
and returns NULL.
-.Ss Ethernet
-.Fn eth_open
+.SS "Ethernet"
+eth_open
is used to obtain a handle to transmit raw Ethernet frames via the
specified network
-.Fa device .
-.Fn eth_get
+device.
+.PP
+eth_get
retrieves the hardware MAC address for the interface specified by
-.Ar e .
-.Fn eth_set
+\fIe\fP.
+.PP
+eth_set
configures the hardware MAC address for the interface specified by
-.Ar e .
-.Fn eth_send
-transmits
-.Fa len
+\fIe\fP.
+.PP
+eth_send
+transmits
+len
bytes of the Ethernet frame pointed to by
-.Fa buf .
-.Fn eth_close
+buf.
+.PP
+eth_close
closes the specified handle.
-.Ss Firewalling
+.SS "Firewalling"
Firewall rules are described by the following structure:
-.Bd -literal
+.nf
struct fw_rule {
char fw_device[INTF_NAME_LEN]; /* interface name */
uint8_t fw_op; /* operation */
@@ -503,51 +595,50 @@
uint16_t fw_sport[2]; /* range / ICMP type */
uint16_t fw_dport[2]; /* range / ICMP code */
};
-The following values are defined for
-.Ar fw_op :
-.Bd -literal
+.fi
+.PP
+The following values are defined for
+\fIfw_op\fP:
+.nf
#define FW_OP_ALLOW 1
#define FW_OP_BLOCK 2
+.fi
+.PP
The following values are defined for
-.Ar fw_dir :
-.Bd -literal
+\fIfw_dir\fP:
+.nf
#define FW_DIR_IN 1
#define FW_DIR_OUT 2
-.Fn fw_open
+.fi
+.PP
+fw_open
is used to obtain a handle to access the local network firewall
configuration.
-.Fn fw_add
+.PP
+fw_add
adds the specified firewall
-.Fa rule .
-.Fn fw_delete
+rule.
+.PP
+fw_delete
deletes the specified firewall
-.Fa rule .
-.Fn fw_loop
+rule.
+.PP
+fw_loop
iterates over the active firewall ruleset, invoking
-the specified
-.Fa callback
-with each
-.Fa rule
+the specified
+callback
+with each
+rule
and the context
-.Fa arg
-passed to
-.Fn fw_loop .
-.Fn fw_close
+arg
+passed to
+fw_loop.
+.PP
+fw_close
closes the specified handle.
-.Ss Network interfaces
+.SS "Network interfaces"
Network interface information is described by the following structure:
-.Bd -literal
+.nf
#define INTF_NAME_LEN 16
struct intf_entry {
@@ -562,292 +653,286 @@
u_int intf_alias_num; /* number of aliases */
struct addr intf_alias_addrs __flexarr; /* array of aliases */
};
+.fi
+.PP
The following bitmask values are defined for
-.Ar intf_type :
-.Bd -literal
+\fIintf_type\fP:
+.nf
#define INTF_TYPE_OTHER 1 /* other */
#define INTF_TYPE_ETH 6 /* Ethernet */
#define INTF_TYPE_LOOPBACK 24 /* software loopback */
#define INTF_TYPE_TUN 53 /* proprietary virtual/internal */
+.fi
+.PP
The following bitmask values are defined for
-.Ar intf_flags :
-.Bd -literal
+\fIintf_flags\fP:
+.nf
#define INTF_FLAG_UP 0x01 /* enable interface */
#define INTF_FLAG_LOOPBACK 0x02 /* is a loopback net (r/o) */
#define INTF_FLAG_POINTOPOINT 0x04 /* point-to-point link (r/o) */
#define INTF_FLAG_NOARP 0x08 /* disable ARP */
#define INTF_FLAG_BROADCAST 0x10 /* supports broadcast (r/o) */
#define INTF_FLAG_MULTICAST 0x20 /* supports multicast (r/o) */
-.Fn intf_open
+.fi
+.PP
+intf_open
is used to obtain a handle to access the network interface
configuration.
-.Fn intf_get
+.PP
+intf_get
retrieves an interface configuration
-.Fa entry ,
+entry,
keyed on
-.Fa intf_name .
-For all
-.Fn intf_get
-functions,
-.Fa intf_len
+intf_name.
+For all
+intf_get
+functions,
+intf_len
should be set to the size of the buffer pointed to by
-.Fa entry
+entry
(usually sizeof(struct intf_entry), but should be larger to accomodate
any interface alias addresses.
-.Fn intf_get_src
+.PP
+intf_get_src
retrieves the configuration for the interface whose primary address
matches the specified
-.Fa src .
-.Fn intf_get_dst
+src.
+.PP
+intf_get_dst
retrieves the configuration for the best interface with which to reach
the specified
-.Fa dst .
-.Fn intf_set
+dst.
+.PP
+intf_set
sets the interface configuration
-.Fa entry .
-.Fn intf_loop
-iterates over all network interfaces, invoking the specified
-.Fa callback
+entry.
+.PP
+intf_loop
+iterates over all network interfaces, invoking the specified
+callback
with each interface configuration
-.Fa entry
+entry
and the context
-.Fa arg
+arg
passed to
-.Fn intf_loop .
-.Fn intf_close
+intf_loop.
+.PP
+intf_close
closes the specified handle.
-.Ss Internet Protocol
-.Fn ip_open
+.SS "Internet Protocol"
+ip_open
is used to obtain a handle to transmit raw IP packets, routed by the
kernel.
-.Fn ip_add_option
+.PP
+ip_add_option
adds the header option for the protocol
-.Fa proto
+proto
specified by
-.Fa optbuf
+optbuf
of length
-.Fa optlen
+optlen
and appends it to the appropriate header of the IP packet contained in
-.Fa buf
+buf
of size
-.Fa len ,
+len,
shifting any existing payload and adding NOPs to pad the option to
a word boundary if necessary.
-.Fn ip_checksum
+.PP
+ip_checksum
sets the IP checksum and any appropriate transport protocol checksum
for the IP packet pointed to by
-.Fa buf
+buf
of length
-.Fa len .
-.Fn ip_send
+len.
+.PP
+ip_send
transmits
-.Fa len
+len
bytes of the IP packet pointed to by
-.Fa buf .
-.Fn ip_close
+buf.
+.PP
+ip_close
closes the specified handle.
-.Ss Internet Protocol Version 6
-.Fn ip6_checksum
+.SS "Internet Protocol Version 6"
+ip6_checksum
sets the appropriate transport protocol checksum for the IPv6 packet
pointed to by
-.Fa buf
+buf
of length
-.Fa len .
-.Ss Random number generation
-.Fn rand_open
+len.
+.SS "Random number generation"
+rand_open
is used to obtain a handle for fast, cryptographically strong
pseudo-random number generation. The starting seed is derived from the
system random data source device (if one exists), or from the current
time and random stack contents.
-.Fn rand_set
-re-initializes the PRNG to start from a known
-.Fa seed
+.PP
+rand_set
+re-initializes the PRNG to start from a known
+seed
value, useful in generating repeatable sequences.
-.Fn rand_get
-writes
-.Fa len
+.PP
+rand_get
+writes
+len
random bytes into
-.Fa buf .
-.Fn rand_add
+buf.
+.PP
+rand_add
adds
-.Fa len
+len
bytes of entropy data from
-.Fa buf
+buf
into the random mix.
-.Fn rand_uint8 ,
-.Fn rand_uint16 ,
+.PP
+rand_uint8,
+rand_uint16,
and
-.Fn rand_uint32
+rand_uint32
return 8, 16, and 32-bit unsigned random values, respectively.
-.Fn rand_shuffle
+.PP
+rand_shuffle
randomly shuffles an array of
-.Fa nmemb
-elements of
-.Fa size
+nmemb
+elements of
+size
bytes, starting at
-.Fa base .
-.Fn rand_close
+base.
+.PP
+rand_close
closes the specified handle.
-.Ss Routing
+.SS "Routing"
Routing table entries are described by the following structure:
-.Bd -literal
+.nf
struct route_entry {
struct addr route_dst; /* destination address */
struct addr route_gw; /* gateway address */
};
-.Fn route_open
+.fi
+.PP
+route_open
is used to obtain a handle to access the kernel
-.Xr route 4
+route(8)
table.
-.Fn route_add
+.PP
+route_add
adds a new routing table
-.Fa entry .
-.Fn route_delete
+entry.
+.PP
+route_delete
deletes the routing table
-.Fa entry
+entry
for the destination prefix specified by
-.Fa route_dst .
-.Fn route_get
+route_dst.
+.PP
+route_get
retrieves the routing table
-.Fa entry
+entry
for the destination prefix specified by
-.Fa route_dst .
-.Fn route_loop
+route_dst.
+.PP
+route_loop
iterates over the kernel
-.Xr route 4
+route(8)
table, invoking the specified
-.Fa callback
+callback
with each
-.Fa entry
+entry
and the context
-.Fa arg
+arg
passed to
-.Fn route_loop .
-.Fn route_close
+route_loop.
+.PP
+route_close
closes the specified handle.
-.Ss Tunnel interface
-.Fn tun_open
+.SS "Tunnel interface"
+tun_open
is used to obtain a handle to a network tunnel interface, to which
-IP packets destined for
-.Fa dst
+IP packets destined for
+dst
are delivered (with source addresses rewritten to
-.Fa src
+src
), where they may be read by a userland process and processed as
desired. IP packets written back to the handle are injected into the
kernel networking subsystem.
-.Fn tun_fileno
+.PP
+tun_fileno
returns a file descriptor associated with the tunnel handle, suitable
-for
-.Xr select 2 .
-.Fn tun_name
+for
+select(2).
+.PP
+tun_name
returns a pointer to the tunnel interface name.
-.Fn tun_send
+.PP
+tun_send
submits a packet to the kernel networking subsystem for delivery.
-.Fn tun_recv
+.PP
+tun_recv
reads the next packet delivered to the tunnel interface.
-.Fn tun_close
+.PP
+tun_close
closes the specified handle.
-.Sh RETURN VALUES
-.Fn addr_ntop
+.SH "RETURN VALUES"
+addr_ntop
returns a pointer to the
-.Fa dst
+dst
argument, or NULL on failure.
-.Fn addr_ntoa
+.PP
+addr_ntoa
returns a pointer to a static memory area containing the printable
address, or NULL on failure.
-.Fn arp_open ,
-.Fn eth_open ,
-.Fn fw_open ,
-.Fn intf_open ,
-.Fn ip_open ,
-.Fn rand_open ,
+.PP
+arp_open,
+eth_open,
+fw_open,
+intf_open,
+ip_open,
+rand_open,
and
-.Fn route_open
+route_open
return a valid handle on success, or NULL on failure.
-.Fn arp_close ,
-.Fn eth_close ,
-.Fn fw_close ,
-.Fn intf_close ,
-.Fn ip_close ,
-.Fn rand_close ,
+.PP
+arp_close,
+eth_close,
+fw_close,
+intf_close,
+ip_close,
+rand_close,
and
-.Fn route_close
+route_close
always return NULL.
-.Fn eth_send
+.PP
+eth_send
and
-.Fn ip_send
+ip_send
return the length of the datagram successfully sent, or -1 on failure.
-.Fn arp_loop ,
-.Fn fw_loop ,
-.Fn intf_loop ,
+.PP
+arp_loop,
+fw_loop,
+intf_loop,
and
-.Fn route_loop
+route_loop
return the status of their
-.Fa callback
-routines. Any non-zero return from a
-.Fa callback
+callback
+routines. Any non-zero return from a
+callback
will cause the loop to exit immediately.
-.Fn ip_add_option
+.PP
+ip_add_option
returns the length of the inserted option (which may have been padded
with NOPs for memory alignment) or -1 on failure.
-.Fn rand_uint8 ,
-.Fn rand_uint16 ,
+.PP
+rand_uint8,
+rand_uint16,
and
-.Fn rand_uint32
+rand_uint32
return 8, 16, and 32-bit unsigned random values, respectively.
-All other
+.PP
+All other
+\fBdnet\fP
routines return 0 on success, or -1 on failure.
-.Sh SEE ALSO
-.Xr pcap 3
-.Sh AUTHORS
+.SH "SEE ALSO"
+pcap(3)
+.SH "AUTHORS"
Dug Song
-.Aq dugsong@monkey.org
+<dugsong@monkey.org>