os/ossrv/genericopenlibs/openenvcore/include/net/if.dosc
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /** @file ../include/net/if.h
     2 @internalComponent
     3 */
     4 
     5 
     6 /** @def IF_NAMESIZE	
     7 
     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.
    12 
    13 @publishedAll
    14 @externallyDefinedApi
    15 */
    16 
    17 /** @fn  if_freenameindex(struct if_nameindex *ptr)
    18 @param ptr
    19 
    20 Refer to if_nametoindex() for the documentation
    21 
    22 
    23  
    24 
    25 @publishedAll
    26 @externallyDefinedApi
    27 */
    28 
    29 
    30 
    31 /** @fn  if_nameindex(void)
    32 
    33 Refer to if_nametoindex() for the documentation
    34 
    35 
    36  
    37 
    38 @publishedAll
    39 @externallyDefinedApi
    40 */
    41 
    42 
    43 
    44 /** @fn  if_indextoname(unsigned int ifindex, char *ifname)
    45 @param ifindex
    46 @param ifname
    47 
    48 Refer to if_nametoindex() for the documentation
    49 
    50 
    51  
    52 
    53 @publishedAll
    54 @externallyDefinedApi
    55 */
    56 
    57 
    58 /** @fn  if_nametoindex(const char *ifname)
    59 @param ifname
    60 
    61 Note: This description also covers the following functions -
    62  if_indextoname()  if_nameindex()  if_freenameindex() 
    63 
    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.
    66 
    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.
    69 
    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.
    75 
    76 @code
    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", ... */
    82 @endcode
    83 
    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.
    85 
    86  The if_freenameindex function frees the dynamic memory that was
    87 allocated by if_nameindex.
    88 
    89 
    90 
    91 
    92 
    93  
    94 
    95 @publishedAll
    96 @externallyDefinedApi
    97 */
    98 
    99 
   100 
   101 /** @struct if_nameindex
   102 
   103 Includes the following members,
   104 
   105 @publishedAll
   106 @externallyDefinedApi
   107 */
   108 
   109 /** @var if_nameindex::if_index
   110 
   111 Numeric index of the interface. 
   112 
   113 */
   114 
   115 /** @var if_nameindex::if_name
   116 
   117 Null-terminated name of the interface. 
   118 
   119 */
   120 
   121 /** @struct if_clonereq
   122 
   123 Structure used to query names of interface cloners.
   124 
   125 @publishedAll
   126 @released
   127 */
   128 
   129 /** @var if_clonereq::ifcr_total
   130 
   131 total cloners (out)
   132 
   133 */
   134 
   135 /** @var if_clonereq::ifcr_count
   136 
   137 room for this many in user buffer
   138 
   139 */
   140 
   141 /** @var if_clonereq::ifcr_buffer
   142 
   143 buffer for cloner names
   144 
   145 */
   146 
   147 /** @struct if_data
   148 
   149 Structure describing information about an interface which may be of interest to management entities.
   150 
   151 @publishedAll
   152 @released
   153 */
   154 
   155 /** @var if_data::ifi_type
   156 
   157 generic interface information. 
   158 ethernet, tokenring, etc
   159 
   160 */
   161 
   162 /** @var if_data::ifi_physical
   163 
   164 generic interface information
   165 e.g., AUI, Thinnet, 10base-T, etc
   166 
   167 */
   168 
   169 /** @var if_data::ifi_addrlen
   170 
   171 generic interface information
   172 media address length 
   173 
   174 */
   175 
   176 /** @var if_data::ifi_hdrlen
   177 
   178 generic interface information
   179 media header length
   180 
   181 */
   182 
   183 /** @var if_data::ifi_link_state
   184 
   185 generic interface information
   186 current link state
   187 
   188 */
   189 
   190 /** @var if_data::ifi_recvquota
   191 
   192 generic interface information
   193 polling quota for receive intrs
   194 
   195 */
   196 
   197 /** @var if_data::ifi_xmitquota
   198 
   199 generic interface information
   200 polling quota for xmit intrs
   201 
   202 */
   203 
   204 /** @var if_data::ifi_datalen
   205 
   206 generic interface information
   207 length of this data struct 
   208 
   209 */
   210 
   211 /** @var if_data::ifi_mtu
   212 
   213 generic interface information
   214 maximum transmission unit
   215 
   216 */
   217 
   218 /** @var if_data::ifi_metric
   219 
   220 generic interface information
   221 routing metric (external only)
   222 
   223 */
   224 
   225 /** @var if_data::ifi_baudrate
   226 
   227 generic interface information
   228 linespeed
   229 
   230 */
   231 
   232 /** @var if_data::ifi_ipackets
   233 
   234 volatile statistics.
   235 packets received on interface 
   236 
   237 */
   238 /** @var if_data::ifi_ierrors
   239 
   240 volatile statistics.
   241 input errors on interface
   242 
   243 */
   244 
   245 /** @var if_data::ifi_opackets
   246 
   247 volatile statistics.
   248 packets sent on interface.
   249 
   250 */
   251 
   252 /** @var if_data::ifi_oerrors
   253 
   254 volatile statistics.
   255 output errors on interface.
   256 
   257 */
   258 
   259 /** @var if_data::ifi_collisions
   260 
   261 volatile statistics.
   262 collisions on csma interfaces.
   263 
   264 */
   265 
   266 /** @var if_data::ifi_ibytes
   267 
   268 volatile statistics.
   269 total number of octets received.
   270 
   271 */
   272 
   273 /** @var if_data::ifi_obytes
   274 
   275 volatile statistics.
   276 total number of octets sent.
   277 
   278 */
   279 
   280 /** @var if_data::ifi_imcasts
   281 
   282 volatile statistics.
   283 packets received via multicast.
   284 
   285 */
   286 
   287 /** @var if_data::ifi_omcasts
   288 
   289 volatile statistics.
   290 packets sent via multicast
   291 
   292 */
   293 
   294 /** @var if_data::ifi_iqdrops
   295 
   296 volatile statistics.
   297 dropped on input, this interface.
   298 
   299 */
   300 
   301 /** @var if_data::ifi_noproto
   302 
   303 volatile statistics.
   304 destined for unsupported protocol.
   305 
   306 */
   307 
   308 /** @var if_data::ifi_hwassist
   309 
   310 volatile statistics.
   311 HW offload capabilities
   312 
   313 */
   314 
   315 /** @var if_data::ifi_epoch
   316 
   317 volatile statistics.
   318 uptime at attach or stat reset.
   319 
   320 */
   321 
   322 /** @var if_data::ifi_timepad
   323 
   324 volatile statistics.
   325 time_t is int, not long on alpha.
   326 
   327 */
   328 
   329 /** @var if_data::ifi_lastchange
   330 
   331 volatile statistics.
   332 time of last administrative change
   333 
   334 */
   335 
   336 /** @struct if_msghdr
   337 
   338 Message format for use in obtaining information about interfaces from getkerninfo and the routing socket
   339 
   340 @publishedAll
   341 @released
   342 */
   343 
   344 /** @struct ifa_msghdr
   345 
   346 Message format for use in obtaining information about interface addresses from getkerninfo and the routing socket
   347 
   348 @publishedAll
   349 @released
   350 */
   351 
   352 /** @var ifa_msghdr::ifam_msglen
   353 
   354 to skip over non-understood messages
   355 
   356 */
   357 
   358 /** @var ifa_msghdr::ifam_version
   359 
   360 future binary compatibility
   361 
   362 */
   363 
   364 /** @var ifa_msghdr::ifam_type
   365 
   366 message type
   367 
   368 */
   369 
   370 /** @var ifa_msghdr::ifam_addrs
   371 
   372 like rtm_addrs
   373 
   374 */
   375 
   376 /** @var ifa_msghdr::ifam_flags
   377 
   378 value of ifa_flags
   379 
   380 */
   381 
   382 /** @var ifa_msghdr::ifam_index
   383 
   384 index for associated ifp
   385 
   386 */
   387 
   388 /** @var ifa_msghdr::ifam_metric
   389 
   390 index for associated ifp
   391 
   392 */
   393 
   394 /** @struct ifma_msghdr
   395 
   396 Message format for use in obtaining information about multicast addresses from the routing socket
   397 
   398 @publishedAll
   399 @released
   400 */
   401 
   402 /** @var ifma_msghdr::ifmam_msglen
   403 
   404 to skip over non-understood messages
   405 
   406 */
   407 
   408 /** @var ifma_msghdr::ifmam_version
   409 
   410 future binary compatibility
   411 
   412 */
   413 
   414 /** @var ifma_msghdr::ifmam_type
   415 
   416 message type
   417 
   418 */
   419 
   420 /** @var ifma_msghdr::ifmam_addrs
   421 
   422 like rtm_addrs
   423 
   424 */
   425 
   426 /** @var ifma_msghdr::ifmam_flags
   427 
   428 value of ifa_flags
   429 
   430 */
   431 
   432 /** @var ifma_msghdr::ifmam_index
   433 
   434 index for associated ifp
   435 
   436 */
   437 
   438 
   439 /** @struct if_announcemsghdr
   440 
   441 Message format announcing the arrival or departure of a network interface.
   442 
   443 @publishedAll
   444 @released
   445 */
   446 
   447 /** @var if_announcemsghdr::ifan_msglen
   448 
   449 to skip over non-understood messages
   450 
   451 */
   452 
   453 /** @var if_announcemsghdr::ifan_version
   454 
   455 future binary compatibility
   456 
   457 */
   458 
   459 /** @var if_announcemsghdr::ifan_type
   460 
   461 message type
   462 
   463 */
   464 
   465 /** @var if_announcemsghdr::ifan_index
   466 
   467 index for associated ifp
   468 
   469 */
   470 
   471 /** @var if_announcemsghdr::ifan_name
   472 
   473 if name, e.g. "en0"
   474 
   475 */
   476 
   477 /** @var if_announcemsghdr::ifan_what
   478 
   479 what type of announcement
   480 
   481 */
   482 
   483 
   484 /** @struct ifreq
   485 
   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.
   488 
   489 @publishedAll
   490 @released
   491 */
   492 
   493 /** @struct ifconf
   494 
   495 Structure used in SIOCGIFCONF request.
   496 Used to retrieve interface configuration for machine (useful for programs which must know all networks accessible).
   497 
   498 @publishedAll
   499 @released
   500 */
   501 
   502 
   503 /** @struct if_laddrreq
   504 
   505 Structure for SIOC[AGD]LIFADDR
   506 
   507 @publishedAll
   508 @released
   509 */
   510 
   511 
   512 /** @fn  int setdefaultif( const struct ifreq* ifrequest )
   513 @param ifrequest
   514 
   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.
   517 
   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).
   521 
   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.
   525 
   526 To remove the default interace, pass NULL as the argument.  
   527 
   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:
   531 
   532 @code
   533 #include <stdio.h>
   534 #include <string.h>
   535 #include <net/if.h>
   536 
   537 int main()
   538 	{
   539 	struct ifreq ifReq;
   540 	int ret;
   541 	
   542 	/* Set the default interface using IAP name */
   543 	strcpy( ifReq.ifr_name, "Example Interface Name" );
   544 	ret = setdefaultif( &ifReq );
   545 	if( ret == -1 )
   546 		printf( "Setting default interface failed with errno = %d", errno );
   547 	
   548 	/* Perform network operations */
   549 	/* ... */
   550 	
   551 	/* Remove the default interface */
   552 	ret = setdefaultif( NULL );
   553 	if( ret == -1 )
   554 		printf( "Removing default interface failed with errno = %d", errno );
   555 	
   556 	return 0;
   557 	}
   558 @endcode 
   559 
   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. 
   563 
   564 @code
   565 #include <stdio.h>
   566 #include <string.h>
   567 #include <net/if.h>
   568 
   569 int main()
   570 	{
   571 	struct ifreq ifReq;
   572 	int ret;
   573 	unsigned int snapId = /* Get the SNAP id to be set from the application settings */
   574 	
   575 	/* Set the default interface using SNAP id */
   576 	
   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;
   580 	
   581 	ret = setdefaultif( &ifReq );
   582 	if( ret == -1 )
   583 		printf( "Setting default interface failed with errno = %d", errno );
   584 	
   585 	/* Perform network operations */
   586 	/* ... */
   587 	
   588 	/* Remove the default interface */
   589 	ret = setdefaultif( NULL );
   590 	if( ret == -1 )
   591 		printf( "Removing default interface failed with errno = %d", errno );
   592 	
   593 	return 0;
   594 	}
   595 @endcode 
   596 
   597 The setdefaultif is not guaranteed to be thread safe.
   598 
   599 @publishedAll
   600 @released
   601 */