lcrzo_device(3)

NAME
lcrzo_device - lcrzo library : devices (network boards)

CONTENTS
/*    Laurent Constantin's network library (lcrzo)
                 lcrzo_device module
  Functions herein allow to work on devices.
*/
/* device name (ex. eth0, le0) */
#define LCRZO_DEVICE_MAXBYTES 128
typedef lcrzo_int8 lcrzo_device[LCRZO_DEVICE_MAXBYTES+1]; /*+1 for/pour '\0'*/
typedef const lcrzo_device lcrzo_constdevice;
/*-------------------------------------------------------------*/
/* this define permits to verify that there is no buffer overflow
   before setting a lcrzo_device */
#define lcrzo_device_verifbof(device) if(strlen(device)>LCRZO_DEVICE_MAXBYTES)return(LCRZO_ERR_PAOVERFLOW)
/*-------------------------------------------------------------*/
/* Name : lcrzo_device_init
   Description :
     Initialize an lcrzo_device address
   Input parameter(s) :
     indevice : string containing the host name
   Input/output parameter(s) :
   Output parameter(s) :
     outdevice : lcrzo_device set with indevice
   Normal return values :
     LCRZO_ERR_OK : ok
     LCRZO_ERR_OKDATATRUNCATED : all the data can't be put in deviceout
*/
int lcrzo_device_init(lcrzo_constdevice indevice,
		      lcrzo_device outdevice);
/* idem, but convert " eth0:1 " to "eth0" */
int lcrzo_device_init_noalias(lcrzo_constdevice indevice,
			      lcrzo_device outdevice);
/*-------------------------------------------------------------*/
/* Name : lcrzo_device_equal
   Description :
     Verify if two lcrzo_device are equal
   Input parameter(s) :
     device1 : lcrzo_device to compare with device2
     device2 : lcrzo_device to compare with device1
   Input/output parameter(s) :
   Output parameter(s) :
   Normal return values :
     0 : if device1 and device2 are different
     1 : if device1 and device2 are equal
*/
lcrzo_bool lcrzo_device_equal(lcrzo_constdevice device1,
		       lcrzo_constdevice device2);
/*-------------------------------------------------------------*/
/* Name : lcrzo_device_cmp
   Description :
     Compare two lcrzo_device
   Input parameter(s) :
     device1 : lcrzo_device to compare with device2
     device2 : lcrzo_device to compare with device1
   Input/output parameter(s) :
   Output parameter(s) :
   Normal return values :
     -1 : device1<device2
      0 : if device1 and device2 are equal
     +1 : device1>device2
*/
lcrzo_int8 lcrzo_device_cmp(lcrzo_constdevice device1,
		     lcrzo_constdevice device2);
/*-------------------------------------------------------------*/
/* Name : lcrzo_device_initdefault
   Description :
     Initialize a default lcrzo_device address
   Input parameter(s) :
   Input/output parameter(s) :
   Output parameter(s) :
     device : lcrzo_device set with "" (default value)
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_device_initdefault(lcrzo_device device);
/*-------------------------------------------------------------*/
/* Name : lcrzo_mtu_init_device
   Description :
     Get the MTU (Maxi. transmission Unit) of a device
   Input parameter(s) :
     device : device of which we get the MTU
   Input/output parameter(s) :
   Output parameter(s) :
     *pmtu : MTU of device
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_mtu_init_device(lcrzo_constdevice device,
			  lcrzo_uint32 *pmtu);
/* Name : lcrzo_etha_init_device
   Description :
     Get the Ethernet address of a device
   Input parameter(s) :
     device : device of which we get the Ethernet address
   Input/output parameter(s) :
   Output parameter(s) :
     etha : lcrzo_etha of device
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_etha_init_device(lcrzo_constdevice device,
			   lcrzo_etha etha);
/* Name : lcrzo_ipl_init_device
   Description :
     Get the IP address of a device
   Input parameter(s) :
     device : device of which we get the IP address
   Input/output parameter(s) :
   Output parameter(s) :
     ipl : lcrzo_ipl of device
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_ipl_init_device(lcrzo_constdevice device,
			  lcrzo_ipl *pipl,
			  lcrzo_ipl *pmask);
/* Name : lcrzo_hs_init_device
   Description :
     Get the hostname of a device
   Input parameter(s) :
     device : device of which we get the hostname
   Input/output parameter(s) :
   Output parameter(s) :
     hs : lcrzo_hs of device
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_hs_init_device(lcrzo_constdevice device,
			 lcrzo_hs hs);
/*-------------------------------------------------------------*/
/* we define 6 types of devices : */
/* Note : those types are almost obsolete. Use :
     lcrzo_conf_devices_count
     lcrzo_conf_devices_value_pos
   which are more powerful
*/
/* down interfaces, up interfaces, down aliases, up aliases*/
#define LCRZO_DEVICE_TYPE_ALL         1
/* up interfaces, up aliases (no loopback)*/
#define LCRZO_DEVICE_TYPE_ONLYVALIDIP 2
/* up Ethernet interfaces (one for each network card)*/
#define LCRZO_DEVICE_TYPE_ONLYBOARDS  3
/* loopback */
#define LCRZO_DEVICE_TYPE_LOOPBACK    4
/* up interfaces */
#define LCRZO_DEVICE_TYPE_UP          5
/* alias */
#define LCRZO_DEVICE_TYPE_ALIAS       6
/* best interface for default choice */
#define LCRZO_DEVICE_TYPE_BEST        7
/* Name : lcrzo_device_istype
   Description :
     Verify if a device is of given type
   Input parameter(s) :
     device : device to check
     type : type to check (LCRZO_DEVICE_TYPE_ALL, ONLYVALIDIP, etc.)
   Input/output parameter(s) :
   Output parameter(s) :
     *pyesitistype : 1 if device has type 'type'
                     0 if device hasn't type 'type'
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_device_istype(lcrzo_constdevice device,
			lcrzo_int16 type,
			lcrzo_bool *pyesitistype);
/* Name : lcrzo_device_count
   Description :
     Count the number of devices of given type
   Input parameter(s) :
     type : type to count (LCRZO_DEVICE_TYPE_ALL, ONLYVALIDIP, etc.)
   Input/output parameter(s) :
   Output parameter(s) :
     *pcount : number of devices which have type 'type'
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_device_count(lcrzo_int16 type,
		       lcrzo_int32 *pcount);
/**********************************************
 * Note about positions :                     *
 * Warning : 0 is an invalid value            *
 * Here are possible values for a position :  *
 *  +1 : first item                           *
 *  +2 : second item                          *
 *  ...                                       *
 * Moreover, we can count from the end :      *
 *  -1 : last item                            *
 *  -2 : last but one item                    *
 *  ...                                       *
 **********************************************/
