Go to the previous, next section.

ioctl

SYNOPSIS

int ioctl(int d, int cmd, ...);

The third argument is called char *argp.

PARAMETERS

d: [in] the file descriptor of the file to manipulate.

cmd: [in] the type of request.

argp: depends on the request.

DESCRIPTION

Controls the io parameters of character special devices (tty, mt, etc.). The values that cmd may take for file operations are:

FIOCLEX
Sets the close-on-exec flag of the file.

FIONCLEX
Clears the close-on-exec flag of the file.

FIONBIO
If argp is true, sets the file O_NONBLOCK flag, otherwise it clears the flag.

FIOASYNC
If argp is true, sets the file O_SYNC flag, otherwise it clears the flag. (This flag is not used as of Linux 1.0.)

FIONREAD
Returns to a buffer pointed to by argp, the number of bytes immediately readable from the file.

FIOSETOWN
Sets the owner of the file to argp (a pid). The owner is the one that receives the SIGURG and SIGIO signals. (Only for sockets.)

FIOGETOWN
Returns the owner of the file to a buffer pointed to by argp. (Only for sockets.)

FIGETBSZ
Returns the block size of the file to a buffer pointed to by argp. (Seems non-standard.)

FIBMAP
Returns the block number in the fs corresponding to the argp'th block in the file. (I have guessed right? Anyway, this is non-standard.)
The values for magnetic tape operations are:

MTIOCTOP
Perform an operation on a magnetic tape. argp is a pointer to a mtop structure.

MTIOCGET
Get magnetic tape status. argp is a pointer to a mtget structure.

MTIOCPOS
Set magnetic tape position. argp points to a long integer specifying the block number to go to.

The section on magnetic tapes will remain incomplete for a while... I don't have a clue how it is supposed to work.

The values for sockets operations are:

SIOCSPGRP
Same as FIOSETOWN.

SIOCGPGRP
Same as FIOGETOWN.

SIOCATMARK
Not supported.

SIOCADDRT
Adds a routing entry in the routing table of the system. The task must have superuser privileges to perform that operation. argp points to a rtentry structure.

SIOCDELRT
Removes a routing entry from the routing table of the system. The task must have superuser privileges to perform that operation. argp points to a rtentry structure.

SIOCADDRTOLD
Same as SIOCADDRT but uses an old_rtentry structure. Obsolete. Do not use.

SIOCDELRTOLD
Same as SIOCDELRT but uses an old_rtentry structure. Obsolete. Do not use.

SIOCDARP
Deletes an ARP entry. The calling task must have superuser privileges. argp points to an arpreq structure.

SIOCGARP
Retreive an ARP entry. The calling task must have superuser privileges. argp points to an arpreq structure.

SIOCSARP
Sets an ARP entry. The calling task must have superuser privileges. argp points to an arpreq structure.

IP_SET_DEV
Not supported.

SIOCGIFCONF
Reteives the network interface configuration list in a ifconf structure.

SIOCGIFFLAGS
Gets the interface flags. argp points to an ifreq structure.

SIOCSIFFLAGS
Sets the interface flags. argp points to an ifreq structure. The calling task must have superuser privileges.

SIOCGIFADDR
Gets the interface address. argp points to an ifreq structure.

SIOCSIFADDR
Sets the interface address. argp points to an ifreq structure. The calling task must have superuser privileges.

SIOCGIFDSTADDR
Gets the interface remote address. argp points to an ifreq structure.

SIOCSIFDSTADDR
Sets the interface remote address. argp points to an ifreq structure. The calling task must have superuser privileges.

SIOCGIFBRDADDR
Gets the interface broadcast address. argp points to an ifreq structure.

SIOCSIFBRDADDR
Sets the interface broadcast address. argp points to an ifreq structure. The calling task must have superuser privileges.

SIOCGIFNETMASK
Gets the interface network mask. argp points to an ifreq structure.

SIOCSIFNETMASK
Sets the interface network mask. argp points to an ifreq structure. The calling task must have superuser privileges.

SIOCGIFMETRIC
Gets the interface routing metric. argp points to an ifreq structure.

SIOCSIFMETRIC
Sets the interface routing metric. argp points to an ifreq structure. The calling task must have superuser privileges.

SIOCGIFMEM or SIOCSIFMEM
Not supported.

SIOCGIFMTU
Gets the interface maximum transmission unit. argp points to an ifreq structure.

SIOCSIFMTU
Sets the interface maximum transmission unit. argp points to an ifreq structure. The calling task must have superuser privileges.

SIOCSIFLINK
Links in an I/O driver into the operating system kernel.

SIOCGIFHWADDR
Gets the interface hardware address. argp points to an ifreq structure.

SIOCSIFHWADDR
Not supported.

SIOCGIFNAME
Not supported.

DDIOCSDBG:
Set the DDI debug level.

struct rtentry {
        unsigned long   rt_hash;        /* hash key for lookups         */
        struct sockaddr rt_dst;         /* target address               */
        struct sockaddr rt_gateway;     /* gateway addr (RTF_GATEWAY)   */
        struct sockaddr rt_genmask;     /* target network mask (IP)     */
        short           rt_flags;
        short           rt_refcnt;
        unsigned long   rt_use;
        struct ifnet    *rt_ifp;
        short           rt_metric;      /* +1 for binary compatibility! */
        char            *rt_dev;        /* forcing the device at add    */
};

