|
|
| |
NETWIB_NET(3) |
FreeBSD Library Functions Manual |
NETWIB_NET(3) |
If you have a browser, read netwib-5.38.0-doc_html.tgz which is easier to read
than this manpage.
This manpage contains a concatenation of includes for section NET.
#ifndef NETWIB_NET_TYPES_INCLUDED
#define NETWIB_NET_TYPES_INCLUDED 1
/*-------------------------------------------------------------*/
/* to store an Ethernet address */
#define NETWIB_ETH_LEN 6
typedef struct {
netwib_byte b[NETWIB_ETH_LEN];
} netwib_eth;
typedef const netwib_eth netwib_consteth;
/*-------------------------------------------------------------*/
/* to store an IPv4 address */
#define NETWIB_IP4_LEN 4
typedef netwib_uint32 netwib_ip4;
/* to store an IPv6 address */
#define NETWIB_IP6_LEN 16
typedef struct {
netwib_byte b[NETWIB_IP6_LEN];
} netwib_ip6;
typedef const netwib_ip6 netwib_constip6;
/* to store an IP address */
typedef enum {
NETWIB_IPTYPE_UNKNOWN = 0,
NETWIB_IPTYPE_IP4,
NETWIB_IPTYPE_IP6
} netwib_iptype;
typedef struct {
netwib_iptype iptype;
union {
netwib_ip4 ip4;
netwib_ip6 ip6;
} ipvalue;
} netwib_ip;
typedef const netwib_ip netwib_constip;
/*-------------------------------------------------------------*/
/* to store a port */
typedef netwib_uint32 netwib_port;
#endif
/*-------------------------------------------------------------*/
/* Name : netwib_device_init_kbd
Description :
Initialize a device by the keyboard
Input parameter(s) :
message : message to print before
defaultdevice : default device to use if user enters nothing
Input/output parameter(s) :
Output parameter(s) :
*pdevice : device set with user's string
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_device_init_kbd(netwib_constbuf *pmessage,
netwib_constbuf *pdefaultdevice,
netwib_buf *pdevice);
#define NETWIB_DEVICE_INIT_KBD_NODEF NULL
/*-------------------------------------------------------------*/
/* Hardware types */
typedef enum {
NETWIB_DEVICE_HWTYPE_UNKNOWN = 1,
NETWIB_DEVICE_HWTYPE_ETHER,
NETWIB_DEVICE_HWTYPE_LOOPBACK,
NETWIB_DEVICE_HWTYPE_PPP,
NETWIB_DEVICE_HWTYPE_PLIP,
NETWIB_DEVICE_HWTYPE_SLIP
} netwib_device_hwtype;
/*-------------------------------------------------------------*/
/* Name : netwib_buf_append_device_hwtype
Description :
Obtains the buf string corresponding to a hwtype.
Input parameter(s) :
type : type
Input/output parameter(s) :
Output parameter(s) :
*pbuf : netwib_buf set with the buf string
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_buf_append_device_hwtype(netwib_device_hwtype type,
netwib_buf *pbuf);
/*-------------------------------------------------------------*/
/* Name : netwib_device_hwtype_init_kbd
Description :
Initialize a netwib_device_hwtype with data entered
through keyboard.
Input parameter(s) :
*pmessage : message to print before
defaulthwtype : default hwtype to use if user enters
nothing (if NETWIB_DEVICE_HWTYPE_UNKNOWN,
means no default)
Input/output parameter(s) :
Output parameter(s) :
*phwtype : netwib_hwtype initialized
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_device_hwtype_init_kbd(netwib_constbuf *pmessage,
netwib_device_hwtype defaulthwtype,
netwib_device_hwtype *phwtype);
#define NETWIB_DEVICE_HWTYPE_INIT_KBD_NODEF NETWIB_DEVICE_HWTYPE_UNKNOWN
/*-------------------------------------------------------------*/
/***************************************************************
* Sniffed data is represented as specified by the DLT *
* associated to packets. *
* Spoofed data (at link level) also has to be represented as *
* DLT expects. *
***************************************************************/
/* Data-link level type codes (names from net/bpf.h). */
typedef enum {
NETWIB_DEVICE_DLTTYPE_UNKNOWN = 1, /* not listed below */
NETWIB_DEVICE_DLTTYPE_NULL, /* no link-layer encapsulation */
NETWIB_DEVICE_DLTTYPE_EN10MB, /* Ethernet (10Mb) */
NETWIB_DEVICE_DLTTYPE_ETHER = NETWIB_DEVICE_DLTTYPE_EN10MB,
NETWIB_DEVICE_DLTTYPE_EN3MB, /* Experimental Ethernet (3Mb) */
NETWIB_DEVICE_DLTTYPE_AX25, /* Amateur Radio AX.25 */
NETWIB_DEVICE_DLTTYPE_PRONET, /* Proteon ProNET Token Ring */
NETWIB_DEVICE_DLTTYPE_CHAOS, /* Chaos */
NETWIB_DEVICE_DLTTYPE_IEEE802, /* IEEE 802 Networks */
NETWIB_DEVICE_DLTTYPE_ARCNET, /* ARCNET */
NETWIB_DEVICE_DLTTYPE_SLIP, /* Serial Line IP */
NETWIB_DEVICE_DLTTYPE_PPP, /* Point-to-point Protocol */
NETWIB_DEVICE_DLTTYPE_FDDI, /* FDDI */
NETWIB_DEVICE_DLTTYPE_ATM_RFC1483, /* LLC/SNAP encapsulated atm */
NETWIB_DEVICE_DLTTYPE_RAW, /* raw IPv4 or IPv6 */
NETWIB_DEVICE_DLTTYPE_RAW4, /* raw IPv4 */
NETWIB_DEVICE_DLTTYPE_RAW6, /* raw IPv6 */
NETWIB_DEVICE_DLTTYPE_SLIP_BSDOS, /* BSD/OS Serial Line IP */
NETWIB_DEVICE_DLTTYPE_PPP_BSDOS, /* BSD/OS Point-to-point Protocol */
NETWIB_DEVICE_DLTTYPE_ATM_CLIP, /* Linux Classical-IP over ATM */
NETWIB_DEVICE_DLTTYPE_PPP_SERIAL, /* PPP over serial with HDLC enc. */
NETWIB_DEVICE_DLTTYPE_PPP_ETHER, /* PPP over Ethernet */
NETWIB_DEVICE_DLTTYPE_C_HDLC, /* Cisco HDLC */
NETWIB_DEVICE_DLTTYPE_IEEE802_11, /* IEEE 802.11 wireless */
NETWIB_DEVICE_DLTTYPE_LOOP,
NETWIB_DEVICE_DLTTYPE_LINUX_SLL,
NETWIB_DEVICE_DLTTYPE_LTALK,
NETWIB_DEVICE_DLTTYPE_ECONET,
NETWIB_DEVICE_DLTTYPE_PRISM_HEADER,
NETWIB_DEVICE_DLTTYPE_AIRONET_HEADER,
NETWIB_DEVICE_DLTTYPE_USER_BEGIN = NETWIB_ENUM_USER_BEGIN
} netwib_device_dlttype;
/*-------------------------------------------------------------*/
/* Name : netwib_buf_append_device_dlttype
Description :
Obtains the buf string corresponding to a hwtype.
Input parameter(s) :
type : type
Input/output parameter(s) :
Output parameter(s) :
*pbuf : netwib_buf set with the buf string
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_buf_append_device_dlttype(netwib_device_dlttype type,
netwib_buf *pbuf);
/*-------------------------------------------------------------*/
/* Name : netwib_device_dlttype_init_kbd
Description :
Initialize a netwib_device_dlttype with data entered
through keyboard.
Input parameter(s) :
*pmessage : message to print before
defaultdlttype : default dlttype to use if user enters
nothing (if NETWIB_DEVICE_DLTTYPE_UNKNOWN,
means no default)
Input/output parameter(s) :
Output parameter(s) :
*pdlttype : netwib_dlttype initialized
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_device_dlttype_init_kbd(netwib_constbuf *pmessage,
netwib_device_dlttype defaultdlttype,
netwib_device_dlttype *pdlttype);
#define NETWIB_DEVICE_DLTTYPE_INIT_KBD_NODEF NETWIB_DEVICE_DLTTYPE_UNKNOWN
/*-------------------------------------------------------------*/
/***************************************************************
* A netwib_ip represents an IP address. *
***************************************************************/
/*-------------------------------------------------------------*/
/* Name : netwib_ip_init_ip4_fields
Description :
Initialize an netwib_ip address.
Input parameter(s) :
a,b,c,d : bytes of the IP address
Input/output parameter(s) :
Output parameter(s) :
*pip : netwib_ip set with a.b.c.d
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_ip_init_ip4_fields(netwib_byte a,
netwib_byte b,
netwib_byte c,
netwib_byte d,
netwib_ip *pip);
/*-------------------------------------------------------------*/
/* Name : netwib_ip_init_ip4
Description :
Initialize an netwib_ip address from an netwib_ip4.
Input parameter(s) :
ip4 : netwib_ip4 address
Input/output parameter(s) :
Output parameter(s) :
*pip : netwib_ip set
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_ip_init_ip4(netwib_ip4 ip4,
netwib_ip *pip);
/*-------------------------------------------------------------*/
/* Name : netwib_ip4_init_ip
Description :
Initialize an netwib_ip4 address from an netwib_ip.
Input parameter(s) :
ip : netwib_ip address
Input/output parameter(s) :
Output parameter(s) :
*pip4 : netwib_ip4 set
Normal return values :
NETWIB_ERR_OK : ok
NETWIB_ERR_NOTCONVERTED : the address could not be represented
*/
netwib_err netwib_ip4_init_ip(netwib_constip *pip,
netwib_ip4 *pip4);
/*-------------------------------------------------------------*/
/* Name : netwib_ip_init_ip6_fields
Description :
Initialize an netwib_ip address.
Input parameter(s) :
a,b,c,d : "aaaa:aaaa:bbbb:bbbb:cccc:cccc:dddd:dddd"
Input/output parameter(s) :
Output parameter(s) :
*pip : netwib_ip set with "aaaa:aaaa:bbbb:b..."
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_ip_init_ip6_fields(netwib_uint32 a,
netwib_uint32 b,
netwib_uint32 c,
netwib_uint32 d,
netwib_ip *pip);
/*-------------------------------------------------------------*/
/* Name : netwib_ip_init_ip6
Description :
Initialize an netwib_ip address from an netwib_ip6.
Input parameter(s) :
ip6 : netwib_ip6 address
Input/output parameter(s) :
Output parameter(s) :
*pip : netwib_ip set
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_ip_init_ip6(netwib_constip6 *pip6,
netwib_ip *pip);
/*-------------------------------------------------------------*/
/* Name : netwib_ip6_init_ip
Description :
Initialize an netwib_ip6 address from an netwib_ip.
Input parameter(s) :
ip : netwib_ip address
Input/output parameter(s) :
Output parameter(s) :
*pip6 : netwib_ip6 set
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_ip6_init_ip(netwib_constip *pip,
netwib_ip6 *pip6);
/*-------------------------------------------------------------*/
typedef enum {
NETWIB_IP_DECODETYPE_IP4 = 1, /* "1.2.3.4" only */
NETWIB_IP_DECODETYPE_IP6, /* "aaaa:bbbb:..." only */
NETWIB_IP_DECODETYPE_IP, /* try IP4 then IP6 */
NETWIB_IP_DECODETYPE_HN4, /* server.example.com->IPv4 only */
NETWIB_IP_DECODETYPE_HN6, /* server.example.com->IPv4 only */
NETWIB_IP_DECODETYPE_HN, /* try HN4 then HN6 */
NETWIB_IP_DECODETYPE_IP4HN4, /* if IP4 does not work, use HN4 */
NETWIB_IP_DECODETYPE_IP6HN6, /* if IP6 does not work, use HN6 */
NETWIB_IP_DECODETYPE_IPHN, /* try IP, then HN */
NETWIB_IP_DECODETYPE_BEST = NETWIB_IP_DECODETYPE_IPHN /* best */
} netwib_ip_decodetype;
/*-------------------------------------------------------------*/
/* Name : netwib_ip_init_buf
Description :
Convert a string "1.2.3.4", "aaaa:bbbb:..." or a
hostname to a netwib_ip. To convert a hostname resolving
to several IP addresses, function netwib_ips_add_buf
has to be used instead.
Input parameter(s) :
*pbuf : string to convert
Input/output parameter(s) :
Output parameter(s) :
*pip : netwib_ip set
Normal return values :
NETWIB_ERR_OK : ok
NETWIB_ERR_NOTCONVERTED : the address could not be resolved
*/
netwib_err netwib_ip_init_buf(netwib_constbuf *pbuf,
netwib_ip_decodetype decodetype,
netwib_ip *pip);
#define netwib_ip_init_buf_best(pbuf,pip) netwib_ip_init_buf(pbuf,NETWIB_IP_DECODETYPE_BEST,pip)
/*-------------------------------------------------------------*/
/* Name : netwib_ip_init_eth
Description :
Convert a netwib_eth to a netwib_ip.
Input parameter(s) :
eth : netwib_eth to convert
Input/output parameter(s) :
Output parameter(s) :
*pip : netwib_ip set with eth value
Normal return values :
NETWIB_ERR_OK : ok
NETWIB_ERR_NOTCONVERTED : the address could not be resolved
Note :
This function does not currently support IPv6. It have
to be finished.
*/
netwib_err netwib_ip_init_eth(netwib_consteth *peth,
netwib_ip *pip);
/*-------------------------------------------------------------*/
/* Name : netwib_ip_init_kbd
Description :
Initialize an netwib_ip with the address entered by the
user through the keyboard
Input parameter(s) :
message : message to print before
defaulthn : default hostname or ip address to use if
user enters nothing. If NULL, there is no default
Input/output parameter(s) :
Output parameter(s) :
*pip : netwib_ip set with user's string
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_ip_init_kbd(netwib_constbuf *pmessage,
netwib_constbuf *pdefaulthn,
netwib_ip *pip);
#define NETWIB_IP_INIT_KBD_NODEF NULL
/*-------------------------------------------------------------*/
/* Name : netwib_ip_cmp
Description :
Compare two netwib_ip.
Input parameter(s) :
ip1 : netwib_ip to compare with ip2
ip2 : netwib_ip to compare with ip1
Input/output parameter(s) :
Output parameter(s) :
*pcmp :
NETWIB_CMP_LT : ip1<ip2
NETWIB_CMP_EQ : if ip1 and ip2 are equal
NETWIB_CMP_GT : ip1>ip2
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_ip_cmp(netwib_constip *pip1,
netwib_constip *pip2,
netwib_cmp *pcmp);
/*-------------------------------------------------------------*/
typedef enum {
NETWIB_IP_ENCODETYPE_IP = 1, /* "1.2.3.4" */
NETWIB_IP_ENCODETYPE_HN, /* server.example.com */
NETWIB_IP_ENCODETYPE_HNIP, /* if HN does not work, use IP */
NETWIB_IP_ENCODETYPE_HNS, /* "host1,host2,etc." */
NETWIB_IP_ENCODETYPE_BEST = NETWIB_IP_ENCODETYPE_HNIP /* best */
} netwib_ip_encodetype;
/*-------------------------------------------------------------*/
/* Name : netwib_buf_append_ip
Description :
Append a string representing a netwib_ip.
Input parameter(s) :
ip : netwib_ip to append
encodetype : encodetype to use
Input/output parameter(s) :
pbuf : buffer updated
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
NETWIB_ERR_NOTCONVERTED : the address could not be resolved
*/
netwib_err netwib_buf_append_ip(netwib_constip *pip,
netwib_ip_encodetype encodetype,
netwib_buf *pbuf);
/*-------------------------------------------------------------*/
/* Name : netwib_buf_append_iptype
Description :
Obtains the buf string corresponding to a type.
Input parameter(s) :
type : type
Input/output parameter(s) :
Output parameter(s) :
*pbuf : netwib_buf set with the buf string
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_buf_append_iptype(netwib_iptype type,
netwib_buf *pbuf);
/*-------------------------------------------------------------*/
/* Name : netwib_iptype_init_kbd
Description :
Initialize a netwib_iptype with data entered
through keyboard.
Input parameter(s) :
*pmessage : message to print before
defaulttype : default type to use if user enters
nothing (if NETWIB_IPTYPE_UNKNOWN means
no default)
Input/output parameter(s) :
Output parameter(s) :
*phwtype : netwib_hwtype initialized
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_iptype_init_kbd(netwib_constbuf *pmessage,
netwib_iptype defaulttype,
netwib_iptype *ptype);
#define NETWIB_IPTYPE_INIT_KBD_NODEF NETWIB_IPTYPE_UNKNOWN
/*-------------------------------------------------------------*/
/***************************************************************
* A netwib_eth represents an Ethernet address. *
* You can init it with a netwib_eth_init_xyz function or with:*
* netwib_eth eth, eth2; *
* eth.b[0] = 0x01; eth.b[1] = 0x02; eth.b[2] = 0x03; ... *
* netwib_c_memcpy(eth.b, array, NETWIB_ETH_LEN); *
* netwib_c_memset(eth.b, 0, NETWIB_ETH_LEN); *
* eth2 = eth1; *
***************************************************************/
/*-------------------------------------------------------------*/
/* Name : netwib_eth_init_fields
Description :
Initialize an netwib_eth address.
Input parameter(s) :
a,b,c,d,e,f : bytes of the Ethernet address
Input/output parameter(s) :
Output parameter(s) :
*peth : netwib_eth set with a:b:c:d:e:f
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_eth_init_fields(netwib_byte a,
netwib_byte b,
netwib_byte c,
netwib_byte d,
netwib_byte e,
netwib_byte f,
netwib_eth *peth);
/*-------------------------------------------------------------*/
/* Name : netwib_eth_init_buf
Description :
Convert the string "aa:bb:cc:dd:ee:ff" to a netwib_eth.
Input parameter(s) :
*pbuf : string
Input/output parameter(s) :
Output parameter(s) :
*peth : netwib_eth set
Normal return values :
NETWIB_ERR_OK : ok
NETWIB_ERR_NOTCONVERTED : format is not "aa:bb:cc:dd:ee:ff"
*/
netwib_err netwib_eth_init_buf(netwib_constbuf *pbuf,
netwib_eth *peth);
/*-------------------------------------------------------------*/
/* Name : netwib_eth_init_ip
Description :
Convert a netwib_ip address to a netwib_eth.
Input parameter(s) :
ip : IP address
Input/output parameter(s) :
Output parameter(s) :
*peth : netwib_eth set with ip
Normal return values :
NETWIB_ERR_OK : ok
NETWIB_ERR_OKUNRESOLVED : the address could not be resolved
*/
netwib_err netwib_eth_init_ip(netwib_constip *pip,
netwib_eth *peth);
/*-------------------------------------------------------------*/
/* Name : netwib_eth_init_kbd
Description :
Initialize an netwib_eth with the address entered by the
user through the keyboard
Input parameter(s) :
message : message to print before
*pdefaulteth : default eth to use if user enters nothing
if NULL, there is no default
Input/output parameter(s) :
Output parameter(s) :
*peth : netwib_eth set with user's string
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_eth_init_kbd(netwib_constbuf *pmessage,
netwib_consteth *pdefaulteth,
netwib_eth *peth);
#define NETWIB_ETH_INIT_KBD_NODEF NULL
/*-------------------------------------------------------------*/
/* Name : netwib_eth_cmp
Description :
Compare two netwib_eth.
Input parameter(s) :
eth1 : netwib_eth to compare with eth2
eth2 : netwib_eth to compare with eth1
Input/output parameter(s) :
Output parameter(s) :
*pcmp :
NETWIB_CMP_LT : eth1<eth2
NETWIB_CMP_EQ : if eth1 and eth2 are equal
NETWIB_CMP_GT : eth1>eth2
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_eth_cmp(netwib_consteth *peth1,
netwib_consteth *peth2,
netwib_cmp *pcmp);
/*-------------------------------------------------------------*/
/* Name : netwib_buf_append_eth
Description :
Append a string representing a netwib_eth.
Input parameter(s) :
eth : netwib_eth to append
Input/output parameter(s) :
pbuf : buffer updated
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_buf_append_eth(netwib_consteth *peth,
netwib_buf *pbuf);
/*-------------------------------------------------------------*/
/* Name : netwib_port_init_kbd
Description :
Initialize a netwib_port with data entered through keyboard.
Input parameter(s) :
*pmessage : message to print before
min : minvalue which can be entered (if 0 no min)
max : maxvalue which can be entered (if 0xFFFFFFFFu no max)
defaultport : default port to use if user enters nothing
if 0xFFFFFFFFu, there is no default
Input/output parameter(s) :
Output parameter(s) :
*pport : netwib_port initialized
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_port_init_kbd(netwib_constbuf *pmessage,
netwib_port min,
netwib_port max,
netwib_port defaultport,
netwib_port *pport);
#define NETWIB_PORT_INIT_KBD_NOMIN 0
#define NETWIB_PORT_INIT_KBD_NOMAX 0xFFFFFFFFu
#define NETWIB_PORT_INIT_KBD_NODEF 0xFFFFFFFFu
/*-------------------------------------------------------------*/
/* Name : netwib_port_init_buf
Description :
Convert a string "123" to a netwib_port.
Input parameter(s) :
*pbuf : string to convert
Input/output parameter(s) :
Output parameter(s) :
*pport : netwib_port set
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_port_init_buf(netwib_constbuf *pbuf,
netwib_port *pport);
/*-------------------------------------------------------------*/
/* Name : netwib_buf_append_port
Description :
Append a string representing a netwib_port.
Input parameter(s) :
port : netwib_port to append
Input/output parameter(s) :
pbuf : buffer updated
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_buf_append_port(netwib_port port,
netwib_buf *pbuf);
/*-------------------------------------------------------------*/
/***************************************************************
* An IP range is of the form : *
* ip4inf ip4sup *
* 1.2.3.4 : 1.2.3.4 1.2.3.4 *
* 1.2.3.4-5.6.7.8 : 1.2.3.4 5.6.7.8 *
* 1.2.3.0/255.255.255.0 : 1.2.3.0 1.2.3.255 *
* 1.2.3.0/24 : 1.2.3.0 1.2.3.255 *
* 1.2.3/255.255.255.0 : 1.2.3.0 1.2.3.255 *
* 1.2.3/24 : 1.2.3.0 1.2.3.255 *
* 1.2.3.0%255.255.255.O : 1.2.3.1 1.2.3.254 *
* 1.2.3.0%24 : 1.2.3.1 1.2.3.254 *
* 1.2.3%255.255.255.O : 1.2.3.1 1.2.3.254 *
* 1.2.3%24 : 1.2.3.1 1.2.3.254 *
* fec0:0:0:1::1 : fec0:0:0:1::1 fec0:0:0:1::1 *
* Notes : *
* - '%' has the same meaning as '/', except that the *
* broadcast addresses are excluded from range. *
* - It is possible to use a hostname range as input. In this *
* case the separator is '=' (because '-' is a valid *
* hostname separator). *
* *
* An netwib_ips is of the form : *
* ip,ip,iprange,iprange *
* all,!ip,!iprange *
* *
* Complete examples : *
* 1.2.3.4 *
* 1.2.3.4-1.2.3.5 *
* 1.2.3.4,5.6.7.8 *
* 1.2.3.4,1.2.3.56-1.2.3.58 *
* all,!1.2.3.4,!1.2.4.4-1.2.4.6 *
* hostname *
* host1=host2 *
* host1,host2 *
***************************************************************/
/*-------------------------------------------------------------*/
/***************************************************************
* Those functions ignores following error cases : *
* - if we try to add a value already in the list *
* - if we try to remove a value not in the list *
***************************************************************/
/*-------------------------------------------------------------*/
typedef struct netwib_ips netwib_ips;
typedef const netwib_ips netwib_constips;
/*-------------------------------------------------------------*/
/* Name : netwib_ips_init
Description :
Initialize a netwib_ips used to store IP list.
Input parameter(s) :
inittype : if future added items will be sorted and/or unique
Input/output parameter(s) :
Output parameter(s) :
**ppips : netwib_ips allocated and initialized
Normal return values :
NETWIB_ERR_OK : ok
*/
typedef enum {
NETWIB_IPS_INITTYPE_SORTUNIQ = 1, /* sorted and unique */
NETWIB_IPS_INITTYPE_NOTSORTUNIQ = 2, /* not sorted and unique */
NETWIB_IPS_INITTYPE_NOTSORTNOTUNIQ = 3 /* not sorted and not
unique (duplicates
are not removed) */
} netwib_ips_inittype;
netwib_err netwib_ips_init(netwib_ips_inittype inittype,
netwib_ips **ppips);
#define netwib_ips_initdefault(ppips) netwib_ips_init(NETWIB_IPS_INITTYPE_SORTUNIQ,ppips)
/*-------------------------------------------------------------*/
/* Name : netwib_ips_close
Description :
Close a netwib_ips.
Input parameter(s) :
Input/output parameter(s) :
**ppips : netwib_ips closed
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_ips_close(netwib_ips **ppips);
/*-------------------------------------------------------------*/
/* Name : netwib_ips_add_ip
Description :
Add an address to the netwib_ips.
Input parameter(s) :
ip : address to add
Input/output parameter(s) :
*pips : netwib_ips where to work
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_ips_add_ip(netwib_ips *pips,
netwib_constip *pip);
/*-------------------------------------------------------------*/
/* Name : netwib_ips_add_iprange
Description :
Add a range of addresses to the netwib_ips.
Input parameter(s) :
infip : inferior ip
supip : superior ip
Input/output parameter(s) :
*pips : netwib_ips where to work
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_ips_add_iprange(netwib_ips *pips,
netwib_constip *pinfip,
netwib_constip *psupip);
/*-------------------------------------------------------------*/
/* Name : netwib_ips_add_ips
Description :
Add a list of addresses to the netwib_ips.
Input parameter(s) :
*pipstoadd : netwib_ips to add
Input/output parameter(s) :
*pips : netwib_ips where to work
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_ips_add_ips(netwib_ips *pips,
netwib_constips *pipstoadd);
/*-------------------------------------------------------------*/
/* Name : netwib_ips_add_buf
Description :
Update a netwib_ips with a string like "1.2.3.4-1.2.3.5".
Input parameter(s) :
pbuf : buffer containing string
Input/output parameter(s) :
*pips : netwib_ips updated
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
Note :
If an error occurs during insertion, result will only
contain partial data. It's developer's job to use a
temporary netwib_ips to deal with such errors.
*/
netwib_err netwib_ips_add_buf(netwib_ips *pips,
netwib_constbuf *pbuf);
/*-------------------------------------------------------------*/
/* Name : netwib_ips_add_kbd
Description :
Update a netwib_ips with data entered through keyboard.
Input parameter(s) :
*pmessage : message to print before
*pdefaultlist : default list to use if user enters nothing
if NULL, there is no default
Input/output parameter(s) :
*pips : netwib_ips updated
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_ips_add_kbd(netwib_ips *pips,
netwib_constbuf *pmessage,
netwib_constbuf *pdefaultlist);
/*-------------------------------------------------------------*/
/* Name : netwib_ips_del_ip
Description :
Del an address to the netwib_ips.
Input parameter(s) :
ip : address to delete
Input/output parameter(s) :
*pips : netwib_ips where to work
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_ips_del_ip(netwib_ips *pips,
netwib_constip *pip);
/*-------------------------------------------------------------*/
/* Name : netwib_ips_del_iprange
Description :
Del a range of addresses to the netwib_ips.
Input parameter(s) :
infip : inferior ip
supip : superior ip
Input/output parameter(s) :
*pips : netwib_ips where to work
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_ips_del_iprange(netwib_ips *pips,
netwib_constip *pinfip,
netwib_constip *psupip);
/*-------------------------------------------------------------*/
/* Name : netwib_ips_del_ips
Description :
Remove a list of addresses to the netwib_ips.
Input parameter(s) :
*pipstodel : netwib_ips to remove
Input/output parameter(s) :
*pips : netwib_ips where to work
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_ips_del_ips(netwib_ips *pips,
netwib_constips *pipstodel);
/*-------------------------------------------------------------*/
/* Name : netwib_ips_contains_xyz
Description :
Check if a netwib_ip is in the list.
Input parameter(s) :
ip : netwib_ip to find
Input/output parameter(s) :
*pips : netwib_ips containing the list of addresses
Output parameter(s) :
*pyes : true if netwib_ip is found
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_ips_contains_ip(netwib_constips *pips,
netwib_constip *pip,
netwib_bool *pyes);
netwib_err netwib_ips_contains_iprange(netwib_constips *pips,
netwib_constip *pinfip,
netwib_constip *psupip,
netwib_bool *pyes);
/*-------------------------------------------------------------*/
typedef enum {
NETWIB_IPS_ENCODETYPE_HNRANGE = 1,/* "host1=host2,etc." */
NETWIB_IPS_ENCODETYPE_IPRANGE, /* "1.2.3.4-1.2.3.5,etc." */
NETWIB_IPS_ENCODETYPE_IPNUMBER, /* "1.1.1.0/24,etc." */
NETWIB_IPS_ENCODETYPE_IPMASK, /* "1.1.1.0/255.255.255.255" */
NETWIB_IPS_ENCODETYPE_HNBEST = NETWIB_IPS_ENCODETYPE_HNRANGE,
NETWIB_IPS_ENCODETYPE_IPBEST = NETWIB_IPS_ENCODETYPE_IPRANGE,
NETWIB_IPS_ENCODETYPE_BEST = NETWIB_IPS_ENCODETYPE_IPBEST
} netwib_ips_encodetype;
/*-------------------------------------------------------------*/
/* Name : netwib_buf_append_ips
Description :
Append a string representing a netwib_ips.
Input parameter(s) :
*pips : netwib_ips to append
Input/output parameter(s) :
pbuf : buffer updated
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_buf_append_ips(netwib_constips *pips,
netwib_ips_encodetype encodetype,
netwib_buf *pbuf);
/*-------------------------------------------------------------*/
typedef struct netwib_ips_index netwib_ips_index;
/*-------------------------------------------------------------*/
/* Name : netwib_ips_index_init
Description :
Initialize a netwib_ips_index used to loop through
a netwib_ips.
Input parameter(s) :
Input/output parameter(s) :
Output parameter(s) :
**ppipsindex : netwib_ips_index allocated and initialized
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_ips_index_init(netwib_constips *pips,
netwib_ips_index **ppipsindex);
/*-------------------------------------------------------------*/
/* Name : netwib_ips_index_close
Description :
Close a netwib_ipsindex.
Input parameter(s) :
Input/output parameter(s) :
**ppipsindex : netwib_ips_index closed
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_ips_index_close(netwib_ips_index **ppipsindex);
/*-------------------------------------------------------------*/
/* Types to control a netwib_ips_index */
typedef enum {
NETWIB_IPS_INDEX_CTLTYPE_REWIND = 1, /* position at beginning */
NETWIB_IPS_INDEX_CTLTYPE_INDEX /* reset with index pos */
} netwib_ips_index_ctltype;
/* Those functions permit to set/get parameters (pointer and
integer) about a netwib_ips_index. It should not be used directly,
but by the defines.
*/
netwib_err netwib_ips_index_ctl_set(netwib_ips_index *pipsindex,
netwib_ips_index_ctltype type,
netwib_ptr p,
netwib_uint32 ui);
netwib_err netwib_ips_index_ctl_get(netwib_ips_index *pipsindex,
netwib_ips_index_ctltype type,
netwib_ptr p,
netwib_uint32 *pui);
/*-------------------------------------------------------------*/
/* netwib_err f(netwib_ips_index *pipsindex); */
#define netwib_ips_index_ctl_set_rewind(pipsindex) netwib_ips_index_ctl_set(pipsindex,NETWIB_IPS_INDEX_CTLTYPE_REWIND,NULL,0)
/* netwib_err f(netwib_ips_index *pipsindex,netwib_ips_index *pipsindexref);*/
#define netwib_ips_index_ctl_set_index(pipsindex,pipsindexref) netwib_ips_index_ctl_set(pipsindex,NETWIB_IPS_INDEX_CTLTYPE_INDEX,pipsindexref,0)
/*-------------------------------------------------------------*/
/* Name : netwib_ips_index_next_ip
Description :
Get the next netwib_ip in the list.
Input parameter(s) :
Input/output parameter(s) :
*pipsindex : netwib_ips_index
Output parameter(s) :
*pip : next netwib_ip
Normal return values :
NETWIB_ERR_OK : ok
NETWIB_ERR_DATAEND : end of the list reached
Note :
If one thread changes the netwib_ips between two calls,
the next result might be incorrect. Developer have to
lock the entire loop (going through each item), or to
copy the netwib_ips and to loop on the copy.
*/
netwib_err netwib_ips_index_next_ip(netwib_ips_index *pipsindex,
netwib_ip *pip);
netwib_err netwib_ips_index_next_iprange(netwib_ips_index *pipsindex,
netwib_ip *pinfip,
netwib_ip *psupip);
/*-------------------------------------------------------------*/
/* Name : netwib_ips_index_this_ip
Description :
Re-give the last netwib_ip in the list.
Input parameter(s) :
Input/output parameter(s) :
*pipsindex : netwib_ips_index
Output parameter(s) :
*pip : next netwib_ip
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_ips_index_this_ip(netwib_ips_index *pipsindex,
netwib_ip *pip);
netwib_err netwib_ips_index_this_iprange(netwib_ips_index *pipsindex,
netwib_ip *pinfip,
netwib_ip *psupip);
/*-------------------------------------------------------------*/
/* Name : netwib_ips_index_this_del
Description :
Delete the last given value by a netwib_ips_index_next
function.
Input parameter(s) :
Input/output parameter(s) :
*pipsindex : netwib_ips_index
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_ips_index_this_del(netwib_ips_index *pipsindex);
/*-------------------------------------------------------------*/
/***************************************************************
* An Ethernet range is of the form : *
* ethinf ethsup *
* a:b:c:d:e:f : a:b:c:d:e:f a:b:c:d:e:f *
* a:b:c:d:e:f-a:b:c:d:f:f : a:b:c:d:e:f a:b:c:d:f:f *
* a:b:c:d:e:0/40 : a:b:c:d:e:0 a:b:c:d:e:f *
* a:b:c:d:e:0%40 : a:b:c:d:e:1 a:b:c:d:e:e *
* a:b:c:d:e:0/ff:ff:ff:ff:ff:0 : a:b:c:d:e:0 a:b:c:d:e:f *
* Notes : *
* - '%' has the same meaning as '/', except that the *
* broadcast addresses are excluded from range. *
* *
* A netwib_eths is of the form : *
* eth,eth,ethrange,ethrange *
* all,!eth,!ethrange *
* *
* Complete examples : *
* a:b:c:d:e:f *
* a:b:c:d:e:f-a:b:c:d:f:f *
* a:b:c:d:e:f,a:b:c:d:f:f *
* 1:2:3:4:5:6,a:b:c:d:e:f-a:b:c:d:f:f *
* all,!1:2:3:4:5:6,!a:b:c:d:e:f-a:b:c:d:f:f *
***************************************************************/
/*-------------------------------------------------------------*/
/***************************************************************
* Those functions ignores following error cases : *
* - if we try to add a value already in the list *
* - if we try to remove a value not in the list *
***************************************************************/
/*-------------------------------------------------------------*/
typedef struct netwib_eths netwib_eths;
typedef const netwib_eths netwib_consteths;
/*-------------------------------------------------------------*/
/* Name : netwib_eths_init
Description :
Initialize a netwib_eths used to store several Ethernet
addresses.
Input parameter(s) :
inittype : if future added items will be sorted and/or unique
Input/output parameter(s) :
Output parameter(s) :
**ppeths : netwib_eths allocated and initialized
Normal return values :
NETWIB_ERR_OK : ok
*/
typedef enum {
NETWIB_ETHS_INITTYPE_SORTUNIQ = 1, /* sorted and unique */
NETWIB_ETHS_INITTYPE_NOTSORTUNIQ = 2, /* not sorted and unique */
NETWIB_ETHS_INITTYPE_NOTSORTNOTUNIQ = 3 /* not sorted and not
unique (duplicates
are not removed) */
} netwib_eths_inittype;
netwib_err netwib_eths_init(netwib_eths_inittype inittype,
netwib_eths **ppeths);
#define netwib_eths_initdefault(ppeths) netwib_eths_init(NETWIB_ETHS_INITTYPE_SORTUNIQ,ppeths)
/*-------------------------------------------------------------*/
/* Name : netwib_eths_close
Description :
Close a netwib_eths.
Input parameter(s) :
Input/output parameter(s) :
**ppeths : netwib_eths closed
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_eths_close(netwib_eths **ppeths);
/*-------------------------------------------------------------*/
/* Name : netwib_eths_add_eth
Description :
Add an address to the netwib_eths.
Input parameter(s) :
eth : address to add
Input/output parameter(s) :
*peths : netwib_eths where to work
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_eths_add_eth(netwib_eths *peths,
netwib_consteth *peth);
/*-------------------------------------------------------------*/
/* Name : netwib_eths_add_ethrange
Description :
Add a range of addresses to the netwib_eths.
Input parameter(s) :
infeth : inferior eth
supeth : superior eth
Input/output parameter(s) :
*peths : netwib_eths where to work
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_eths_add_ethrange(netwib_eths *peths,
netwib_consteth *pinfeth,
netwib_consteth *psupeth);
/*-------------------------------------------------------------*/
/* Name : netwib_eths_add_eths
Description :
Add a list of addresses to the netwib_eths.
Input parameter(s) :
*pethstoadd : netwib_eths to add
Input/output parameter(s) :
*peths : netwib_eths where to work
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
Note :
If an error occurs during insertion, result will only
contain partial data. It's developer's job to use a
temporary netwib_eths to deal with such errors.
*/
netwib_err netwib_eths_add_eths(netwib_eths *peths,
netwib_consteths *pethstoadd);
/*-------------------------------------------------------------*/
/* Name : netwib_eths_add_buf
Description :
Add a list represented as a string like
"aa:bb:cc:dd:ee:ff-aa:bb:cc:dd:ff:ff".
Input parameter(s) :
*pbuf : an Ethernet string
Input/output parameter(s) :
*peths : netwib_eths updated
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_eths_add_buf(netwib_eths *peths,
netwib_constbuf *pbuf);
/*-------------------------------------------------------------*/
/* Name : netwib_eths_add_kbd
Description :
Update a list with data entered through keyboard.
Input parameter(s) :
message : message to print before
defaultlist : default list to use if user enters nothing
if NULL, there is no default
Input/output parameter(s) :
Output parameter(s) :
*peths : netwib_eths updated
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_eths_add_kbd(netwib_eths *peths,
netwib_constbuf *pmessage,
netwib_constbuf *pdefaultlist);
/*-------------------------------------------------------------*/
/* Name : netwib_eths_del_eth
Description :
Del an address to the netwib_eths.
Input parameter(s) :
eth : address to delete
Input/output parameter(s) :
*peths : netwib_eths where to work
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_eths_del_eth(netwib_eths *peths,
netwib_consteth *peth);
/*-------------------------------------------------------------*/
/* Name : netwib_eths_del_ethrange
Description :
Del a range of addresses to the netwib_eths.
Input parameter(s) :
infeth : inferior eth
supeth : superior eth
Input/output parameter(s) :
*peths : netwib_eths where to work
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_eths_del_ethrange(netwib_eths *peths,
netwib_consteth *pinfeth,
netwib_consteth *psupeth);
/*-------------------------------------------------------------*/
/* Name : netwib_eths_del_eths
Description :
Remove a list of addresses to the netwib_eths.
Input parameter(s) :
*pethstoadd : netwib_eths to remove
Input/output parameter(s) :
*peths : netwib_eths where to work
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_eths_del_eths(netwib_eths *peths,
netwib_consteths *pethstodel);
/*-------------------------------------------------------------*/
/* Name : netwib_eths_contains_xyz
Description :
Check if a netwib_eth is in the list.
Input parameter(s) :
eth : netwib_eth to find
Input/output parameter(s) :
*peths : netwib_eths containing the list of addresses
Output parameter(s) :
*pyes : true if netwib_eth is found
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_eths_contains_eth(netwib_consteths *peths,
netwib_consteth *peth,
netwib_bool *pyes);
netwib_err netwib_eths_contains_ethrange(netwib_consteths *peths,
netwib_consteth *pinfeth,
netwib_consteth *psupeth,
netwib_bool *pyes);
/*-------------------------------------------------------------*/
/* Name : netwib_buf_append_eths
Description :
Append a string representing a netwib_eths.
Input parameter(s) :
*peths : netwib_eths to append
Input/output parameter(s) :
pbuf : buffer updated
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_buf_append_eths(netwib_consteths *peths,
netwib_buf *pbuf);
/*-------------------------------------------------------------*/
typedef struct netwib_eths_index netwib_eths_index;
/*-------------------------------------------------------------*/
/* Name : netwib_eths_index_init
Description :
Initialize a netwib_eths_index used to loop through
a netwib_eths.
Input parameter(s) :
Input/output parameter(s) :
Output parameter(s) :
**ppethsindex : netwib_eths_index allocated and initialized
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_eths_index_init(netwib_consteths *peths,
netwib_eths_index **ppethsindex);
/*-------------------------------------------------------------*/
/* Name : netwib_eths_index_close
Description :
Close a netwib_ethsindex.
Input parameter(s) :
Input/output parameter(s) :
**ppethsindex : netwib_eths_index closed
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_eths_index_close(netwib_eths_index **ppethsindex);
/*-------------------------------------------------------------*/
/* Types to control a netwib_eths_index */
typedef enum {
NETWIB_ETHS_INDEX_CTLTYPE_REWIND = 1, /* position at beginning */
NETWIB_ETHS_INDEX_CTLTYPE_INDEX /* reset with index pos */
} netwib_eths_index_ctltype;
/* Those functions permit to set/get parameters (pointer and
integer) about a netwib_eths_index. It should not be used directly,
but by the defines.
*/
netwib_err netwib_eths_index_ctl_set(netwib_eths_index *pethsindex,
netwib_eths_index_ctltype type,
netwib_ptr p,
netwib_uint32 ui);
netwib_err netwib_eths_index_ctl_get(netwib_eths_index *pethsindex,
netwib_eths_index_ctltype type,
netwib_ptr p,
netwib_uint32 *pui);
/*-------------------------------------------------------------*/
/* netwib_err f(netwib_eths_index *pethsindex); */
#define netwib_eths_index_ctl_set_rewind(pethsindex) netwib_eths_index_ctl_set(pethsindex,NETWIB_ETHS_INDEX_CTLTYPE_REWIND,NULL,0)
/* netwib_err f(netwib_eths_index *pethsindex,netwib_eths_index *pethsindexref);*/
#define netwib_eths_index_ctl_set_index(pethsindex,pethsindexref) netwib_eths_index_ctl_set(pethsindex,NETWIB_ETHS_INDEX_CTLTYPE_INDEX,pethsindexref,0)
/*-------------------------------------------------------------*/
/* Name : netwib_eths_index_next_eth
Description :
Get the next netwib_eth in the list.
Input parameter(s) :
Input/output parameter(s) :
*pethsindex : netwib_eths_index
Output parameter(s) :
*peth : next netwib_eth
Normal return values :
NETWIB_ERR_OK : ok
NETWIB_ERR_DATAEND : end of the list reached
Note :
If one thread changes the netwib_eths between two calls,
the next result might be incorrect. Developer have to
lock the entire loop (going through each item), or to
copy the netwib_eths and to loop on the copy.
*/
netwib_err netwib_eths_index_next_eth(netwib_eths_index *pethsindex,
netwib_eth *peth);
netwib_err netwib_eths_index_next_ethrange(netwib_eths_index *pethsindex,
netwib_eth *pinfeth,
netwib_eth *psupeth);
/*-------------------------------------------------------------*/
/* Name : netwib_eths_index_this_eth
Description :
Re-give the last netwib_eth in the list.
Input parameter(s) :
Input/output parameter(s) :
*pethsindex : netwib_eths_index
Output parameter(s) :
*peth : next netwib_eth
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_eths_index_this_eth(netwib_eths_index *pethsindex,
netwib_eth *peth);
netwib_err netwib_eths_index_this_ethrange(netwib_eths_index *pethsindex,
netwib_eth *pinfeth,
netwib_eth *psupeth);
/*-------------------------------------------------------------*/
/* Name : netwib_eths_index_this_del
Description :
Delete the last given value by a netwib_eths_index_next
function.
Input parameter(s) :
Input/output parameter(s) :
*pethsindex : netwib_eths_index
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_eths_index_this_del(netwib_eths_index *pethsindex);
/*-------------------------------------------------------------*/
/***************************************************************
* An port range is of the form : *
* portinf portsup *
* 123 : 123 123 *
* 123-124 : 123 124 *
* *
* An netwib_ports is of the form : *
* port,port,portrange,portrange *
* all,!port,!portrange *
* *
* Complete examples : *
* 123 *
* 123-125 *
* 1234,5678 *
* 1234,12356-12358 *
* all,!1234,!1244-1246 *
***************************************************************/
/*-------------------------------------------------------------*/
/***************************************************************
* Those functions ignores following error cases : *
* - if we try to add a value already in the list *
* - if we try to remove a value not in the list *
***************************************************************/
/*-------------------------------------------------------------*/
typedef struct netwib_ports netwib_ports;
typedef const netwib_ports netwib_constports;
/*-------------------------------------------------------------*/
/* Name : netwib_ports_init
Description :
Initialize a netwib_ports used to store port list.
Input parameter(s) :
inittype : if future added items will be sorted and/or unique
Input/output parameter(s) :
Output parameter(s) :
**ppports : netwib_ports allocated and initialized
Normal return values :
NETWIB_ERR_OK : ok
*/
typedef enum {
NETWIB_PORTS_INITTYPE_SORTUNIQ = 1, /* sorted and unique */
NETWIB_PORTS_INITTYPE_NOTSORTUNIQ = 2, /* not sorted and unique */
NETWIB_PORTS_INITTYPE_NOTSORTNOTUNIQ = 3 /* not sorted and not
unique (duplicates
are not removed) */
} netwib_ports_inittype;
netwib_err netwib_ports_init(netwib_ports_inittype inittype,
netwib_ports **ppports);
#define netwib_ports_initdefault(ppports) netwib_ports_init(NETWIB_PORTS_INITTYPE_SORTUNIQ,ppports)
/*-------------------------------------------------------------*/
/* Name : netwib_ports_close
Description :
Close a netwib_ports.
Input parameter(s) :
Input/output parameter(s) :
**ppports : netwib_ports closed
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_ports_close(netwib_ports **ppports);
/*-------------------------------------------------------------*/
/* Name : netwib_ports_add_port
Description :
Add a port to the netwib_ports.
Input parameter(s) :
port : address to add
Input/output parameter(s) :
*pports : netwib_ports where to work
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_ports_add_port(netwib_ports *pports,
netwib_port port);
/*-------------------------------------------------------------*/
/* Name : netwib_ports_add_portrange
Description :
Add a range of ports to the netwib_ports.
Input parameter(s) :
infport : inferior port
support : superior port
Input/output parameter(s) :
*pports : netwib_ports where to work
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_ports_add_portrange(netwib_ports *pports,
netwib_port infport,
netwib_port support);
/*-------------------------------------------------------------*/
/* Name : netwib_ports_add_ports
Description :
Add a list of port to the netwib_ports.
Input parameter(s) :
*pportstoadd : netwib_ports to add
Input/output parameter(s) :
*pports : netwib_ports where to work
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_ports_add_ports(netwib_ports *pports,
netwib_constports *pportstoadd);
/*-------------------------------------------------------------*/
/* Name : netwib_ports_add_buf
Description :
Update a netwib_ports with a string like "1234-1235".
Input parameter(s) :
*pbuf : buffer containing string
Input/output parameter(s) :
*pports : netwib_ports updated
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
Note :
If an error occurs during insertion, result will only
contain partial data. It's developer's job to use a
temporary netwib_ports to deal with such errors.
*/
netwib_err netwib_ports_add_buf(netwib_ports *pports,
netwib_constbuf *pbuf);
/*-------------------------------------------------------------*/
/* Name : netwib_ports_add_kbd
Description :
Update a netwib_ports with data entered through keyboard.
Input parameter(s) :
message : message to print before
defaultlist : default list to use if user enters nothing
if NULL, there is no default
Input/output parameter(s) :
*pports : netwib_ports updated
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_ports_add_kbd(netwib_ports *pports,
netwib_constbuf *pmessage,
netwib_constbuf *pdefaultlist);
/*-------------------------------------------------------------*/
/* Name : netwib_ports_del_port
Description :
Del a port from the netwib_ports.
Input parameter(s) :
port : address to delete
Input/output parameter(s) :
*pports : netwib_ports where to work
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_ports_del_port(netwib_ports *pports,
netwib_port port);
/*-------------------------------------------------------------*/
/* Name : netwib_ports_del_portrange
Description :
Del a range of ports to the netwib_ports.
Input parameter(s) :
infport : inferior port
support : superior port
Input/output parameter(s) :
*pports : netwib_ports where to work
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_ports_del_portrange(netwib_ports *pports,
netwib_port infport,
netwib_port support);
/*-------------------------------------------------------------*/
/* Name : netwib_ports_del_ports
Description :
Remove a list of port to the netwib_ports.
Input parameter(s) :
*pportstodel : netwib_ports to remove
Input/output parameter(s) :
*pports : netwib_ports where to work
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_ports_del_ports(netwib_ports *pports,
netwib_constports *pportstodel);
/*-------------------------------------------------------------*/
/* Name : netwib_ports_contains_xyz
Description :
Check if a netwib_port is in the list.
Input parameter(s) :
port : netwib_port to find
Input/output parameter(s) :
*pports : netwib_ports containing the list of addresses
Output parameter(s) :
*pyes : true if netwib_port is found
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_ports_contains_port(netwib_constports *pports,
netwib_port port,
netwib_bool *pyes);
netwib_err netwib_ports_contains_portrange(netwib_constports *pports,
netwib_port infport,
netwib_port support,
netwib_bool *pyes);
/*-------------------------------------------------------------*/
/* Name : netwib_buf_append_ports
Description :
Append a string representing a netwib_ports.
Input parameter(s) :
*pports : netwib_ports to append
Input/output parameter(s) :
pbuf : buffer updated
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_buf_append_ports(netwib_constports *pports,
netwib_buf *pbuf);
/*-------------------------------------------------------------*/
typedef struct netwib_ports_index netwib_ports_index;
/*-------------------------------------------------------------*/
/* Name : netwib_ports_index_init
Description :
Initialize a netwib_ports_index used to loop through
a netwib_ports.
Input parameter(s) :
Input/output parameter(s) :
Output parameter(s) :
**ppportsindex : netwib_ports_index allocated and initialized
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_ports_index_init(netwib_constports *pports,
netwib_ports_index **ppportsindex);
/*-------------------------------------------------------------*/
/* Name : netwib_ports_index_close
Description :
Close a netwib_portsindex.
Input parameter(s) :
Input/output parameter(s) :
**ppportsindex : netwib_ports_index closed
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_ports_index_close(netwib_ports_index **ppportsindex);
/*-------------------------------------------------------------*/
/* Types to control a netwib_ports_index */
typedef enum {
NETWIB_PORTS_INDEX_CTLTYPE_REWIND = 1, /* position at beginning */
NETWIB_PORTS_INDEX_CTLTYPE_INDEX /* reset with index pos */
} netwib_ports_index_ctltype;
/* Those functions permit to set/get parameters (pointer and
integer) about a netwib_ports_index. It should not be used directly,
but by the defines.
*/
netwib_err netwib_ports_index_ctl_set(netwib_ports_index *pportsindex,
netwib_ports_index_ctltype type,
netwib_ptr p,
netwib_uint32 ui);
netwib_err netwib_ports_index_ctl_get(netwib_ports_index *pportsindex,
netwib_ports_index_ctltype type,
netwib_ptr p,
netwib_uint32 *pui);
/*-------------------------------------------------------------*/
/* netwib_err f(netwib_ports_index *pportsindex); */
#define netwib_ports_index_ctl_set_rewind(pportsindex) netwib_ports_index_ctl_set(pportsindex,NETWIB_PORTS_INDEX_CTLTYPE_REWIND,NULL,0)
/* netwib_err f(netwib_ports_index *pportsindex,netwib_ports_index *pportsindexref);*/
#define netwib_ports_index_ctl_set_index(pportsindex,pportsindexref) netwib_ports_index_ctl_set(pportsindex,NETWIB_PORTS_INDEX_CTLTYPE_INDEX,pportsindexref,0)
/*-------------------------------------------------------------*/
/* Name : netwib_ports_index_next_port
Description :
Get the next netwib_port in the list.
Input parameter(s) :
Input/output parameter(s) :
*pportsindex : netwib_ports_index
Output parameter(s) :
*pport : next netwib_port
Normal return values :
NETWIB_ERR_OK : ok
NETWIB_ERR_DATAEND : end of the list reached
Note :
If one thread changes the netwib_ports between two calls,
the next result might be incorrect. Developer have to
lock the entire loop (going through each item), or to
copy the netwib_ports and to loop on the copy.
*/
netwib_err netwib_ports_index_next_port(netwib_ports_index *pportsindex,
netwib_port *pport);
netwib_err netwib_ports_index_next_portrange(netwib_ports_index *pportsindex,
netwib_port *pinfport,
netwib_port *psupport);
/*-------------------------------------------------------------*/
/* Name : netwib_ports_index_this_port
Description :
Re-give the last netwib_port in the list.
Input parameter(s) :
Input/output parameter(s) :
*pportsindex : netwib_ports_index
Output parameter(s) :
*pport : next netwib_port
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_ports_index_this_port(netwib_ports_index *pportsindex,
netwib_port *pport);
netwib_err netwib_ports_index_this_portrange(netwib_ports_index *pportsindex,
netwib_port *pinfport,
netwib_port *psupport);
/*-------------------------------------------------------------*/
/* Name : netwib_ports_index_this_del
Description :
Delete the last given value by a netwib_ports_index_next
function.
Input parameter(s) :
Input/output parameter(s) :
*pportsindex : netwib_ports_index
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_ports_index_this_del(netwib_ports_index *pportsindex);
/*-------------------------------------------------------------*/
/* Name : netwib_conf_display
Description :
Print devices/arp/routes configuration.
Input parameter(s) :
Input/output parameter(s) :
Output parameter(s) :
*pbuf : netwib_buf receiving data
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_conf_display(void);
netwib_err netwib_buf_append_conf(netwib_buf *pbuf);
/*-------------------------------------------------------------*/
/* For debugging purposes only */
netwib_err netwib_conf_debug_display(void);
netwib_err netwib_buf_append_conf_debug(netwib_buf *pbuf);
/*-------------------------------------------------------------*/
typedef struct netwib_conf_devices_index netwib_conf_devices_index;
/*-------------------------------------------------------------*/
typedef struct {
netwib_uint32 devnum;
netwib_buf device;
netwib_buf deviceeasy;
netwib_uint32 mtu;
netwib_device_hwtype hwtype;
netwib_eth eth;
} netwib_conf_devices;
/*-------------------------------------------------------------*/
/* Name : netwib_conf_devices_index_init
Description :
Initialize a netwib_conf_devices_index used to loop through
a netwib_conf_devices.
Input parameter(s) :
pitem : address of netwib_conf_devices which will be set
on each call of netwib_conf_devices_next
Input/output parameter(s) :
Output parameter(s) :
**ppindex : netwib_conf_devices_index allocated and initialized
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_conf_devices_index_init(netwib_conf_devices *pitem,
netwib_conf_devices_index **ppindex);
/*-------------------------------------------------------------*/
/* Name : netwib_conf_devices_index_close
Description :
Close a netwib_conf_devices_index.
Input parameter(s) :
Input/output parameter(s) :
**ppindex : netwib_conf_devices_index to close
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_conf_devices_index_close(netwib_conf_devices_index **ppindex);
/*-------------------------------------------------------------*/
/* Name : netwib_conf_devices_index_next
Description :
Get next entry.
Input parameter(s) :
Input/output parameter(s) :
*pindex : netwib_conf_devices_index to work on
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
NETWIB_ERR_DATAEND : end reached
*/
netwib_err netwib_conf_devices_index_next(netwib_conf_devices_index *pindex);
/*-------------------------------------------------------------*/
/* Name : netwib_conf_devices_display
Description :
Print devices configuration.
Input parameter(s) :
Input/output parameter(s) :
Output parameter(s) :
*pbuf : netwib_buf receiving data
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_conf_devices_display(void);
netwib_err netwib_buf_append_conf_devices(netwib_buf *pbuf);
/*-------------------------------------------------------------*/
typedef struct netwib_conf_ip_index netwib_conf_ip_index;
/*-------------------------------------------------------------*/
typedef struct {
netwib_uint32 devnum;
/* ip configuration */
netwib_ip ip;
netwib_ip mask; /* set for IPv4 */
netwib_uint32 prefix; /* set for IPv6 */
/* point to point configuration */
netwib_bool ispointtopoint;
netwib_ip pointtopointip;
} netwib_conf_ip;
/*-------------------------------------------------------------*/
/* Name : netwib_conf_ip_index_init
Description :
Initialize a netwib_conf_ip_index used to loop through
a netwib_conf_ip.
Input parameter(s) :
pitem : address of netwib_conf_ip which will be set
on each call of netwib_conf_ip_next
Input/output parameter(s) :
Output parameter(s) :
**ppindex : netwib_conf_ip_index allocated and initialized
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_conf_ip_index_init(netwib_conf_ip *pitem,
netwib_conf_ip_index **ppindex);
/*-------------------------------------------------------------*/
/* Name : netwib_conf_ip_index_close
Description :
Close a netwib_conf_ip_index.
Input parameter(s) :
Input/output parameter(s) :
**ppindex : netwib_conf_ip_index to close
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_conf_ip_index_close(netwib_conf_ip_index **ppindex);
/*-------------------------------------------------------------*/
/* Name : netwib_conf_ip_index_next
Description :
Get next entry.
Input parameter(s) :
Input/output parameter(s) :
*pindex : netwib_conf_ip_index to work on
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
NETWIB_ERR_DATAEND : end reached
*/
netwib_err netwib_conf_ip_index_next(netwib_conf_ip_index *pindex);
/*-------------------------------------------------------------*/
/* Name : netwib_conf_ip_display
Description :
Print ip configuration.
Input parameter(s) :
Input/output parameter(s) :
Output parameter(s) :
*pbuf : netwib_buf receiving data
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_conf_ip_display(void);
netwib_err netwib_buf_append_conf_ip(netwib_buf *pbuf);
/*-------------------------------------------------------------*/
typedef struct netwib_conf_arpcache_index netwib_conf_arpcache_index;
/*-------------------------------------------------------------*/
/***************************************************************
* This structure stores : *
* - ARP cache for IPv4 *
* - neighbors for IPv6 *
***************************************************************/
/*-------------------------------------------------------------*/
typedef struct {
netwib_uint32 devnum;
netwib_eth eth;
netwib_ip ip;
} netwib_conf_arpcache;
/*-------------------------------------------------------------*/
/* Name : netwib_conf_arpcache_index_init
Description :
Initialize a netwib_conf_arpcache_index used to loop through
a netwib_conf_arpcache.
Input parameter(s) :
pitem : address of netwib_conf_arpcache which will be set
on each call of netwib_conf_arpcache_next
Input/output parameter(s) :
Output parameter(s) :
**ppindex : netwib_conf_arpcache_index allocated and initialized
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_conf_arpcache_index_init(netwib_conf_arpcache *pitem,
netwib_conf_arpcache_index **ppindex);
/*-------------------------------------------------------------*/
/* Name : netwib_conf_arpcache_index_close
Description :
Close a netwib_conf_arpcache_index.
Input parameter(s) :
Input/output parameter(s) :
**ppindex : netwib_conf_arpcache_index to close
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_conf_arpcache_index_close(netwib_conf_arpcache_index **ppindex);
/*-------------------------------------------------------------*/
/* Name : netwib_conf_arpcache_index_next
Description :
Get next entry.
Input parameter(s) :
Input/output parameter(s) :
*pindex : netwib_conf_arpcache_index to work on
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
NETWIB_ERR_DATAEND : end reached
*/
netwib_err netwib_conf_arpcache_index_next(netwib_conf_arpcache_index *pindex);
/*-------------------------------------------------------------*/
/* Name : netwib_conf_arpcache_display
Description :
Print arp configuration.
Input parameter(s) :
Input/output parameter(s) :
Output parameter(s) :
*pbuf : netwib_buf receiving data
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_conf_arpcache_display(void);
netwib_err netwib_buf_append_conf_arpcache(netwib_buf *pbuf);
/*-------------------------------------------------------------*/
/* Name : netwib_conf_arpcache_add
Description :
Add an entry in the cache. Then resolving functions
can find the value.
Input parameter(s) :
*pdevice : can be NULL if unknown
*peth : Ethernet address
*pip : IP address
Input/output parameter(s) :
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_conf_arpcache_add(netwib_constbuf *pdevice,
netwib_consteth *peth,
netwib_constip *pip);
/*-------------------------------------------------------------*/
typedef struct netwib_conf_routes_index netwib_conf_routes_index;
/*-------------------------------------------------------------*/
typedef struct {
netwib_uint32 devnum;
netwib_ip dst;
netwib_ip mask; /* set for IPv4 */
netwib_uint32 prefix; /* set for IPv6 */
netwib_bool srcset;
netwib_ip src;
netwib_bool gwset;
netwib_ip gw;
netwib_uint32 metric;
} netwib_conf_routes;
/*
srcunset and gwunset : dst is a local device
srcset and gwunset : dst in on LAN
srcunset and gwset : error
srcset and gwset : dst is through gw
*/
/*-------------------------------------------------------------*/
/* Name : netwib_conf_routes_index_init
Description :
Initialize a netwib_conf_routes_index used to loop through
a netwib_conf_routes.
Input parameter(s) :
pitem : address of netwib_conf_routes which will be set
on each call of netwib_conf_routes_next
Input/output parameter(s) :
Output parameter(s) :
**ppindex : netwib_conf_routes_index allocated and initialized
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_conf_routes_index_init(netwib_conf_routes *pitem,
netwib_conf_routes_index **ppindex);
/*-------------------------------------------------------------*/
/* Name : netwib_conf_routes_index_close
Description :
Close a netwib_conf_routes_index.
Input parameter(s) :
Input/output parameter(s) :
**ppindex : netwib_conf_routes_index to close
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_conf_routes_index_close(netwib_conf_routes_index **ppindex);
/*-------------------------------------------------------------*/
/* Name : netwib_conf_routes_index_next
Description :
Get next entry.
Input parameter(s) :
Input/output parameter(s) :
*pindex : netwib_conf_routes_index to work on
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
NETWIB_ERR_DATAEND : end reached
*/
netwib_err netwib_conf_routes_index_next(netwib_conf_routes_index *pindex);
/*-------------------------------------------------------------*/
/* Name : netwib_conf_routes_display
Description :
Print routes configuration.
Input parameter(s) :
Input/output parameter(s) :
Output parameter(s) :
*pbuf : netwib_buf receiving data
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_conf_routes_display(void);
netwib_err netwib_buf_append_conf_routes(netwib_buf *pbuf);
/*-------------------------------------------------------------*/
/* Name : netwib_conf_routes_reach_eth
Description :
Determine device, sources addresses and destination Ethernet
address to use to send an IP packet to a host.
Input parameter(s) :
dstip : host to reach
Input/output parameter(s) :
Output parameter(s) :
*pdevice : device to use
*psrceth : Ethernet source address to use
*pdsteth : Ethernet destination address to use
*psrcip : IP source address to use
Normal return values :
NETWIB_ERR_OK : ok (set: all)
NETWIB_ERR_ROUTELOCALDEV : hostip is the address of a
local device (set : device)
NETWIB_ERR_ROUTENOTETHER : Ethernet is not used to reach
destination (set : none)
NETWIB_ERR_ROUTENOTFOUND : the routing table doesn't contain
a route to hostip (set : none)
*/
netwib_err netwib_conf_routes_reach_eth(netwib_constip *pdstip,
netwib_buf *pdevice,
netwib_eth *psrceth,
netwib_eth *pdsteth,
netwib_ip *psrcip);
/*-------------------------------------------------------------*/
/* Name : netwib_conf_routes_reach_ip
Description :
Determine device and addresses to use to send an IP packet
to a host.
Input parameter(s) :
dstip : host to reach
Input/output parameter(s) :
Output parameter(s) :
*pdevice : device to use (for example to sniff)
*psrcip : IP source address to use
Normal return values :
NETWIB_ERR_OK : ok (set: all)
NETWIB_ERR_ROUTELOCALDEV : hostip is the address of a
local device (set : *pdevice)
NETWIB_ERR_ROUTENOTFOUND : the routing table doesn't contain
a route to hostip (set : none)
*/
netwib_err netwib_conf_routes_reach_ip(netwib_constip *pdstip,
netwib_buf *pdevice,
netwib_ip *psrcip);
/*-------------------------------------------------------------*/
/* We need a forward declaration for netwib_ipproto.
*/
#include "../pkt/types.h"
/*-------------------------------------------------------------*/
/***************************************************************
* Parameter pip6exts permits to specify IP6 extensions (rfc *
* 3542). However, this is not yet implemented. *
***************************************************************/
/*-------------------------------------------------------------*/
/* Name : netwib_io_init_sock_xyz
Description :
Initialize a socket connection.
Input parameter(s) :
localip : local IP
remoteip : remote IP
iptype : iptype to use
localport : local port
remoteport : remote port
*pip4opts : optional IP options to add
Input/output parameter(s) :
Output parameter(s) :
**ppio : netwib_io initialized
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_io_init_sock_udp_cli_full(netwib_constip *plocalip,
netwib_constip *premoteip,
netwib_port localport,
netwib_port remoteport,
netwib_constbuf *pip4opts,
netwib_ipproto ip6extsproto,
netwib_constbuf *pip6exts,
netwib_io **ppio);
#define netwib_io_init_sock_udp_cli(plocalip,premoteip,localport,remoteport,ppio) netwib_io_init_sock_udp_cli_full(plocalip,premoteip,localport,remoteport,NULL,NETWIB_IPPROTO_NONE,NULL,ppio)
#define netwib_io_init_sock_udp_cli_easy(premoteip,remoteport,ppio) netwib_io_init_sock_udp_cli(NULL,premoteip,0,remoteport,ppio)
netwib_err netwib_io_init_sock_tcp_cli_full(netwib_constip *plocalip,
netwib_constip *premoteip,
netwib_port localport,
netwib_port remoteport,
netwib_constbuf *pip4opts,
netwib_ipproto ip6extsproto,
netwib_constbuf *pip6exts,
netwib_io **ppio);
#define netwib_io_init_sock_tcp_cli(plocalip,premoteip,localport,remoteport,ppio) netwib_io_init_sock_tcp_cli_full(plocalip,premoteip,localport,remoteport,NULL,NETWIB_IPPROTO_NONE,NULL,ppio)
#define netwib_io_init_sock_tcp_cli_easy(premoteip,remoteport,ppio) netwib_io_init_sock_tcp_cli(NULL,premoteip,0,remoteport,ppio)
netwib_err netwib_io_init_sock_udp_ser_full(netwib_constip *plocalip,
netwib_port localport,
netwib_constbuf *pip4opts,
netwib_ipproto ip6extsproto,
netwib_constbuf *pip6exts,
netwib_io **ppio);
#define netwib_io_init_sock_udp_ser(plocalip,localport,ppio) netwib_io_init_sock_udp_ser_full(plocalip,localport,NULL,NETWIB_IPPROTO_NONE,NULL,ppio)
netwib_err netwib_io_init_sock_udp_ser_easy(netwib_iptype iptype,
netwib_port localport,
netwib_io **ppio);
netwib_err netwib_io_init_sock_tcp_ser_full(netwib_constip *plocalip,
netwib_port localport,
netwib_constbuf *pip4opts,
netwib_ipproto ip6extsproto,
netwib_constbuf *pip6exts,
netwib_io **ppio);
#define netwib_io_init_sock_tcp_ser(plocalip,localport,ppio) netwib_io_init_sock_tcp_ser_full(plocalip,localport,NULL,NETWIB_IPPROTO_NONE,NULL,ppio)
netwib_err netwib_io_init_sock_tcp_ser_easy(netwib_iptype iptype,
netwib_port localport,
netwib_io **ppio);
netwib_err netwib_io_init_sock_udp_mulser_full(netwib_constip *plocalip,
netwib_port localport,
netwib_constbuf *pip4opts,
netwib_ipproto ip6extsproto,
netwib_constbuf *pip6exts,
netwib_io **ppio);
#define netwib_io_init_sock_udp_mulser(plocalip,localport,ppio) netwib_io_init_sock_udp_mulser_full(plocalip,localport,NULL,NETWIB_IPPROTO_NONE,NULL,ppio)
netwib_err netwib_io_init_sock_udp_mulser_easy(netwib_iptype iptype,
netwib_port localport,
netwib_io **ppio);
/*-------------------------------------------------------------*/
/* Name : netwib_sock_tcp_mulser_full
Description :
Deal with a tcp multi-client server.
Note : we never exit from this function.
Input parameter(s) :
localip : listening IP address
localport : listening port
ip4opts : IP options to add
pfunc : memory address of the function which will be
called for each client. For each call, the first
parameter ('pio') will be set with socket,
and the second parameter ('pinfos')
will be set with the optional parameter below.
Note : at the end, this function must not close pio
Input/output parameter(s) :
pinfos : optional parameter (can be NULL) which will be
used as the second parameter for *pfunc. This
may be used to send information to *pfunc.
Output parameter(s) :
Normal return values :
NETWIB_ERR_OK : ok
*/
typedef netwib_err (*netwib_sock_tcp_mulser_pf)(netwib_io *pio,
netwib_ptr pinfos);
netwib_err netwib_sock_tcp_mulser_full(netwib_constip *plocalip,
netwib_port localport,
netwib_constbuf *pip4opts,
netwib_ipproto ip6extsproto,
netwib_constbuf *pip6exts,
netwib_sock_tcp_mulser_pf pfunc,
netwib_ptr pinfos);
#define netwib_sock_tcp_mulser(plocalip,localport,pfunc,pinfos) netwib_sock_tcp_mulser_full(plocalip,localport,NULL,NETWIB_IPPROTO_NONE,NULL,pfunc,pinfos)
netwib_err netwib_sock_tcp_mulser_easy(netwib_iptype iptype,
netwib_port localport,
netwib_sock_tcp_mulser_pf pfunc,
netwib_ptr pinfos);
/*-------------------------------------------------------------*/
/* Set/get IP4 options */
/* netwib_err f(netwib_io *pio, netwib_constbuf *pip4opts); */
#define netwib_sock_ctl_set_ip4opts(pio,pip4opts) netwib_io_ctl_set(pio,NETWIB_IO_WAYTYPE_SUPPORTED,NETWIB_IO_CTLTYPE_SOCK_IP4OPTS,pip4opts,0)
/* netwib_err f(netwib_io *pio, netwib_buf *pip4opts); */
#define netwib_sock_ctl_get_ip4opts(pio,pip4opts) netwib_io_ctl_get(pio,NETWIB_IO_WAYTYPE_SUPPORTED,NETWIB_IO_CTLTYPE_SOCK_IP4OPTS,pip4opts,NULL)
/*-------------------------------------------------------------*/
/* Set/get IP6 extensions */
/* netwib_err f(netwib_io *pio, netwib_ipproto ip6extsproto,
netwib_constbuf *pip6exts); */
#define netwib_sock_ctl_set_ip6exts(pio,ip6extsproto,pip6exts) netwib_io_ctl_set(pio,NETWIB_IO_WAYTYPE_SUPPORTED,NETWIB_IO_CTLTYPE_SOCK_IP6EXTS,pip6exts,ip6extsproto)
/* netwib_err f(netwib_io *pio, netwib_ipproto *pip6extsproto,
netwib_buf *pip6exts); */
#define netwib_sock_ctl_get_ip6exts(pio,pip6extsproto,pip6exts) netwib_io_ctl_get(pio,NETWIB_IO_WAYTYPE_SUPPORTED,NETWIB_IO_CTLTYPE_SOCK_IP6EXTS,pip6exts,pip6extsproto)
/*-------------------------------------------------------------*/
/* Obtain local IP address and port */
/* netwib_err f(netwib_io *pio, netwib_ip *pip, netwib_port *pport); */
#define netwib_sock_ctl_get_local(pio,pip,pport) netwib_io_ctl_get(pio,NETWIB_IO_WAYTYPE_SUPPORTED,NETWIB_IO_CTLTYPE_SOCK_LOCAL,pip,pport)
/* Obtain remote IP address and port */
/* netwib_err f(netwib_io *pio, netwib_ip *pip, netwib_port *pport); */
#define netwib_sock_ctl_get_remote(pio,pip,pport) netwib_io_ctl_get(pio,NETWIB_IO_WAYTYPE_SUPPORTED,NETWIB_IO_CTLTYPE_SOCK_REMOTE,pip,pport)
/*-------------------------------------------------------------*/
/* Change multicast TTL */
/* netwib_err f(netwib_io *pio, netwib_uin32 ttl); */
#define netwib_sock_ctl_set_multicastttl(pio,ttl) netwib_io_ctl_set(pio,NETWIB_IO_WAYTYPE_SUPPORTED,NETWIB_IO_CTLTYPE_SOCK_MULTICASTTTL,NULL,ttl)
/*-------------------------------------------------------------*/
typedef enum {
NETWIB_IO_SOCKTYPE_UDP_CLI = 1,
NETWIB_IO_SOCKTYPE_TCP_CLI,
NETWIB_IO_SOCKTYPE_UDP_SER,
NETWIB_IO_SOCKTYPE_TCP_SER,
NETWIB_IO_SOCKTYPE_UDP_MULSER,
NETWIB_IO_SOCKTYPE_TCP_MULSER
} netwib_io_socktype;
/* Get socket type */
/* netwib_err f(netwib_io *pio, netwib_io_socktype *psocktype); */
#define netwib_sock_ctl_get_socktype(pio,psocktype) netwib_io_ctl_get(pio,NETWIB_IO_WAYTYPE_SUPPORTED,NETWIB_IO_CTLTYPE_SOCK_SOCKTYPE,psocktype,NULL)
/*-------------------------------------------------------------*/
/***************************************************************
* Netwib supports Ethernet cards(netwib_device_hwtype=ETHER), *
* Loopback(LOOPBACK) and Serial Modems(PPP). *
* Unfortunately, these are not supported on every system as *
* described in this table. *
* *
* Device_hwtype Supported? Returned_DLT *
* FreeBSD : *
* ETHER yes ETHER *
* LOOPBACK yes NULL *
* PPP yes ?[7] *
* Linux : *
* ETHER yes ETHER *
* LOOPBACK yes NULL *
* PPP yes ?[7] *
* OpenBSD : *
* ETHER yes ETHER *
* LOOPBACK yes LOOP *
* PPP yes ?[7] *
* Solaris : *
* ETHER yes ETHER *
* LOOPBACK no - *
* PPP yes[1] ?[7] *
* Windows 95 : *
* ETHER yes ETHER *
* LOOPBACK no - *
* PPP yes[1][2] ETHER *
* Windows 98 : *
* ETHER yes ETHER *
* LOOPBACK no - *
* PPP yes[1] ETHER *
* Windows Me : *
* ETHER yes ETHER *
* LOOPBACK no - *
* PPP ?[3] ETHER *
* Windows NT4 : *
* ETHER yes ETHER *
* LOOPBACK no - *
* PPP y/n[1][4] ETHER *
* Windows 2000 : *
* ETHER yes ETHER *
* LOOPBACK no - *
* PPP no[5] ETHER *
* Windows XP : *
* ETHER yes ETHER *
* LOOPBACK no - *
* PPP no[6] - *
* *
* Notes : *
* 1 : System adds a fake Ethernet header *
* 2 : Windows Sockets 2 and Dialup Networking 1.3 have to *
* be installed (urls are in problemusagewindows_en.txt) *
* 3 : Not tested *
* 4 : As described in WinPCAP FAQ, it doesn't work (but, it *
* works on my computer) *
* 5 : As described in WinPCAP FAQ, it doesn't work (on my *
* computer, when packets are sniffed, we can't spoof) *
* 6 : As described in WinPCAP FAQ, it doesn't work (a *
* contributor confirmed that it doesn't work on its *
* computer) *
* 7 : I'll summarize this info later... *
***************************************************************/
/*-------------------------------------------------------------*/
/* Name : netwib_io_init_sniff
Description :
Open a sniff session.
Returned packets will start at Link header.
Input parameter(s) :
*pdevice : device where we sniff
*pfilter : sniff filter (NULL to sniff everything)
Input/output parameter(s) :
Output parameter(s) :
**ppio : io created
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_io_init_sniff(netwib_constbuf *pdevice,
netwib_constbuf *pfilter,
netwib_io **ppio);
/*-------------------------------------------------------------*/
/***************************************************************
* Note about sniff filters : *
* Filters permit to select network packets we sniff. *
* Basic elements of a bpf filter are : *
* host 1.2.3.4 *
* net 192.168.10 *
* net 192.168.10.0 mask 255.255.255.0 *
* net 192.168.10.0/24 *
* port 21 *
* dst host 1.2.3.4 *
* src port 2345 *
* ether host a:b:c:d:e:f ("ether a:b:c:d:e:f" is not working)
* ether src aa:bb:cc:dd:ee:ff *
* ip *
* arp *
* rarp *
* tcp *
* icmp *
* udp *
* Here are filter examples : *
* host 1.2.3.4 *
* net 192.168 and icmp *
* host 1.2.3.4 or dst port 80 *
* (udp or tcp) and not host 1.2.3.4 *
***************************************************************/
/* change the filter */
/* netwib_err f(netwib_io *pio, netwib_constbuf *pfilter); */
#define netwib_sniff_ctl_set_filter(pio,pfilter) netwib_io_ctl_set(pio,NETWIB_IO_WAYTYPE_SUPPORTED,NETWIB_IO_CTLTYPE_SNIFF_FILTER,pfilter,0)
/* netwib_err f(netwib_io *pio, netwib_buf *pfilter); */
#define netwib_sniff_ctl_get_filter(pio,pfilter) netwib_io_ctl_get(pio,NETWIB_IO_WAYTYPE_SUPPORTED,NETWIB_IO_CTLTYPE_SNIFF_FILTER,pfilter,NULL)
/*-------------------------------------------------------------*/
/* obtain the DLT of returned packets */
/* netwib_err f(netwib_io *pio, netwib_device_dlttype *pdlt); */
#define netwib_sniff_ctl_get_dlt(pio,pdlt) netwib_io_ctl_get(pio,NETWIB_IO_WAYTYPE_SUPPORTED,NETWIB_IO_CTLTYPE_SNIFF_DLT,NULL,(netwib_uint32*)pdlt)
/*-------------------------------------------------------------*/
/***************************************************************
* This io link : *
* - has to be plugged on netwib_io_init_sniff *
* - reassemble fragmented IP packets *
* - do nothing with other packets *
***************************************************************/
netwib_err netwib_io_init_sniff_ipreas(netwib_io **ppio);
/*-------------------------------------------------------------*/
/***************************************************************
* This io link : *
* - has to be plugged on netwib_io_init_sniff_ipreas *
* - reorder sequences of TCP packets *
* - remove duplicate TCP packets *
* - do nothing with other packets *
***************************************************************/
netwib_err netwib_io_init_sniff_tcpreord(netwib_io **ppio);
/*-------------------------------------------------------------*/
/* Name : netwib_io_init_sniff_ip
Description :
Open a sniff session, and return only IP packets.
Returned packets will start at IP header (DLTTYPE_RAW).
Input parameter(s) :
*pdevice : device where we sniff
*pfilter : sniff filter (NULL to sniff everything)
ipreas : if netwib_io_init_sniff_ipreas has to
be used
tcpreord : if netwib_io_init_sniff_tcpreord has to
be used
Input/output parameter(s) :
Output parameter(s) :
**ppio : io created
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_io_init_sniff_ip(netwib_constbuf *pdevice,
netwib_constbuf *pfilter,
netwib_bool ipreas,
netwib_bool tcpreord,
netwib_io **ppio);
/*-------------------------------------------------------------*/
/***************************************************************
* Netwib supports Ethernet cards(netwib_device_hwtype=ETHER), *
* Loopback(LOOPBACK) and Serial Modems(PPP). *
* Unfortunately, these are not supported on every system as *
* described in this table. *
* *
* Device LINK LINK_dlt IP4 IP6 *
* hwtype supported? to_use supported? supported? *
* FreeBSD : *
* ETHER yes ETHER yes ?[3] *
* LOOPBACK yes NULL yes ?[3] *
* PPP ?[3] ?[3] yes ?[3] *
* Linux : *
* ETHER yes ETHER yes yes[4] *
* LOOPBACK no - yes yes[4] *
* PPP ?[3] ?[3] yes yes[4] *
* OpenBSD : *
* ETHER yes ETHER yes ?[3] *
* LOOPBACK no - yes ?[3] *
* PPP ?[3] ?[3] yes ?[3] *
* Solaris : *
* ETHER yes ETHER yes ?[3] *
* LOOPBACK no - no[1] no[1] *
* PPP ?[3] ?[3] yes ?[3] *
* Windows 95 : *
* ETHER yes ETHER no no *
* LOOPBACK no - no no *
* PPP no no no no *
* Windows 98 : *
* ETHER yes ETHER no no *
* LOOPBACK no - no no *
* PPP no no no no *
* Windows Me : *
* ETHER yes ETHER no no *
* LOOPBACK no - no no *
* PPP ?[3] ?[3] no no *
* Windows NT4 : *
* ETHER yes ETHER no no *
* LOOPBACK no - no no *
* PPP no no no no *
* Windows 2000 : *
* ETHER yes ETHER yes ?[3] *
* LOOPBACK no - no no *
* PPP ?[3] ?[3] yes ?[3] *
* Windows XP : *
* ETHER yes ETHER yes yes[4] *
* LOOPBACK no - no no *
* PPP ?[3] ?[3] ?[2] ?[3] *
* *
* Notes : *
* 1 : not sure *
* 2 : not tested *
* 3 : I'll summarize this info later... *
* 4 : on systems where IPv6 is supported *
***************************************************************/
/*-------------------------------------------------------------*/
/* Name : netwib_io_init_spoof
Description :
Open a spoof session.
Input parameter(s) :
*pdevice : device where we spoof
Input/output parameter(s) :
Output parameter(s) :
**ppio : io created
Normal return values :
NETWIB_ERR_OK : ok
*/
typedef enum {
NETWIB_SPOOF_INITTYPE_LINK = 1, /* spoof at link level */
NETWIB_SPOOF_INITTYPE_IP4, /* spoof at IP4 level */
NETWIB_SPOOF_INITTYPE_IP6 /* spoof at IP6 level */
} netwib_spoof_inittype;
netwib_err netwib_io_init_spoof(netwib_spoof_inittype inittype,
netwib_constbuf *pdevice,
netwib_io **ppio);
#define netwib_io_init_spoof_link(device,ppio) netwib_io_init_spoof(NETWIB_SPOOF_INITTYPE_LINK,device,ppio)
#define netwib_io_init_spoof_ip4(ppio) netwib_io_init_spoof(NETWIB_SPOOF_INITTYPE_IP4,NULL,ppio)
#define netwib_io_init_spoof_ip6(ppio) netwib_io_init_spoof(NETWIB_SPOOF_INITTYPE_IP6,NULL,ppio)
/*-------------------------------------------------------------*/
/* obtain the DLT needed to spoof at link level */
/* netwib_err f(netwib_io *pio, netwib_device_dlttype *pdlt); */
#define netwib_spoof_ctl_get_dlt(pio,pdlt) netwib_io_ctl_get(pio,NETWIB_IO_WAYTYPE_SUPPORTED,NETWIB_IO_CTLTYPE_SPOOF_DLT,NULL,(netwib_uint32*)pdlt)
/*-------------------------------------------------------------*/
/***************************************************************
* This io permits to spoof at IP4/6 level (DLTTYPE_RAW). *
***************************************************************/
typedef enum {
NETWIB_SPOOF_IP_INITTYPE_UNKNOWN = 0,
NETWIB_SPOOF_IP_INITTYPE_RAW, /* use only IP4/6 level */
NETWIB_SPOOF_IP_INITTYPE_LINKF, /* add a link header and spoof
at link level (source ad
is filled) */
NETWIB_SPOOF_IP_INITTYPE_LINKB, /* add a link header and spoof
at link level (source ad
is blank (0:0:0:0:0:0)) */
NETWIB_SPOOF_IP_INITTYPE_LINKFB, /* add a link header and spoof
at link level (source ad
can be blank) */
NETWIB_SPOOF_IP_INITTYPE_RAWLINKF, /* try IP4/6 level. If doesn't
work, use link */
NETWIB_SPOOF_IP_INITTYPE_RAWLINKB,
NETWIB_SPOOF_IP_INITTYPE_RAWLINKFB,
NETWIB_SPOOF_IP_INITTYPE_LINKFRAW, /* try link level. If doesn't
work, use IP4/6 */
NETWIB_SPOOF_IP_INITTYPE_LINKBRAW,
NETWIB_SPOOF_IP_INITTYPE_LINKFBRAW,
NETWIB_SPOOF_IP_INITTYPE_LINK = NETWIB_SPOOF_IP_INITTYPE_LINKFB,
NETWIB_SPOOF_IP_INITTYPE_RAWLINK = NETWIB_SPOOF_IP_INITTYPE_RAWLINKFB,
NETWIB_SPOOF_IP_INITTYPE_LINKRAW = NETWIB_SPOOF_IP_INITTYPE_LINKFBRAW,
NETWIB_SPOOF_IP_INITTYPE_BEST = NETWIB_SPOOF_IP_INITTYPE_LINKRAW
} netwib_spoof_ip_inittype;
netwib_err netwib_io_init_spoof_ip(netwib_spoof_ip_inittype inittype,
netwib_io **ppio);
#define netwib_io_init_spoof_ip_best(ppio) netwib_io_init_spoof_ip(NETWIB_SPOOF_IP_INITTYPE_BEST,NETWIB_PKT_FIELDTYPE_BEST,ppio)
/*-------------------------------------------------------------*/
/* Name : netwib_buf_append_spoof_ip_inittype
Description :
Obtains the buf string corresponding to a type.
Input parameter(s) :
type : type
Input/output parameter(s) :
Output parameter(s) :
*pbuf : netwib_buf set with the buf string
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_buf_append_spoof_ip_inittype(netwib_spoof_ip_inittype type,
netwib_buf *pbuf);
/*-------------------------------------------------------------*/
/* Name : netwib_spoof_ip_inittype_init_kbd
Description :
Initialize a netwib_spoof_ip_inittype with data entered
through keyboard.
Input parameter(s) :
*pmessage : message to print before
defaulttype : default type to use if user enters
nothing (if NETWIB_SPOOF_IP_INITTYPE_UNKNOWN,
means no default)
Input/output parameter(s) :
Output parameter(s) :
*phwtype : netwib_hwtype initialized
Normal return values :
NETWIB_ERR_OK : ok
*/
netwib_err netwib_spoof_ip_inittype_init_kbd(netwib_constbuf *pmessage,
netwib_spoof_ip_inittype defaulttype,
netwib_spoof_ip_inittype *ptype);
#define NETWIB_SPOOF_IP_INITTYPE_INIT_KBD_NODEF NETWIB_SPOOF_IP_INITTYPE_UNKNOWN
netwib(3), netwib_dat(3), netwib_sys(3),
netwib_net(3), netwib_pkt(3), netwib_shw(3),
netwib_err(3)
Visit the GSP FreeBSD Man Page Interface. Output converted with ManDoc. |