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