struct old_rtentry {
        unsigned long   rt_genmask;
        struct sockaddr rt_dst;
        struct sockaddr rt_gateway;
        short           rt_flags;
        short           rt_refcnt;
        unsigned long   rt_use;
        char            *rt_dev; 
};

rt_flags is a or'ed combinaison of one or more of the following:

RTF_UP
the route is usable.

RTF_GATEWAY
the destination is a gateway.

RTF_HOST
the entry is a host. (If this flag is not set, the entry is a net.)

struct arpreq {
  struct sockaddr       arp_pa;         /* protocol address             */
  struct sockaddr       arp_ha;         /* hardware address             */
  int                   arp_flags;      /* flags                        */
};

The arp_flags member may be one or more or'ed values of the following:

ATF_INUSE
the entry is in use.

ATF_COM
the entry is complete (ha is valid).

ATF_PERM
the entry is permanent.

ATF_PUBL
publish entry.

ATF_USETRAILERS
has requested trailers.

Here is the layout of the ifconf structure used to get the configuration list:

struct ifconf {
        int     ifc_len;                        /* size of buffer       */
        union {
                caddr_t ifcu_buf;
                struct  ifreq *ifcu_req;
        } ifc_ifcu;
};

Here is the layout of the ifreq structure used to send/receive interface data:

struct ifreq {
#define IFHWADDRLEN     6
#define IFNAMSIZ        16
    union {
        char    ifrn_name[IFNAMSIZ];            /* if name, e.g. "en0" */
        char    ifrn_hwaddr[IFHWADDRLEN];
    } ifr_ifrn;
    union {
        struct  sockaddr ifru_addr;
        struct  sockaddr ifru_dstaddr;
        struct  sockaddr ifru_broadaddr;
        struct  sockaddr ifru_netmask;
        short   ifru_flags;
        int     ifru_metric;
        int     ifru_mtu;
        caddr_t ifru_data;
    } ifr_ifru;
};

For terminal I/O, the following commands may be used:

TCGETS
Gets the termios structure associated with the terminal. argp points to a termios structure.

TCSETS
Sets the termios structure associated with the terminal. The change is immediate. argp points to a termios structure.

TCSETSW
Same as TCSETS but wait until the output buffer is empty before performing the change.

TCSETSF
Same as TCSETS but wait until the output buffer is empty and flushes the input buffer before performing the change.

TCGETA
Gets the termio structure associated with the terminal. argp points to a termio structure.

TCSETS
Sets the termio structure associated with the terminal. The change is immediate. argp points to a termio structure.

TCSETAW
Same as TCSETA but wait until the output buffer is empty before performing the change.

TCSETAF
Same as TCSETA but wait until the output buffer is empty and flushes the input buffer before performing the change.

TCXONC
Starts or stops the tty flow. argp may be one of the following:

TCOOFF
Stops output.

TCOON
Restart output.

TCIOFF
Stops input.

TCION
Restart input.

TCFLSH
Flushes the tty. argp may be TCIFLUSH to flush the input, TCOFLUSH to flush the output or TCIOFLUSH to flush both.

TIOCEXCL
Sets the tty in exclusive mode. No further open operations on the terminal are permited.

TIOCNXCL
Disable exclusive mode. open operations are now permitted.

TIOCSCTTY
Sets that termial as the controlling terminal of the current task. The calling task must be a session leader and not have a controlling tty already. If the task does not have superuser privileges, normal authorisations checks are performed. If the task has superuser privileges and argp is set to 1, the terminal will be set as the controling terminal even if it was already the controling terminal of another task.

TIOCGPGRP
Gets the process group id associated with this terminal. argp points to an integer that is set to that id.

TIOCSPGRP
Associate the terminal to the process group which has an id equals to argp. The processes of the process group must have the same real or saved uid of as the effective or save uid of the calling task, or be descendants of the calling process or the calling process must have superuser privileges.

TIOCOUTQ
Sets an integer pointed to by argp to the number of bytes in the output queue that are not sent.

TIOCSTI
Insert the value of argp into the input queue of the terminal.

TIOCGWINSZ
Returns the window size into a winsize structure pointed to by argp.

TIOCSWINSZ
Sets the window size to the winsize structure pointed to by argp.

TIOCCONS
Controls the redirection of the console. If fd is a console, the redirection is cancelled. If fd is a pseudo console slave, the console is redirected to that slave. If fd is a pseudo console master, the console is redirected to its slave. The calling taks must be have superuser privileges.

TIOCNOTTY
Dissociate the controling terminal from the current task. The calling task must be process leader.

TIOCGETD
Retreives the terminal current line discipline mode. The value is store to the area pointed to by argp.

TIOCSETD
Sets the terminal line discipline mode to the value of argp.

TIOCGLCKTRMIOS
Gets the locking status of the termios structure of the terminal. argp points to a termios structure.

TIOCSLCKTRMIOS
Sets the locking status of the termios structure of the terminal. argp points to a termios structure that contains the new flags. The calling task must have superuser privileges.

TIOCPKT
If argp is 1, it sets the packet flag in the tty structure, otherwise it sets the flag to zero. (What purpose does that serves?)

TIOCLINUX
Linux dependent.

TCSBRK
Waits for the output queue to become empty, then, if argp is 1, sends a break.

TCSBRKP
Same as TCSBRK?

RETURN VALUE

On success zero is returned. On error, -1 is returned and errno is set to one of the following values:

Go to the previous, next section.