Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

soc_ioctl() (ioctl) - control sockets

&pagelevel(3)&pagelevel



#include <sys.socket.h>
#include <ioctl.h>
#include <net.if.h>

Kernighan-Ritchie-C:
int soc_ioctl(s, request, argp);

int s;
unsigned long request;
char *argp;

ANSI-C:
int soc_ioctl(int s, unsigned long request, char* argp);


Description

The soc_ioctl() function executes control functions for sockets.
s designates the socket descriptor.

The following control functions are supported for sockets in the AF_INET address family:

request

*arg

Function

FIONBIO

int

Enable/disable blocking mode

FIONREAD

int

Get message length in buffer

SIOCGIFCONF

struct ifconf

Get interface configuration

SIOCGIFADDR

struct ifreq

Get Internet address of interface

SIOCGIFBRDADDR

struct ifreq

Get interface broadcast address

SIOCGIFFLAGS

struct ifreq

Get interface flags

SIOCGIFNETMASK

struct ifreq

Determine net mask for the interface

SIOCGLIFADDR

struct lifreq

Determine interface address

SIOCGLIFBRDADDR

struct lifreq

Determine broadcast address of the interface

SIOCGLIFCONF

struct lifconf

Output interface configuration list

SIOCGLIFFLAGS

struct lifreq

Determine interface flags

SIOCGLIFHWADDR

struct lifreq

Determine MAC address for the interface

SIOCGLIFINDEX

struct lifreq

Determine interface index

SIOCGLIFNETMASK

struct lifreq

Determine net mask for the interface

SIOCGLIFNUM

struct lifnum

Determine number of interfaces

SIOCGLAHCONF

struct lvhost

Output list of all active hosts

SIOCGLVHCONF

struct lvhost

Output list of active virtual hosts

SIOCGLVHNUM

int

Determine number of active virtual hosts

The following control functions are supported for sockets in the AF_INET6 address family:

request

*argp

Function

FIONBIO

int

Enable/disable blocking mode

FIONREAD

int

Get message length in buffer

SIOCGLIFADDR

struct lifreq

Determine interface address

SIOCGLIFBRDADDR

struct lifreq

Determine broadcast address of the interface

SIOCGLIFCONF

struct lifconf

Output interface configuration list

SIOCGLIFFLAGS

struct lifreq

Determine interface flags

SIOCGLIFHWADDR

struct lifreq

Output MAC address for the interface

SIOCGLIFINDEX

struct lifreq

Determine interface index

SIOCGLIFNETMASK

struct lifreq

Determine MAC address for the interface

SIOCGLIFNUM

struct lifnum

Determine number of interfaces

SIOCGLAHCONF

struct lvhost

Output list of all active hosts

SIOCGLVHCONF

struct lvhost

Output list of active virtual hosts

SIOCGLVHNUM

int

Determine number of active virtual hosts

The following control functions are supported for sockets in the AF_ISO address family:

request

*argp

Function

FIONBIO

int

Enable/disable blocking mode

The following control functions can be used without socket (s = 0):

request

*argp

Funktion

SIOCGBCPROC

struct ifproc

Returns the BCAM processor name to an FQDN

SIOCGBCFQDN

struct ifproc

Returns the FQDN to a BCAM processor name


FIONBIO

This option affects the execution behavior of socket functions on socket s with data flow control enabled and for actions of the communications partner that have not yet been completed.

  • *argp = 0:
    Socket functions block until the function can be executed.

  • *argp != 0:
    Socket functions return with the errno code EWOULDBLOCK if the function cannot be executed immediately. The select() or soc_poll() function can be used to determine which sockets are ready for reading or writing.
    Default case: FIONBIO is not set.

FIONREAD

Returns the length of the message currently in the input buffer (in bytes).

SIOCGIFCONF

An output list is created in the form of non-concatenated elements of the type struct ifreq (see SIOCGIFADDR option). The caller provides the corresponding memory area for this list by entering the start address and the length in the relevant fields of the ifconf structure.
Only as many elements of the type struct ifreq are output as fit into the buffer made available.

These interfaces belong to a host, normally to the standard host. If virtual hosts are also configured, you can receive the corresponding interfaces in the following way:

  • If the application is started under an ID relocated to a virtual host by an entry in the BCAM application table, the information about this virtual host is output.

  • The setsockopt() subfunction SO_VHOSTANY can be used to select, before calling soc_ioctl(), the host for which information is to be output.
    The ifconf structure is declared in <net.if.h> as follows:

    struct  ifconf {
            int             ifc_len;
            union {
                    caddr_t ifcu_buf;
                    struct  ifreq *ifcu_req;
            } ifc_ifcu;
    #define ifc_buf ifc_ifcu.ifcu_buf
    #define ifc_req ifc_ifcu.ifcu_req
    };
    

