Go to the previous, next section.
int ioctl(int d, int cmd, ...);
The third argument is called char *argp.
d: [in] the file descriptor of the file to manipulate.
cmd: [in] the type of request.
argp: depends on the request.
Controls the io parameters of character special devices (tty, mt, etc.). The values that cmd may take for file operations are:
FIOCLEX
FIONCLEX
FIONBIO
O_NONBLOCK flag,
otherwise it clears the flag.
FIOASYNC
O_SYNC flag,
otherwise it clears the flag. (This flag is not used as of Linux 1.0.)
FIONREAD
FIOSETOWN
SIGURG and SIGIO signals.
(Only for sockets.)
FIOGETOWN
FIGETBSZ
FIBMAP
MTIOCTOP
mtop structure.
MTIOCGET
mtget structure.
MTIOCPOS
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
FIOSETOWN.
SIOCGPGRP
FIOGETOWN.
SIOCATMARK
SIOCADDRT
rtentry structure.
SIOCDELRT
rtentry structure.
SIOCADDRTOLD
SIOCADDRT but uses an old_rtentry
structure. Obsolete. Do not use.
SIOCDELRTOLD
SIOCDELRT but uses an old_rtentry
structure. Obsolete. Do not use.
SIOCDARP
arpreq structure.
SIOCGARP
arpreq structure.
SIOCSARP
arpreq structure.
IP_SET_DEV
SIOCGIFCONF
ifconf
structure.
SIOCGIFFLAGS
ifreq
structure.
SIOCSIFFLAGS
ifreq
structure. The calling task must have superuser privileges.
SIOCGIFADDR
ifreq structure.
SIOCSIFADDR
ifreq structure. The calling task must have superuser privileges.
SIOCGIFDSTADDR
ifreq structure.
SIOCSIFDSTADDR
ifreq structure. The calling task must have superuser privileges.
SIOCGIFBRDADDR
ifreq structure.
SIOCSIFBRDADDR
ifreq structure. The calling task must have superuser privileges.
SIOCGIFNETMASK
ifreq structure.
SIOCSIFNETMASK
ifreq structure. The calling task must have superuser privileges.
SIOCGIFMETRIC
ifreq structure.
SIOCSIFMETRIC
ifreq structure. The calling task must have superuser privileges.
SIOCGIFMEM or SIOCSIFMEM
SIOCGIFMTU
ifreq structure.
SIOCSIFMTU
ifreq structure. The calling task must have superuser privileges.
SIOCSIFLINK
SIOCGIFHWADDR
ifreq structure.
SIOCSIFHWADDR
SIOCGIFNAME
DDIOCSDBG:
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
RTF_GATEWAY
RTF_HOST
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
ATF_COM
ATF_PERM
ATF_PUBL
ATF_USETRAILERS
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
termios structure associated with the terminal.
argp points to a termios structure.
TCSETS
termios structure associated with the terminal. The
change is immediate. argp points to a termios
structure.
TCSETSW
TCSETS but wait until the output buffer is empty
before performing the change.
TCSETSF
TCSETS but wait until the output buffer is empty and
flushes the input buffer before performing the change.
TCGETA
termio structure associated with the terminal.
argp points to a termio structure.
TCSETS
termio structure associated with the terminal. The
change is immediate. argp points to a termio
structure.
TCSETAW
TCSETA but wait until the output buffer is empty
before performing the change.
TCSETAF
TCSETA but wait until the output buffer is empty and
flushes the input buffer before performing the change.
TCXONC
TCOOFF
TCOON
TCIOFF
TCION
TCFLSH
TCIFLUSH to flush the
input, TCOFLUSH to flush the output or TCIOFLUSH to
flush both.
TIOCEXCL
open operations on
the terminal are permited.
TIOCNXCL
open operations are now permitted.
TIOCSCTTY
TIOCGPGRP
TIOCSPGRP
TIOCOUTQ
TIOCSTI
TIOCGWINSZ
winsize structure pointed to
by argp.
TIOCSWINSZ
winsize structure pointed to by
argp.
TIOCCONS
TIOCNOTTY
TIOCGETD
TIOCSETD
TIOCGLCKTRMIOS
termios structure of the
terminal. argp points to a termios structure.
TIOCSLCKTRMIOS
termios structure of the
terminal. argp points to a termios structure that
contains the new flags. The calling task must have superuser privileges.
TIOCPKT
packet flag in the tty
structure, otherwise it sets the flag to zero. (What purpose does that
serves?)
TIOCLINUX
TCSBRK
TCSBRKP
TCSBRK?
On success zero is returned. On error, -1 is returned and errno
is set to one of the following values:
EINVAL: cmd or argp have an invalid
value.
ENOTTY: d is not a character special device or the
request made on d is not valid for this type of device.
EBADF.