First public contribution.
1 /** @file ../include/net/if.h
8 Length of interface external name, including terminating '\\0'.
9 Limitation: IAP names in P.I.P.S. are restricted to 49 bytes in ASCII. For names in languages with a multi-byte character set,
10 you can go upto 24 characters for 2-byte and 16 characters for 3-byte representations.
11 All lengths are excluding the terminal NULL character.
17 /** @fn if_freenameindex(struct if_nameindex *ptr)
20 Refer to if_nametoindex() for the documentation
31 /** @fn if_nameindex(void)
33 Refer to if_nametoindex() for the documentation
44 /** @fn if_indextoname(unsigned int ifindex, char *ifname)
48 Refer to if_nametoindex() for the documentation
58 /** @fn if_nametoindex(const char *ifname)
61 Note: This description also covers the following functions -
62 if_indextoname() if_nameindex() if_freenameindex()
64 @return Upon successful completion, if_nametoindex returns the index number of the interface.
65 If the interface is not found, a value of 0 is returned and errno is set to ENXIO. Upon successful completion, if_indextoname returns ifname. If the interface is not found, a NULL pointer is returned and errno is set to ENXIO. The if_nameindex returns a NULL pointer if sufficient memory cannot be allocated.
67 The if_nametoindex function maps the interface name specified in ifname to its corresponding index.
68 If the specified interface does not exist, it returns 0.
70 The if_indextoname function maps the interface index specified in ifindex to it corresponding name, which is copied into the
71 buffer pointed to by ifname, which must be of at least IFNAMSIZ bytes.
72 This pointer is also the return value of the function.
73 If there is no interface corresponding to the specified
74 index, NULL is returned.
77 The if_nameindex function returns an array of if_nameindex structures, one structure per interface, as defined in the include
78 file #include <net/if.h>;
79 The if_nameindex structure contains at least the following entries:
80 unsigned int if_index; /* 1, 2, ... */
81 char *if_name; /* null terminated name: "le0", ... */
84 The end of the array of structures is indicated by a structure with an if_index of 0 and an if_name of NULL. A NULL pointer is returned upon an error.
86 The if_freenameindex function frees the dynamic memory that was
87 allocated by if_nameindex.
101 /** @struct if_nameindex
103 Includes the following members,
106 @externallyDefinedApi
109 /** @var if_nameindex::if_index
111 Numeric index of the interface.
115 /** @var if_nameindex::if_name
117 Null-terminated name of the interface.
121 /** @struct if_clonereq
123 Structure used to query names of interface cloners.
129 /** @var if_clonereq::ifcr_total
135 /** @var if_clonereq::ifcr_count
137 room for this many in user buffer
141 /** @var if_clonereq::ifcr_buffer
143 buffer for cloner names
149 Structure describing information about an interface which may be of interest to management entities.
155 /** @var if_data::ifi_type
157 generic interface information.
158 ethernet, tokenring, etc
162 /** @var if_data::ifi_physical
164 generic interface information
165 e.g., AUI, Thinnet, 10base-T, etc
169 /** @var if_data::ifi_addrlen
171 generic interface information
176 /** @var if_data::ifi_hdrlen
178 generic interface information
183 /** @var if_data::ifi_link_state
185 generic interface information
190 /** @var if_data::ifi_recvquota
192 generic interface information
193 polling quota for receive intrs
197 /** @var if_data::ifi_xmitquota
199 generic interface information
200 polling quota for xmit intrs
204 /** @var if_data::ifi_datalen
206 generic interface information
207 length of this data struct
211 /** @var if_data::ifi_mtu
213 generic interface information
214 maximum transmission unit
218 /** @var if_data::ifi_metric
220 generic interface information
221 routing metric (external only)
225 /** @var if_data::ifi_baudrate
227 generic interface information
232 /** @var if_data::ifi_ipackets
235 packets received on interface
238 /** @var if_data::ifi_ierrors
241 input errors on interface
245 /** @var if_data::ifi_opackets
248 packets sent on interface.
252 /** @var if_data::ifi_oerrors
255 output errors on interface.
259 /** @var if_data::ifi_collisions
262 collisions on csma interfaces.
266 /** @var if_data::ifi_ibytes
269 total number of octets received.
273 /** @var if_data::ifi_obytes
276 total number of octets sent.
280 /** @var if_data::ifi_imcasts
283 packets received via multicast.
287 /** @var if_data::ifi_omcasts
290 packets sent via multicast
294 /** @var if_data::ifi_iqdrops
297 dropped on input, this interface.
301 /** @var if_data::ifi_noproto
304 destined for unsupported protocol.
308 /** @var if_data::ifi_hwassist
311 HW offload capabilities
315 /** @var if_data::ifi_epoch
318 uptime at attach or stat reset.
322 /** @var if_data::ifi_timepad
325 time_t is int, not long on alpha.
329 /** @var if_data::ifi_lastchange
332 time of last administrative change
336 /** @struct if_msghdr
338 Message format for use in obtaining information about interfaces from getkerninfo and the routing socket
344 /** @struct ifa_msghdr
346 Message format for use in obtaining information about interface addresses from getkerninfo and the routing socket
352 /** @var ifa_msghdr::ifam_msglen
354 to skip over non-understood messages
358 /** @var ifa_msghdr::ifam_version
360 future binary compatibility
364 /** @var ifa_msghdr::ifam_type
370 /** @var ifa_msghdr::ifam_addrs
376 /** @var ifa_msghdr::ifam_flags
382 /** @var ifa_msghdr::ifam_index
384 index for associated ifp
388 /** @var ifa_msghdr::ifam_metric
390 index for associated ifp
394 /** @struct ifma_msghdr
396 Message format for use in obtaining information about multicast addresses from the routing socket
402 /** @var ifma_msghdr::ifmam_msglen
404 to skip over non-understood messages
408 /** @var ifma_msghdr::ifmam_version
410 future binary compatibility
414 /** @var ifma_msghdr::ifmam_type
420 /** @var ifma_msghdr::ifmam_addrs
426 /** @var ifma_msghdr::ifmam_flags
432 /** @var ifma_msghdr::ifmam_index
434 index for associated ifp
439 /** @struct if_announcemsghdr
441 Message format announcing the arrival or departure of a network interface.
447 /** @var if_announcemsghdr::ifan_msglen
449 to skip over non-understood messages
453 /** @var if_announcemsghdr::ifan_version
455 future binary compatibility
459 /** @var if_announcemsghdr::ifan_type
465 /** @var if_announcemsghdr::ifan_index
467 index for associated ifp
471 /** @var if_announcemsghdr::ifan_name
477 /** @var if_announcemsghdr::ifan_what
479 what type of announcement
486 Interface request structure used for socket ioctl's.
487 All interface ioctl's must have parameter definitions which begin with ifr_name. The remainder may be interface specific.
495 Structure used in SIOCGIFCONF request.
496 Used to retrieve interface configuration for machine (useful for programs which must know all networks accessible).
503 /** @struct if_laddrreq
505 Structure for SIOC[AGD]LIFADDR
512 /** @fn int setdefaultif( const struct ifreq* ifrequest )
515 @return The setdefaultif returns 0 on success and -1 on failure.
516 Specifically, if the interface is not found, -1 is returned and errno is set to ENOENT.
518 The setdefaultif function can be used to set (or remove) a default network interface (either IAP or SNAP) for the application.
519 This default interface, if set, will be used by all the further socket related function calls (connect, send, write etc)
520 and all the host resolver function calls (getaddrinfo, getnameinfo, gethostbyname, getaddrbyname etc).
522 If there is a default interface set using setdefaultif and if there is a separate interface set on a socket
523 using the ioctl system call, network operations on that socket will not use the default one,
524 but the socket specific interface.
526 To remove the default interace, pass NULL as the argument.
528 To set an IAP name as the default interface, the 'ifr_name' member of the 'ifreq' structure must be filled with
529 the IAP name to be set. Unicode IAP names can also be set by converting them to UTF8 format before passing them to
530 this API. See the example below:
542 /* Set the default interface using IAP name */
543 strcpy( ifReq.ifr_name, "Example Interface Name" );
544 ret = setdefaultif( &ifReq );
546 printf( "Setting default interface failed with errno = %d", errno );
548 /* Perform network operations */
551 /* Remove the default interface */
552 ret = setdefaultif( NULL );
554 printf( "Removing default interface failed with errno = %d", errno );
560 To set a SNAP id as the default interface, the 'ifr_name' member of the 'ifreq' structure must be an empty string.
561 In this case, the 'snap_id' member of the 'ifr_ifru' union in the parameter should contain the SNAP id to be set.
562 It is recommended to zero initialize the 'ifreq' structure in this case. See the example below.
573 unsigned int snapId = /* Get the SNAP id to be set from the application settings */
575 /* Set the default interface using SNAP id */
577 /* memset the ifreq to make sure that the interface name is an empty string */
578 memset(&ifReq, 0, sizeof(struct ifreq));
579 ifReq.ifr_ifru.snap_id = snapId;
581 ret = setdefaultif( &ifReq );
583 printf( "Setting default interface failed with errno = %d", errno );
585 /* Perform network operations */
588 /* Remove the default interface */
589 ret = setdefaultif( NULL );
591 printf( "Removing default interface failed with errno = %d", errno );
597 The setdefaultif is not guaranteed to be thread safe.