SIOCGIFADDR

Returns the Internet address for the interface specified in the ifreq structure with the interface name ifr_name.

The ifreq structure is declared in <net.if.h> as follows:


struct ifreq {
#define IFNAMSIZ     16
   char ifr_name[IFNAMSIZ];      /* Interfacename z.B. IF000003" */
   union {
       struct sockaddr ifru_addr;
       struct sockaddr ifru_dstaddr;
       struct sockaddr ifru_broadaddr;
       short ifru_flags;
       int ifru_metric;
       caddr_t ifru_data; 
    } ifr_ifru;
#define ifr_addr      ifr_ifru.ifru_addr      /* address */
#define ifr_dstaddr   ifr_ifru.ifru_dstaddr   /* dest. addr. of conn, */
#define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
#define ifr_flags     ifr_ifru.ifru_flags     /* flags */
#define ifr_metric    ifr_ifru.ifru_metric    /* metric */

#define ifr_data      ifr_ifru.ifru_data      /* for use by interface */
};

Note that SOCKETS(BS2000) only returns information on one interface at present. 

SIOCGIFBRDADDR

Returns the broadcast address specified for the interface in the ifreq structure (see SIOCGIFADDR option) when an IPv4 interface is concerned and when the IFF_BROADCAST flag is set. This is normally not the case because no broadcast can be generated with socket language means and transport system support. 

SIOCGIFFLAGS

Returns the interface flags in the ifr_flags element for the interface name specified in the struct ifreq:

  • IFF_UP - if the interface is active

  • IFF_BROADCAST - if broadcast messages can be sent via this interface

  • IFF_MULTICAST - if multicast messages can be sent via this interface

  • IFF_LOOPBACK - if messages can be sent to loopback via this interface

  • IFF_CONTROLLAN - if communication with the CONTROLLAN is possible via this interface

SIOCGIFNETMASK

Outputs the subnet mask in the form of bits of the network share of the subnet mask set to “1” (e.g. “FFFFFF00”) in the ifr_addr element for the IPv4 interface specified in the ifreq structure.

SIOCGLIFADDR

Returns the interface address for the name specified in struct lifreq. The lifreq structure is an ifreq structure enhanced particularly with respect to IPv6.

SIOCGLIFBRDADDR

Returns the broadcast address for the interface specified in the lfreq structure when the IFF_BROADCAST flag is set for this interface. This is normally not the case because no broadcast can be generated with socket language means and transport system support.
Separate subfunctions under getsockopt() / setsockopt() are provided for the use of MULTICAST (see section "getsockopt(), setsockopt() - get and set socket options").

SIOCGLIFCONF

An output list is created in the form of non-concatenated elements of the type struct li-freq. The caller provides the corresponding memory area for this list by entering the start address and the length in the relevant fields of the lifconf structure.
Only as many elements of the type struct lifreq are output as fit into the buffer made available. The output can be filtered by means of the assignments of the lifc_family and lifc_flags elements.
Values for lifc_family: AF_INET, AF_INET6, AF_UNSPEC
Values for lifc_flags: see SIOCGLIFFLAGS

These interfaces belong to a host, normally to the standard host. If virtual hosts are configured, you can receive the corresponding interfaces in the following way:

  • If the application is started under an ID relocated to a virtual host by an entry in the BCAM application table, the information is output about this virtual host.

  • The setsockopt() subfunction SO_VHOSTANY can be used to select, before calling soc_ioctl(), the host for which information is to be output. 
    The lifconf structure is declared in <net.if.h> as follows:

    struct  lifconf {
            sa_family_t     lifc_family;
            int             lifc_flags;
            int             lifc_len;
            union {
                    caddr_t lifcu_buf;
                    struct  lifreq *lifcu_req;
            } lifc_lifcu;
    #define lifc_buf lifc_lifcu.lifcu_buf
    #define lifc_req lifc_lifcu.lifcu_req
    };
    

SIOCGLIFFLAGS