/* Name : lcrzo_device_value_pos
   Description :
     Get a device of a given type
   Input parameter(s) :
     type : type we want (LCRZO_DEVICE_TYPE_ALL, ONLYVALIDIP, etc.)
     pos : position of the wanted device (cf. the above frame to
           know possible values)
   Input/output parameter(s) :
   Output parameter(s) :
     device : device number 'pos' and which have type 'type'
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_device_value_pos(lcrzo_int16 type,
			   lcrzo_int32 pos,
			   lcrzo_device device);
/* Name : lcrzo_device_value_first
   Description :
     Get the first device of a given type
   Input parameter(s) :
     type : type we want (LCRZO_DEVICE_TYPE_ALL, ONLYVALIDIP, etc.)
   Input/output parameter(s) :
   Output parameter(s) :
     device : first device which have type 'type'
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_device_value_first(lcrzo_int16 type,
			     lcrzo_device device);
/* Name : lcrzo_device_value_last
   Description :
     Get the last device of a given type
   Input parameter(s) :
     type : type we want (LCRZO_DEVICE_TYPE_ALL, ONLYVALIDIP, etc.)
   Input/output parameter(s) :
   Output parameter(s) :
     device : last device which have type 'type'
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_device_value_last(lcrzo_int16 type,
			    lcrzo_device device);
/* Name : lcrzo_device_loop_range
   Description :
     Call a function for each device of a given type, and in a
     given position range.
   Input parameter(s) :
     type : type we want (LCRZO_DEVICE_TYPE_ALL, ONLYVALIDIP, etc.)
     startpos : start position for the loop (cf. the above frame to
                know possible values)
     endpos : end position for the loop (cf. the above frame to
              know possible values)
     pfunc : memory address of the function which will be called
             for each device in the range [startpos->endpos]. For
             each call, the first parameter ('device') will be set
             with the device, and the second parameter ('pinfos')
             will be set with the optional parameter below.
   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 :
     LCRZO_ERR_OK : ok
*/
int lcrzo_device_loop_range(lcrzo_int16 type,
			    lcrzo_int32 startpos,
			    lcrzo_int32 endpos,
			    int (*pfunc)(lcrzo_device device,
					 void *pinfos),
			    void *pinfos);
/* Name : lcrzo_device_loop_all
   Description :
     Call a function for every device of a given type.
   Input parameter(s) :
     type : type we want (LCRZO_DEVICE_TYPE_ALL, ONLYVALIDIP, etc.)
     pfunc : memory address of the function which will be called
             for every device. For each call, the first parameter
             ('device') will be set with the device, and the
	     second parameter ('pinfos') will be set with the
	     optional parameter below.
   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 :
     LCRZO_ERR_OK : ok
*/
int lcrzo_device_loop_all(lcrzo_int16 type,
			  int (*pfunc)(lcrzo_device device,
				       void *pinfos),
			  void *pinfos);
/*-------------------------------------------------------------*/
/* Name : lcrzo_device_init_stdin
   Description :
     Initialize an lcrzo_device with the address entered by the
     user through the keyboard
   Input parameter(s) :
     message : message to print before
     defaultdevice : default lcrzo_device to use if user enters nothing
   Input/output parameter(s) :
   Output parameter(s) :
     device : lcrzo_device set with user's string
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_device_init_stdin(lcrzo_conststring message,
			    lcrzo_constdevice defaultdevice,
			    lcrzo_device device);

SEE ALSO
lcrzo(3), lcrzo_types(3), lcrzo_data(3), lcrzo_string(3), lcrzo_time(3), lcrzo_file(3), lcrzo_address(3), lcrzo_device(3), lcrzo_list(3), lcrzo_process(3), lcrzo_ipc(3), lcrzo_header(3), lcrzo_ipopt(3), lcrzo_tcpopt(3), lcrzo_packet(3), lcrzo_icmp(3), lcrzo_print(3), lcrzo_record(3), lcrzo_conf(3), lcrzo_spoof(3), lcrzo_sniff(3), lcrzo_sock(3), lcrzo_wait(3), lcrzo_global(3), lcrzo_error(3) lcrzo_misc(3), lcrzo_obso(3),