Symbian
Symbian Developer Library

SYMBIAN OS V9.4

Feedback

[Index] [Previous] [Next]

#include <if.h>
Link against: libc.lib

IF_NAMESIZE

Interface status: externallyDefinedApi

IF_NAMESIZE 50

Description

Length of interface external name, including terminating '\0'. 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, you can go upto 24 characters for 2-byte and 16 characters for 3-byte representations. All lengths are excluding the terminal NULL character.

[Top]


if_freenameindex(struct if_nameindex *)

Interface status: externallyDefinedApi

IMPORT_C void if_freenameindex(struct if_nameindex *);

Description

Parameters

struct if_nameindexif_nameindex *

Refer to if_nametoindex(const char *)if_nametoindex(const char *) for the documentation

[Top]


if_indextoname(unsigned,char *)

Interface status: externallyDefinedApi

IMPORT_C char* if_indextoname(unsigned int, char *);

Description

Parameters

unsigned int

char *

Refer to if_nametoindex(const char *)if_nametoindex(const char *) for the documentation

Return value

char *

[Top]


if_nameindex(void)

Interface status: externallyDefinedApi

IMPORT_C struct if_nameindex* if_nameindex(void);

Description

Refer to if_nametoindex(const char *)if_nametoindex(const char *) for the documentation

Return value

struct if_nameindexif_nameindex *

[Top]


if_nametoindex(const char *)

Interface status: externallyDefinedApi

IMPORT_C unsigned int if_nametoindex(const char *);

Description

The if_nametoindex function maps the interface name specified in ifname to its corresponding index. If the specified interface does not exist, it returns 0.

The if_indextoname function maps the interface index specified in ifindex to it corresponding name, which is copied into the buffer pointed to by ifname, which must be of at least IFNAMSIZ bytes. This pointer is also the return value of the function. If there is no interface corresponding to the specified index, NULL is returned.

 The if_nameindex function returns an array of if_nameindex structures, one structure per interface, as defined in the include 
  file #include <net/if.h>; 
  The if_nameindex structure contains at least the following entries: 
  unsigned int   if_index;  /* 1, 2, ... */
    char          *if_name;   /* null terminated name: "le0", ... */

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.

The if_freenameindex function frees the dynamic memory that was allocated by if_nameindexif_nameindex.

Parameters

const char *

Note: This description also covers the following functions - if_indextoname(unsigned,char *)if_indextoname(unsigned,char *) if_nameindex(void)if_nameindex(void) if_freenameindex(struct if_nameindex *)if_freenameindex(struct if_nameindex *)

Return value

unsigned int

Upon successful completion, if_nametoindex returns the index number of the interface. 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_nameindexif_nameindex returns a NULL pointer if sufficient memory cannot be allocated.

[Top]


setdefaultif(const struct ifreq *)

IMPORT_C int setdefaultif(const struct ifreq *);

Description

The setdefaultif function can be used to set (or remove) a default network interface for the application. This default interface, if set, will be used by all the further socket related function calls (connect, send, write etc) and all the host resolver function calls (getaddrinfo, getnameinfo, gethostbyname, getaddrbyname etc).

If there is a default interface set using setdefaultif and if there is a separate interface set on a socket using the ioctl system call, network operations on that socket will not use the default one, but the socket specific interface.

To remove the default interace, pass NULL as the argument.

Example:

#include <stdio.h>
#include <string.h>
#include <net/if.h>

int main()
    {
    struct ifreq ifReq;
    int ret;
    
    /* Set the default interface */
    strcpy( ifReq.ifr_name, "Example Interface Name" );
    ret = setdefaultif( &ifReq );
    if( ret == -1 )
        printf( "Setting default interface failed with errno = %d", errno );
    
    /* Perform network operations */
    /* ... */
    
    /* Remove the default interface */
    ret = setdefaultif( NULL );
    if( ret == -1 )
        printf( "Removing default interface failed with errno = %d", errno );
    
    return 0;
    }

The setdefaultif is not guaranteed to be thread safe.

Parameters

const struct ifreqifreq *

Return value

int

The setdefaultif returns 0 on success and -1 on failure. Specifically, if the interface is not found, -1 is returned and errno is set to ENOENT.