Returns the interface flags in the lifr_flags element for the interface name specified in the lifreq structure:

  • IFF_UP - if the interface is active

  • IFF_BROADCAST - if broadcast messages can be sent via this interface

  • IFF_MULTICAST - if multicast messages can be sent via this interface

  • IFF_LOOPBACK - if messages can be sent to loopback via this interface

  • IFF_CONTROLLAN - if communication with the CONTROLLAN is possible via this interface

  • IFF_AUTOCONFIG - if this interface was supplied with an address generated by IPv6 autoconfig. This also includes the IPv6 link local address with the prefix FE80::/10 created locally in the host.

SIOCGLIFHWADDR

Outputs the MAC address for the interface name specified in the lifreq structure.

SIOCGLIFINDEX

Outputs the index for the interface name specified in lifreq structure.

SIOCGLIFNETMASK

Outputs the the subnet mask in the lifr_addr element and the prefix length in bits in the ifr_addrlen element for the interface name lifr_name specified in the lifreq structure. When an IPv4 interface is involved, the output takes place in the form of all bits concerned of the network share being set to “1” (e.g. “FFFFFF00”). When an IPv6 interface is involved, the network share is output as the original address and the following bits are then set to “0” (e.g. “FD11F052433485AA000000000000”).

SIOCGLIFNUM

Outputs the number of interfaces for the address family specified in the lifnum structure.

SIOCGLAHCONF

A non-concatenated list containing elements of the type struct lvhost is returned. These contain the socket host name, the BCAM host name, the host number and an active flag of the real host and, if present, also of virtual hosts. The user must transfer the memory space for this list in *argp with the type struct lvhost. The length must be entered in the lvhostlen field.
If information on all hosts is to be output, a memory space of n x sizeof(struct lvhost) is required, where n is the maximum possible number of active hosts.
The return information can be accessed by direct addressing or using indexes. The number of returned list elements of the type struct lvhost is entered in the vhostsum field of the first element. In the last list element, the vhostlast field is flagged with “1”.
If the memory space provided is not large enough, the vhostlast field in the last list element is flagged with “1”.

SIOCGLVHCONF

A non-concatenated list containing elements of the type struct lvhost is returned, which in contrast to SIOCGLAHCONF contains only the information about the virtual hosts. The user must pass the memory space for this list with *argp of the type struct lvhost. The length must be entered in the field lvhostlen. If information on all virtual hosts is to be output, a memory space of n x sizeof(struct lvhost) is required, where n is the return value from SIOCGLVHNUM.

The return information can be accessed by direct addressing or using indexes. The number of returned list elements of the type struct lvhost is entered in the field vhostsum. In the last list element, the vhostlast field is flagged with "1".

The structure lvhost is declared in <net.if.h> as follows:


struct  lvhost { 
       int             lvhostlen;    /* length of memory for lvhostlist */
       unsigned short  vhostsum;     /* number of vhosts delivered      */
       unsigned short  vhostlast;    /* last element if not zero        */
       int             vhost_num;    /* vhost number, must be greater 1 */
       short           vhost_flag;   /* vhost active ?                  */
       char            vsockethost[33];  /* sockethostname of vhost     */
       char            vbcamhost[9]; /* bcamhostname of vhost           */
};


SIOCGLVHNUM

Returns the number of active virtual hosts.

The structure lifreq is declared as follows in <net.if.h>:

struct  lifreq {
#define LIFNAMSIZ 32
        char                             lifr_name[LIFNAMSIZ];
        union {
                int                      lifru_addrlen;
                unsigned int             lifru_ppa;
        } lifr_lifru1;
#define lifr_addrlen    lifr_lifru1.lifru_addrlen
#define lifr_ppa        lifr_lifru1.lifru_ppa
        unsigned int                     lifr_movetoindex;
        union {
                struct sockaddr_storage  lifru_addr;
                struct sockaddr_storage  lifru_dstaddr;
                struct sockaddr_storage  lifru_broadaddr;
                struct sockaddr_storage  lifru_token;
                struct sockaddr_storage  lifru_subnet;
                struct sockaddr          lifru_hwaddr;
                int                      lifru_index;
        union {
                unsigned int             lifru_flags_0,lifru_flags_1;
                u_int64_t                lifru_flags;
        } lifr_lifruflags;
                int                      lifru_metric;
                unsigned int             lifru_mtu;
                char                     lifru_data[1];
                char                     lifru_enaddr[6];
                int                      lif_muxid[2];
                struct lif_nd_req        lifru_nd_req;
                struct lif_ifinfo_req    lifru_ifinfo_req;
                char                     lifru_groupname[LIFNAMSIZ];
                unsigned int             lifru_delay;
        } lifr_lifru;

#define  lifr_addr       lifr_lifru.lifru_addr
#define  lifr_dstaddr    lifr_lifru.lifru_dstaddr
#define  lifr_broadaddr  lifr_lifru.lifru_broadaddr
#define  lifr_token      lifr_lifru.lifru_token
#define  lifr_subnet     lifr_lifru.lifru_subnet
#define  lifr_index      lifr_lifru.lifru_index
#define  lifr_flags      lifr_lifru.lifr_lifruflags.lifru_flags
#define  lifr_flags_l    lifr_lifru.lifr_lifruflags.lifru_flags_1
#define  lifr_flags_h    lifr_lifru.lifr_lifruflags.lifru_flags_0
#define  lifr_metric     lifr_lifru.lifru_metric
#define  lifr_mtu        lifr_lifru.lifru_mtu
#define  lifr_data       lifr_lifru.lifru_data
#define  lifr_enaddr     lifr_lifru.lifru_enaddr
#define  lifr_index      lifr_lifru.lifru_index
#define  lifr_ip_muxid   lifr_lifru.lif_muxid[0]
#define  lifr_nd         lifr_lifru.lifru_nd_req
#define  lifr_ifinfo     lifr_lifru.lifru_ifinfo_req
#define  lifr_groupname  lifr_lifru.lifru_groupname
#define  lifr_delay      lifr_lifru.lifru_delay
#define  lifr_hwaddr      lifr_lifru.lifru.lifru_hwaddr
};

The structure sockaddr_storage is declared as follows in <sys.socket.h>:

#define _SS_MAXSIZE     128         /* Implementation specific max size */
#define _PADSIZE        (_SS_MAXSIZE - (sizeof(u_int64_t) + 8 ))
struct sockaddr_storage {
        sa_family_t     ss_family;         /* address family */
#define __ss_family     ss_family
        char            res[6];            /* reserved for alignment */
        u_int64_t       addr;              /* address */
        char            pad[_PADSIZE];     /* pad up to max size */
};

The structure lifconf is declared as follows in <net.if.h>:

struct  lifconf {
        sa_family_t     lifc_family;
        int             lifc_flags;
        int             lifc_len;
        union {
                caddr_t lifcu_buf;
                struct  lifreq *lifcu_req;
        } lifc_lifcu;
#define lifc_buf lifc_lifcu.lifcu_buf
#define lifc_req lifc_lifcu.lifcu_req
};

The structure lifnum is declared as follows in <net.if.h>:

struct lifnum {
        sa_family_t     lifn_family;
        int             lifn_flags;
        int             lifn_count;
};


SIOCGBCPROC

The caller has to pass the ifproc structure's fields *fqdn and fqdnlen to the program. Pointer *fqdn has to be supplied as a char array which contains the FQDN (Fully Qualified Domain Name) to be checked. The length of this FQDN has to be inserted in the fqdnlen field. After the function call the BCAM processor name belonging to the FQDN is written to the field bcproc[] with the string null termination (‘\0‘). 

If there is no BCAM processor name to this FQDN, a negative return value is returned. This also applies, if there is a processor name assigned to this FQDN in the FQDN file, but the corresponding processor/route has not been created.
An IP address must be converted into an FQDN beforehand (see getnameinfo() function).
The socket descriptor is neither needed nor evaluated for this function.

The structure ifproc is declared as follows in <net.if.h>:

struct ifproc {
         char            *fqdn;     /* FQDN (Fully Qualified Domain Name) */
         int             fqdnlen;   /* length of the FQDN                 */
         char            bcproc[9]; /* space for BCAM processor name      */
};


SIOCGBCFQDN

The caller must provide a char array for *fqdn and enter the length of this array in the fqdnlen field. In addition, the BCAM processor name must be recorded into the bcproc[] field. After calling this function the FQDN (Fully Qualified Domain Name) associated with the BCAM processor name is written to the field to which *fqdn refers with the string null termination ('\0‘). If fqdnlen is smaller than the length of the FQDN, an error will be set and no FQDN will be returned. An error will also be set, if the specified BCAM processor name does not exist or if there is no FQDN for this processor name. In this case length 0 will be written to fqdnlen.

The socket descriptor is neither needed nor evaluated for this function.

Return value

-1:

If errors occur. errno is set to indicate the error.

Errors indicated by errno

EBADF

The s parameter is not a valid descriptor.

EINVAL

request or arg are not valid for this device (interface, socket).