inode

title: inode(7)

summary: file inode information

text:
# inode(7)

## NAME
inode - file inode information

## DESCRIPTION
Each file has an inode containing metadata about the file. An application can retrieve this metadata using stat(2) (or related calls), which returns a stat structure, or statx(2), which returns a statx structure.

The following is a list of the information typically found in, or associated with, the file inode, with the names of the corresponding structure fields returned by stat(2) and statx(2):

Device where inode resides

stat.st_dev; statx.stx_dev_minor and statx.stx_dev_major

Each inode (as well as the associated file) resides in a filesystem that is hosted on a device. That device is identified by the combination of its major ID (which identifies the general class of device) and minor ID (which identifies a specific instance in the general class).

Inode number

stat.st_ino; statx.stx_ino

Each file in a filesystem has a unique inode number. Inode numbers are guaranteed to be unique only within a filesystem (i.e., the same inode numbers may be used by different filesystems, which is the reason that hard links may not cross filesystem boundaries). This field contains the file's inode number.

File type and mode

stat.st_mode; statx.stx_mode

See the discussion of file type and mode, below.

Link count

stat.st_nlink; statx.stx_nlink

This field contains the number of hard links to the file. Additional links to an existing file are created using link(2).

User ID

st_uid stat.st_uid; statx.stx_uid

This field records the user ID of the owner of the file. For newly created files, the file user ID is the effective user ID of the creating process. The user ID of a file can be changed using chown(2).

Group ID

stat.st_gid; statx.stx_gid

The inode records the ID of the group owner of the file. For newly created files, the file group ID is either the group ID of the parent directory or the effective group ID of the creating process, depending on whether or not the set-group-ID bit is set on the parent directory (see below). The group ID of a file can be changed using chown(2).

Device represented by this inode

stat.st_rdev; statx.stx_rdev_minor and statx.stx_rdev_major

If this file (inode) represents a device, then the inode records the major and minor ID of that device.

File size

stat.st_size; statx.stx_size

This field gives the size of the file (if it is a regular file or a symbolic link) in bytes. The size of a symbolic link is the length of the pathname it contains, without a terminating null byte.

Preferred block size for I/O

stat.st_blksize; statx.stx_blksize

This field gives the "preferred" blocksize for efficient filesystem I/O. (Writing to a file in smaller chunks may cause an inefficient read-modify-rewrite.)

Number of blocks allocated to the file

stat.st_blocks; statx.stx_size

This field indicates the number of blocks allocated to the file, 512-byte units, (This may be smaller than st_size/512 when the file has holes.)

The POSIX.1 standard notes that the unit for the st_blocks member of the stat structure is not defined by the standard. On many implementations it is 512 bytes; on a few systems, a different unit is used, such as 1024. Furthermore, the unit may differ on a per-filesystem basis.

Last access timestamp (atime)

stat.st_atime; statx.stx_atime

This is the file's last access timestamp. It is changed by file accesses, for example, by execve(2), mknod(2), pipe(2), utime(2), and read(2) (of more than zero bytes). Other interfaces, such as mmap(2), may or may not update the atime timestamp

Some filesystem types allow mounting in such a way that file and/or directory accesses do not cause an update of the atime timestamp. (See noatime, nodiratime, and relatime in mount(8), and related information in mount(2).) In addition, the atime timestamp is not updated if a file is opened with the O_NOATIME flag; see open(2).

File creation (birth) timestamp (btime)

(not returned in the stat structure); statx.stx_btime

The file's creation timestamp. This is set on file creation and not changed subsequently.

The btime timestamp was not historically present on UNIX systems and is not currently supported by most Linux filesystems.

Last modification timestamp (mtime)

stat.st_mtime; statx.stx_mtime

This is the file's last modification timestamp. It is changed by file modifications, for example, by mknod(2), truncate(2), utime(2), and write(2) (of more than zero bytes). Moreover, the mtime timestamp of a directory is changed by the creation or deletion of files in that directory. The mtime timestamp is not changed for changes in owner, group, hard link count, or mode.

Last status change timestamp (ctime)

stat.st_ctime; statx.stx_ctime

This is the file's last status change timestamp. It is changed by writing or by setting inode information (i.e., owner, group, link count, mode, etc.).

The timestamp fields report time measured with a zero point at the Epoch, 1970-01-01 00:00:00 +0000, UTC (see time(7)).

Nanosecond timestamps are supported on XFS, JFS, Btrfs, and ext4 (since Linux 2.6.23). Nanosecond timestamps are not supported in ext2, ext3, and Reiserfs. In order to return timestamps with nanosecond precision, the timestamp fields in the stat and statx structures are defined as structures that include a nanosecond component. See stat(2) and statx(2) for details. On filesystems that do not support subsecond timestamps, the nanosecond fields in the stat and statx structures are returned with the value 0.

### The file type and mode
The stat.st_mode field (for statx(2), the statx.stx_mode field) contains the file type and mode.

POSIX refers to the stat.st_mode bits corresponding to the mask S_IFMT (see below) as the file type, the 12 bits corresponding to the mask 07777 as the file mode bits and the least significant 9 bits (0777) as the file permission bits.

The following mask values are defined for the file type:

S_IFMT

0170000

bit mask for the file type bit field

S_IFSOCK

0140000

socket

S_IFLNK

0120000

symbolic link

S_IFREG

0100000

regular file

S_IFBLK

0060000

block device

S_IFDIR

0040000

directory

S_IFCHR

0020000

character device

S_IFIFO

0010000

FIFO

Thus, to test for a regular file (for example), one could write:

```
stat(pathname, &sb);
if ((sb.st_mode & S_IFMT) == S_IFREG) {

    /* Handle regular file */
}
```

Because tests of the above form are common, additional macros are defined by POSIX to allow the test of the file type in st_mode to be written more concisely:

S_ISREG(m)

is it a regular file?

S_ISDIR(m)

directory?

S_ISCHR(m)

character device?

S_ISBLK(m)

block device?

S_ISFIFO(m)

FIFO (named pipe)?

S_ISLNK(m)

symbolic link? (Not in POSIX.1-1996.)

S_ISSOCK(m)

socket? (Not in POSIX.1-1996.)

The preceding code snippet could thus be rewritten as:

```
stat(pathname, &sb);
if (S_ISREG(sb.st_mode)) {

    /* Handle regular file */
}
```

The definitions of most of the above file type test macros are provided if any of the following feature test macros is defined: _BSD_SOURCE (in glibc 2.19 and earlier), _SVID_SOURCE (in glibc 2.19 and earlier), or _DEFAULT_SOURCE (in glibc 2.20 and later). In addition, definitions of all of the above macros except S_IFSOCK and S_ISSOCK() are provided if _XOPEN_SOURCE is defined.

The definition of S_IFSOCK can also be exposed either by defining _XOPEN_SOURCE with a value of 500 or greater or (since glibc 2.24) by defining both _XOPEN_SOURCE and _XOPEN_SOURCE_EXTENDED.

The definition of S_ISSOCK() is exposed if any of the following feature test macros is defined: _BSD_SOURCE (in glibc 2.19 and earlier), _DEFAULT_SOURCE (in glibc 2.20 and later), _XOPEN_SOURCE with a value of 500 or greater, _POSIX_C_SOURCE with a value of 200112L or greater, or (since glibc 2.24) by defining both _XOPEN_SOURCE and _XOPEN_SOURCE_EXTENDED.

The following mask values are defined for the file mode component of the st_mode field:

S_ISUID

04000

set-user-ID bit (see execve(2))

S_ISGID

02000

set-group-ID bit (see below)

S_ISVTX

01000

sticky bit (see below)

S_IRWXU

00700

owner has read, write, and execute permission

S_IRUSR

00400

owner has read permission

S_IWUSR

00200

owner has write permission

S_IXUSR

00100

owner has execute permission

S_IRWXG

00070

group has read, write, and execute permission

S_IRGRP

00040

group has read permission

S_IWGRP

00020

group has write permission

S_IXGRP

00010

group has execute permission

S_IRWXO

00007

others (not in group) have read, write, and execute permission

S_IROTH

00004

others have read permission

S_IWOTH

00002

others have write permission

S_IXOTH

00001

others have execute permission

The set-group-ID bit (S_ISGID) has several special uses. For a directory, it indicates that BSD semantics are to be used for that directory: files created there inherit their group ID from the directory, not from the effective group ID of the creating process, and directories created there will also get the S_ISGID bit set. For an executable file, the set-group-ID bit causes the effective group ID of a process that executes the file to change as described in execve(2). For a file that does not have the group execution bit (S_IXGRP) set, the set-group-ID bit indicates mandatory file/record locking.

The sticky bit (S_ISVTX) on a directory means that a file in that directory can be renamed or deleted only by the owner of the file, by the owner of the directory, and by a privileged process.

## STANDARDS
POSIX.1-2008.

## HISTORY
POSIX.1-2001.

POSIX.1-1990 did not describe the S_IFMT, S_IFSOCK, S_IFLNK, S_IFREG, S_IFBLK, S_IFDIR, S_IFCHR, S_IFIFO, and S_ISVTX constants, but instead specified the use of the macros S_ISDIR() and so on.

The S_ISLNK() and S_ISSOCK() macros were not in POSIX.1-1996; the former is from SVID 4, the latter from SUSv2.

UNIX V7 (and later systems) had S_IREAD, S_IWRITE, S_IEXEC, and where POSIX prescribes the synonyms S_IRUSR, S_IWUSR, and S_IXUSR.

## NOTES
For pseudofiles that are autogenerated by the kernel, the file size (stat.st_size; statx.stx_size) reported by the kernel is not accurate. For example, the value 0 is returned for many files under the /proc directory, while various files under /sys report a size of 4096 bytes, even though the file content is smaller. For such files, one should simply try to read as many bytes as possible (and append '\0' to the returned buffer if it is to be interpreted as a string).

## SEE ALSO
stat(1), stat(2), statx(2), symlink(7)


inotify

package: man-pages

title: inotify(7)

summary: monitoring filesystem events

text:
# inotify(7)

## NAME
inotify - monitoring filesystem events

## DESCRIPTION
The inotify API provides a mechanism for monitoring filesystem events. Inotify can be used to monitor individual files, or to monitor directories. When a directory is monitored, inotify will return events for the directory itself, and for files inside the directory.

The following system calls are used with this API:

•

inotify_init(2) creates an inotify instance and returns a file descriptor referring to the inotify instance. The more recent inotify_init1(2) is like inotify_init(2), but has a flags argument that provides access to some extra functionality.

•

inotify_add_watch(2) manipulates the "watch list" associated with an inotify instance. Each item ("watch") in the watch list specifies the pathname of a file or directory, along with some set of events that the kernel should monitor for the file referred to by that pathname. inotify_add_watch(2) either creates a new watch item, or modifies an existing watch. Each watch has a unique "watch descriptor", an integer returned by inotify_add_watch(2) when the watch is created.

•

When events occur for monitored files and directories, those events are made available to the application as structured data that can be read from the inotify file descriptor using read(2) (see below).

•

inotify_rm_watch(2) removes an item from an inotify watch list.

•

When all file descriptors referring to an inotify instance have been closed (using close(2)), the underlying object and its resources are freed for reuse by the kernel; all associated watches are automatically freed.

With careful programming, an application can use inotify to efficiently monitor and cache the state of a set of filesystem objects. However, robust applications should allow for the fact that bugs in the monitoring logic or races of the kind described below may leave the cache inconsistent with the filesystem state. It is probably wise to do some consistency checking, and rebuild the cache when inconsistencies are detected.

### Reading events from an inotify file descriptor
To determine what events have occurred, an application read(2)s from the inotify file descriptor. If no events have so far occurred, then, assuming a blocking file descriptor, read(2) will block until at least one event occurs (unless interrupted by a signal, in which case the call fails with the error EINTR; see signal(7)).

Each successful read(2) returns a buffer containing one or more of the following structures:

```
struct inotify_event {

    int      wd;       /* Watch descriptor */

    uint32_t mask;     /* Mask describing event */

    uint32_t cookie;   /* Unique cookie associating related

                          events (for rename(2)) */

    uint32_t len;      /* Size of name field */

    char     name[];   /* Optional null-terminated name */
};
```

wd identifies the watch for which this event occurs. It is one of the watch descriptors returned by a previous call to inotify_add_watch(2).

mask contains bits that describe the event that occurred (see below).

cookie is a unique integer that connects related events. Currently, this is used only for rename events, and allows the resulting pair of IN_MOVED_FROM and IN_MOVED_TO events to be connected by the application. For all other event types, cookie is set to 0.

The name field is present only when an event is returned for a file inside a watched directory; it identifies the filename within the watched directory. This filename is null-terminated, and may include further null bytes ('\0') to align subsequent reads to a suitable address boundary.

The len field counts all of the bytes in name, including the null bytes; the length of each inotify_event structure is thus sizeof(struct inotify_event)+len.

The behavior when the buffer given to read(2) is too small to return information about the next event depends on the kernel version: before Linux 2.6.21, read(2) returns 0; since Linux 2.6.21, read(2) fails with the error EINVAL. Specifying a buffer of size

```
sizeof(struct inotify_event) + NAME_MAX + 1
```

will be sufficient to read at least one event.

### inotify events
The inotify_add_watch(2) mask argument and the mask field of the inotify_event structure returned when read(2)ing an inotify file descriptor are both bit masks identifying inotify events. The following bits can be specified in mask when calling inotify_add_watch(2) and may be returned in the mask field returned by read(2):

IN_ACCESS (+)

File was accessed (e.g., read(2), execve(2)).

IN_ATTRIB (*)

Metadata changed—for example, permissions (e.g., chmod(2)), timestamps (e.g., utimensat(2)), extended attributes (setxattr(2)), link count (since Linux 2.6.25; e.g., for the target of link(2) and for unlink(2)), and user/group ID (e.g., chown(2)).

IN_CLOSE_WRITE (+)

File opened for writing was closed.

IN_CLOSE_NOWRITE (*)

File or directory not opened for writing was closed.

IN_CREATE (+)

File/directory created in watched directory (e.g., open(2) O_CREAT, mkdir(2), link(2), symlink(2), bind(2) on a UNIX domain socket).

IN_DELETE (+)

File/directory deleted from watched directory.

IN_DELETE_SELF

Watched file/directory was itself deleted. (This event also occurs if an object is moved to another filesystem, since mv(1) in effect copies the file to the other filesystem and then deletes it from the original filesystem.) In addition, an IN_IGNORED event will subsequently be generated for the watch descriptor.

IN_MODIFY (+)

File was modified (e.g., write(2), truncate(2)).

IN_MOVE_SELF

Watched file/directory was itself moved.

IN_MOVED_FROM (+)

Generated for the directory containing the old filename when a file is renamed.

IN_MOVED_TO (+)

Generated for the directory containing the new filename when a file is renamed.

IN_OPEN (*)

File or directory was opened.

Inotify monitoring is inode-based: when monitoring a file (but not when monitoring the directory containing a file), an event can be generated for activity on any link to the file (in the same or a different directory).

When monitoring a directory:

•

the events marked above with an asterisk (*) can occur both for the directory itself and for objects inside the directory; and

•

the events marked with a plus sign (+) occur only for objects inside the directory (not for the directory itself).

Note: when monitoring a directory, events are not generated for the files inside the directory when the events are performed via a pathname (i.e., a link) that lies outside the monitored directory.

When events are generated for objects inside a watched directory, the name field in the returned inotify_event structure identifies the name of the file within the directory.

The IN_ALL_EVENTS macro is defined as a bit mask of all of the above events. This macro can be used as the mask argument when calling inotify_add_watch(2).

Two additional convenience macros are defined:

IN_MOVE

Equates to IN_MOVED_FROM | IN_MOVED_TO.

IN_CLOSE

Equates to IN_CLOSE_WRITE | IN_CLOSE_NOWRITE.

The following further bits can be specified in mask when calling inotify_add_watch(2):

IN_DONT_FOLLOW (since Linux 2.6.15)

Don't dereference pathname if it is a symbolic link.

IN_EXCL_UNLINK (since Linux 2.6.36)

By default, when watching events on the children of a directory, events are generated for children even after they have been unlinked from the directory. This can result in large numbers of uninteresting events for some applications (e.g., if watching /tmp, in which many applications create temporary files whose names are immediately unlinked). Specifying IN_EXCL_UNLINK changes the default behavior, so that events are not generated for children after they have been unlinked from the watched directory.

IN_MASK_ADD

If a watch instance already exists for the filesystem object corresponding to pathname, add (OR) the events in mask to the watch mask (instead of replacing the mask); the error EINVAL results if IN_MASK_CREATE is also specified.

IN_ONESHOT

Monitor the filesystem object corresponding to pathname for one event, then remove from watch list.

IN_ONLYDIR (since Linux 2.6.15)

Watch pathname only if it is a directory; the error ENOTDIR results if pathname is not a directory. Using this flag provides an application with a race-free way of ensuring that the monitored object is a directory.

IN_MASK_CREATE (since Linux 4.18)

Watch pathname only if it does not already have a watch associated with it; the error EEXIST results if pathname is already being watched.

Using this flag provides an application with a way of ensuring that new watches do not modify existing ones. This is useful because multiple paths may refer to the same inode, and multiple calls to inotify_add_watch(2) without this flag may clobber existing watch masks.

The following bits may be set in the mask field returned by read(2):

IN_IGNORED

Watch was removed explicitly (inotify_rm_watch(2)) or automatically (file was deleted, or filesystem was unmounted). See also BUGS.

IN_ISDIR

Subject of this event is a directory.

IN_Q_OVERFLOW

Event queue overflowed (wd is -1 for this event).

IN_UNMOUNT

Filesystem containing watched object was unmounted. In addition, an IN_IGNORED event will subsequently be generated for the watch descriptor.

### Examples
Suppose an application is watching the directory dir and the file dir/myfile for all events. The examples below show some events that will be generated for these two objects.

fd = open("dir/myfile", O_RDWR);

Generates IN_OPEN events for both dir and dir/myfile.

read(fd, buf, count);

Generates IN_ACCESS events for both dir and dir/myfile.

write(fd, buf, count);

Generates IN_MODIFY events for both dir and dir/myfile.

fchmod(fd, mode);

Generates IN_ATTRIB events for both dir and dir/myfile.

close(fd);

Generates IN_CLOSE_WRITE events for both dir and dir/myfile.

Suppose an application is watching the directories dir1 and dir2, and the file dir1/myfile. The following examples show some events that may be generated.

link("dir1/myfile", "dir2/new");

Generates an IN_ATTRIB event for myfile and an IN_CREATE event for dir2.

rename("dir1/myfile", "dir2/myfile");

Generates an IN_MOVED_FROM event for dir1, an IN_MOVED_TO event for dir2, and an IN_MOVE_SELF event for myfile. The IN_MOVED_FROM and IN_MOVED_TO events will have the same cookie value.

Suppose that dir1/xx and dir2/yy are (the only) links to the same file, and an application is watching dir1, dir2, dir1/xx, and dir2/yy. Executing the following calls in the order given below will generate the following events:

unlink("dir2/yy");

Generates an IN_ATTRIB event for xx (because its link count changes) and an IN_DELETE event for dir2.

unlink("dir1/xx");

Generates IN_ATTRIB, IN_DELETE_SELF, and IN_IGNORED events for xx, and an IN_DELETE event for dir1.

Suppose an application is watching the directory dir and (the empty) directory dir/subdir. The following examples show some events that may be generated.

mkdir("dir/new", mode);

Generates an IN_CREATE | IN_ISDIR event for dir.

rmdir("dir/subdir");

Generates IN_DELETE_SELF and IN_IGNORED events for subdir, and an IN_DELETE | IN_ISDIR event for dir.

### /proc interfaces
The following interfaces can be used to limit the amount of kernel memory consumed by inotify:

/proc/sys/fs/inotify/max_queued_events

The value in this file is used when an application calls inotify_init(2) to set an upper limit on the number of events that can be queued to the corresponding inotify instance. Events in excess of this limit are dropped, but an IN_Q_OVERFLOW event is always generated.

/proc/sys/fs/inotify/max_user_instances

This specifies an upper limit on the number of inotify instances that can be created per real user ID.

/proc/sys/fs/inotify/max_user_watches

This specifies an upper limit on the number of watches that can be created per real user ID.

## STANDARDS
Linux.

## HISTORY
Inotify was merged into Linux 2.6.13. The required library interfaces were added in glibc 2.4. (IN_DONT_FOLLOW, IN_MASK_ADD, and IN_ONLYDIR were added in glibc 2.5.)

## NOTES
Inotify file descriptors can be monitored using select(2), poll(2), and epoll(7). When an event is available, the file descriptor indicates as readable.

Since Linux 2.6.25, signal-driven I/O notification is available for inotify file descriptors; see the discussion of F_SETFL (for setting the O_ASYNC flag), F_SETOWN, and F_SETSIG in fcntl(2). The siginfo_t structure (described in sigaction(2)) that is passed to the signal handler has the following fields set: si_fd is set to the inotify file descriptor number; si_signo is set to the signal number; si_code is set to POLL_IN; and POLLIN is set in si_band.

If successive output inotify events produced on the inotify file descriptor are identical (same wd, mask, cookie, and name), then they are coalesced into a single event if the older event has not yet been read (but see BUGS). This reduces the amount of kernel memory required for the event queue, but also means that an application can't use inotify to reliably count file events.

The events returned by reading from an inotify file descriptor form an ordered queue. Thus, for example, it is guaranteed that when renaming from one directory to another, events will be produced in the correct order on the inotify file descriptor.

The set of watch descriptors that is being monitored via an inotify file descriptor can be viewed via the entry for the inotify file descriptor in the process's /proc/pid/fdinfo directory. See proc(5) for further details. The FIONREAD ioctl(2) returns the number of bytes available to read from an inotify file descriptor.

### Limitations and caveats
The inotify API provides no information about the user or process that triggered the inotify event. In particular, there is no easy way for a process that is monitoring events via inotify to distinguish events that it triggers itself from those that are triggered by other processes.

Inotify reports only events that a user-space program triggers through the filesystem API. As a result, it does not catch remote events that occur on network filesystems. (Applications must fall back to polling the filesystem to catch such events.) Furthermore, various pseudo-filesystems such as /proc, /sys, and /dev/pts are not monitorable with inotify.

The inotify API does not report file accesses and modifications that may occur because of mmap(2), msync(2), and munmap(2).

The inotify API identifies affected files by filename. However, by the time an application processes an inotify event, the filename may already have been deleted or renamed.

The inotify API identifies events via watch descriptors. It is the application's responsibility to cache a mapping (if one is needed) between watch descriptors and pathnames. Be aware that directory renamings may affect multiple cached pathnames.

Inotify monitoring of directories is not recursive: to monitor subdirectories under a directory, additional watches must be created. This can take a significant amount time for large directory trees.

If monitoring an entire directory subtree, and a new subdirectory is created in that tree or an existing directory is renamed into that tree, be aware that by the time you create a watch for the new subdirectory, new files (and subdirectories) may already exist inside the subdirectory. Therefore, you may want to scan the contents of the subdirectory immediately after adding the watch (and, if desired, recursively add watches for any subdirectories that it contains).

Note that the event queue can overflow. In this case, events are lost. Robust applications should handle the possibility of lost events gracefully. For example, it may be necessary to rebuild part or all of the application cache. (One simple, but possibly expensive, approach is to close the inotify file descriptor, empty the cache, create a new inotify file descriptor, and then re-create watches and cache entries for the objects to be monitored.)

If a filesystem is mounted on top of a monitored directory, no event is generated, and no events are generated for objects immediately under the new mount point. If the filesystem is subsequently unmounted, events will subsequently be generated for the directory and the objects it contains.

### Dealing with rename() events
As noted above, the IN_MOVED_FROM and IN_MOVED_TO event pair that is generated by rename(2) can be matched up via their shared cookie value. However, the task of matching has some challenges.

These two events are usually consecutive in the event stream available when reading from the inotify file descriptor. However, this is not guaranteed. If multiple processes are triggering events for monitored objects, then (on rare occasions) an arbitrary number of other events may appear between the IN_MOVED_FROM and IN_MOVED_TO events. Furthermore, it is not guaranteed that the event pair is atomically inserted into the queue: there may be a brief interval where the IN_MOVED_FROM has appeared, but the IN_MOVED_TO has not.

Matching up the IN_MOVED_FROM and IN_MOVED_TO event pair generated by rename(2) is thus inherently racy. (Don't forget that if an object is renamed outside of a monitored directory, there may not even be an IN_MOVED_TO event.) Heuristic approaches (e.g., assume the events are always consecutive) can be used to ensure a match in most cases, but will inevitably miss some cases, causing the application to perceive the IN_MOVED_FROM and IN_MOVED_TO events as being unrelated. If watch descriptors are destroyed and re-created as a result, then those watch descriptors will be inconsistent with the watch descriptors in any pending events. (Re-creating the inotify file descriptor and rebuilding the cache may be useful to deal with this scenario.)

Applications should also allow for the possibility that the IN_MOVED_FROM event was the last event that could fit in the buffer returned by the current call to read(2), and the accompanying IN_MOVED_TO event might be fetched only on the next read(2), which should be done with a (small) timeout to allow for the fact that insertion of the IN_MOVED_FROM+IN_MOVED_TO event pair is not atomic, and also the possibility that there may not be any IN_MOVED_TO event.

## BUGS
Before Linux 3.19, fallocate(2) did not create any inotify events. Since Linux 3.19, calls to fallocate(2) generate IN_MODIFY events.

Before Linux 2.6.16, the IN_ONESHOT mask flag does not work.

As originally designed and implemented, the IN_ONESHOT flag did not cause an IN_IGNORED event to be generated when the watch was dropped after one event. However, as an unintended effect of other changes, since Linux 2.6.36, an IN_IGNORED event is generated in this case.

Before Linux 2.6.25, the kernel code that was intended to coalesce successive identical events (i.e., the two most recent events could potentially be coalesced if the older had not yet been read) instead checked if the most recent event could be coalesced with the oldest unread event.

When a watch descriptor is removed by calling inotify_rm_watch(2) (or because a watch file is deleted or the filesystem that contains it is unmounted), any pending unread events for that watch descriptor remain available to read. As watch descriptors are subsequently allocated with inotify_add_watch(2), the kernel cycles through the range of possible watch descriptors (1 to INT_MAX) incrementally. When allocating a free watch descriptor, no check is made to see whether that watch descriptor number has any pending unread events in the inotify queue. Thus, it can happen that a watch descriptor is reallocated even when pending unread events exist for a previous incarnation of that watch descriptor number, with the result that the application might then read those events and interpret them as belonging to the file associated with the newly recycled watch descriptor. In practice, the likelihood of hitting this bug may be extremely low, since it requires that an application cycle through INT_MAX watch descriptors, release a watch descriptor while leaving unread events for that watch descriptor in the queue, and then recycle that watch descriptor. For this reason, and because there have been no reports of the bug occurring in real-world applications, as of Linux 3.15, no kernel changes have yet been made to eliminate this possible bug.

## EXAMPLES
The following program demonstrates the usage of the inotify API. It marks the directories passed as a command-line arguments and waits for events of type IN_OPEN, IN_CLOSE_NOWRITE, and IN_CLOSE_WRITE.

The following output was recorded while editing the file /home/user/temp/foo and listing directory /tmp. Before the file and the directory were opened, IN_OPEN events occurred. After the file was closed, an IN_CLOSE_WRITE event occurred. After the directory was closed, an IN_CLOSE_NOWRITE event occurred. Execution of the program ended when the user pressed the ENTER key.

### Example output

```
$ ./a.out /tmp /home/user/temp
Press enter key to terminate.
Listening for events.
IN_OPEN: /home/user/temp/foo [file]
IN_CLOSE_WRITE: /home/user/temp/foo [file]
IN_OPEN: /tmp/ [directory]
IN_CLOSE_NOWRITE: /tmp/ [directory]
Listening for events stopped.
```

### Program source

```
#include <errno.h>
#include <poll.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/inotify.h>
#include <unistd.h>
#include <string.h>
/* Read all available inotify events from the file descriptor 'fd'.

   wd is the table of watch descriptors for the directories in argv.

   argc is the length of wd and argv.

   argv is the list of watched directories.

   Entry 0 of wd and argv is unused. */
static void
handle_events(int fd, int *wd, int argc, char* argv[])
{

    /* Some systems cannot read integer variables if they are not

       properly aligned. On other systems, incorrect alignment may

       decrease performance. Hence, the buffer used for reading from

       the inotify file descriptor should have the same alignment as

       struct inotify_event. */

    char buf[4096]

        __attribute__ ((aligned(__alignof__(struct inotify_event))));

    const struct inotify_event *event;

    ssize_t len;

    /* Loop while events can be read from inotify file descriptor. */

    for (;;) {

        /* Read some events. */

        len = read(fd, buf, sizeof(buf));

        if (len == -1 && errno != EAGAIN) {

            perror("read");

            exit(EXIT_FAILURE);

        }

        /* If the nonblocking read() found no events to read, then

           it returns -1 with errno set to EAGAIN. In that case,

           we exit the loop. */

        if (len <= 0)

            break;

        /* Loop over all events in the buffer. */

        for (char *ptr = buf; ptr < buf + len;

                ptr += sizeof(struct inotify_event) + event->len) {

            event = (const struct inotify_event *) ptr;

            /* Print event type. */

            if (event->mask & IN_OPEN)

                printf("IN_OPEN: ");

            if (event->mask & IN_CLOSE_NOWRITE)

                printf("IN_CLOSE_NOWRITE: ");

            if (event->mask & IN_CLOSE_WRITE)

                printf("IN_CLOSE_WRITE: ");

            /* Print the name of the watched directory. */

            for (size_t i = 1; i < argc; ++i) {

                if (wd[i] == event->wd) {

                    printf("%s/", argv[i]);

                    break;

                }

            }

            /* Print the name of the file. */

            if (event->len)

                printf("%s", event->name);

            /* Print type of filesystem object. */

            if (event->mask & IN_ISDIR)

                printf(" [directory]\n");

            else

                printf(" [file]\n");

        }

    }
}
int
main(int argc, char* argv[])
{

    char buf;

    int fd, i, poll_num;

    int *wd;

    nfds_t nfds;

    struct pollfd fds[2];

    if (argc < 2) {

        printf("Usage: %s PATH [PATH ...]\n", argv[0]);

        exit(EXIT_FAILURE);

    }

    printf("Press ENTER key to terminate.\n");

    /* Create the file descriptor for accessing the inotify API. */

    fd = inotify_init1(IN_NONBLOCK);

    if (fd == -1) {

        perror("inotify_init1");

        exit(EXIT_FAILURE);

    }

    /* Allocate memory for watch descriptors. */

    wd = calloc(argc, sizeof(int));

    if (wd == NULL) {

        perror("calloc");

        exit(EXIT_FAILURE);

    }

    /* Mark directories for events

       - file was opened

       - file was closed */

    for (i = 1; i < argc; i++) {

        wd[i] = inotify_add_watch(fd, argv[i],

                                  IN_OPEN | IN_CLOSE);

        if (wd[i] == -1) {

            fprintf(stderr, "Cannot watch '%s': %s\n",

                    argv[i], strerror(errno));

            exit(EXIT_FAILURE);

        }

    }

    /* Prepare for polling. */

    nfds = 2;

    fds[0].fd = STDIN_FILENO;       /* Console input */

    fds[0].events = POLLIN;

    fds[1].fd = fd;                 /* Inotify input */

    fds[1].events = POLLIN;

    /* Wait for events and/or terminal input. */

    printf("Listening for events.\n");

    while (1) {

        poll_num = poll(fds, nfds, -1);

        if (poll_num == -1) {

            if (errno == EINTR)

                continue;

            perror("poll");

            exit(EXIT_FAILURE);

        }

        if (poll_num > 0) {

            if (fds[0].revents & POLLIN) {

                /* Console input is available. Empty stdin and quit. */

                while (read(STDIN_FILENO, &buf, 1) > 0 && buf != '\n')

                    continue;

                break;

            }

            if (fds[1].revents & POLLIN) {

                /* Inotify events are available. */

                handle_events(fd, wd, argc, argv);

            }

        }

    }

    printf("Listening for events stopped.\n");

    /* Close inotify file descriptor. */

    close(fd);

    free(wd);

    exit(EXIT_SUCCESS);
}
```

## SEE ALSO
inotifywait(1), inotifywatch(1), inotify_add_watch(2), inotify_init(2), inotify_init1(2), inotify_rm_watch(2), read(2), stat(2), fanotify(7)

Documentation/filesystems/inotify.txt in the Linux kernel source tree

branch: sisyphus


intro

title: intro(7)

text:
# intro(7)

## NAME
intro - introduction to overview and miscellany section

## DESCRIPTION
Section 7 of the manual provides overviews on various topics, and describes conventions and protocols, character set standards, the standard filesystem layout, and miscellaneous other things.

## NOTES

### Authors and copyright conditions
Look at the header of the manual page source for the author(s) and copyright conditions. Note that these can be different from page to page!

## SEE ALSO
standards(7)


ip

title: ip(7)

summary: Linux IPv4 protocol implementation

text:
# ip(7)

## NAME
ip - Linux IPv4 protocol implementation

## SYNOPSIS

```
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h> /* superset of previous */
```

```
tcp_socket = socket(AF_INET, SOCK_STREAM, 0);
udp_socket = socket(AF_INET, SOCK_DGRAM, 0);
raw_socket = socket(AF_INET, SOCK_RAW, protocol);
```

## DESCRIPTION
Linux implements the Internet Protocol, version 4, described in RFC 791 and RFC 1122. ip contains a level 2 multicasting implementation conforming to RFC 1112. It also contains an IP router including a packet filter.

The programming interface is BSD-sockets compatible. For more information on sockets, see socket(7).

An IP socket is created using socket(2):

```
socket(AF_INET, socket_type, protocol);
```

Valid socket types include SOCK_STREAM to open a stream socket, SOCK_DGRAM to open a datagram socket, and SOCK_RAW to open a raw(7) socket to access the IP protocol directly.

protocol is the IP protocol in the IP header to be received or sent. Valid values for protocol include:

•

0 and IPPROTO_TCP for tcp(7) stream sockets;

•

0 and IPPROTO_UDP for udp(7) datagram sockets;

•

IPPROTO_SCTP for sctp(7) stream sockets; and

•

IPPROTO_UDPLITE for udplite(7) datagram sockets.

For SOCK_RAW you may specify a valid IANA IP protocol defined in RFC 1700 assigned numbers.

When a process wants to receive new incoming packets or connections, it should bind a socket to a local interface address using bind(2). In this case, only one IP socket may be bound to any given local (address, port) pair. When INADDR_ANY is specified in the bind call, the socket will be bound to all local interfaces. When listen(2) is called on an unbound socket, the socket is automatically bound to a random free port with the local address set to INADDR_ANY. When connect(2) is called on an unbound socket, the socket is automatically bound to a random free port or to a usable shared port with the local address set to INADDR_ANY.

A TCP local socket address that has been bound is unavailable for some time after closing, unless the SO_REUSEADDR flag has been set. Care should be taken when using this flag as it makes TCP less reliable.

### Address format
An IP socket address is defined as a combination of an IP interface address and a 16-bit port number. The basic IP protocol does not supply port numbers, they are implemented by higher level protocols like udp(7) and tcp(7). On raw sockets sin_port is set to the IP protocol.

```
struct sockaddr_in {

    sa_family_t    sin_family; /* address family: AF_INET */

    in_port_t      sin_port;   /* port in network byte order */

    struct in_addr sin_addr;   /* internet address */
};
/* Internet address */
struct in_addr {

    uint32_t       s_addr;     /* address in network byte order */
};
```

sin_family is always set to AF_INET. This is required; in Linux 2.2 most networking functions return EINVAL when this setting is missing. sin_port contains the port in network byte order. The port numbers below 1024 are called privileged ports (or sometimes: reserved ports). Only a privileged process (on Linux: a process that has the CAP_NET_BIND_SERVICE capability in the user namespace governing its network namespace) may bind(2) to these sockets. Note that the raw IPv4 protocol as such has no concept of a port, they are implemented only by higher protocols like tcp(7) and udp(7).

sin_addr is the IP host address. The s_addr member of struct in_addr contains the host interface address in network byte order. in_addr should be assigned one of the INADDR_* values (e.g., INADDR_LOOPBACK) using htonl(3) or set using the inet_aton(3), inet_addr(3), inet_makeaddr(3) library functions or directly with the name resolver (see gethostbyname(3)).

IPv4 addresses are divided into unicast, broadcast, and multicast addresses. Unicast addresses specify a single interface of a host, broadcast addresses specify all hosts on a network, and multicast addresses address all hosts in a multicast group. Datagrams to broadcast addresses can be sent or received only when the SO_BROADCAST socket flag is set. In the current implementation, connection-oriented sockets are allowed to use only unicast addresses.

Note that the address and the port are always stored in network byte order. In particular, this means that you need to call htons(3) on the number that is assigned to a port. All address/port manipulation functions in the standard library work in network byte order.

### Special and reserved addresses
There are several special addresses:

INADDR_LOOPBACK (127.0.0.1)

always refers to the local host via the loopback device;

INADDR_ANY (0.0.0.0)

means any address for socket binding;

INADDR_BROADCAST (255.255.255.255)

has the same effect on bind(2) as INADDR_ANY for historical reasons. A packet addressed to INADDR_BROADCAST through a socket which has SO_BROADCAST set will be broadcast to all hosts on the local network segment, as long as the link is broadcast-capable.

Highest-numbered address

Lowest-numbered address

On any locally-attached non-point-to-point IP subnet with a link type that supports broadcasts, the highest-numbered address (e.g., the .255 address on a subnet with netmask 255.255.255.0) is designated as a broadcast address. It cannot usefully be assigned to an individual interface, and can only be addressed with a socket on which the SO_BROADCAST option has been set. Internet standards have historically also reserved the lowest-numbered address (e.g., the .0 address on a subnet with netmask 255.255.255.0) for broadcast, though they call it "obsolete" for this purpose. (Some sources also refer to this as the "network address.") Since Linux 5.14, it is treated as an ordinary unicast address and can be assigned to an interface.

Internet standards have traditionally also reserved various addresses for particular uses, though Linux no longer treats some of these specially.

[0.0.0.1, 0.255.255.255]

[240.0.0.0, 255.255.255.254]

Addresses in these ranges (0/8 and 240/4) are reserved globally. Since Linux 5.3 and Linux 2.6.25, respectively, the 0/8 and 240/4 addresses, other than INADDR_ANY and INADDR_BROADCAST, are treated as ordinary unicast addresses. Systems that follow the traditional behaviors may not interoperate with these historically reserved addresses.

[127.0.0.1, 127.255.255.254]

Addresses in this range (127/8) are treated as loopback addresses akin to the standardized local loopback address INADDR_LOOPBACK (127.0.0.1);

[224.0.0.0, 239.255.255.255]

Addresses in this range (224/4) are dedicated to multicast use.

### Socket options
IP supports some protocol-specific socket options that can be set with setsockopt(2) and read with getsockopt(2). The socket option level for IP is IPPROTO_IP. A boolean integer flag is zero when it is false, otherwise true.

When an invalid socket option is specified, getsockopt(2) and setsockopt(2) fail with the error ENOPROTOOPT.

IP_ADD_MEMBERSHIP (since Linux 1.2)

Join a multicast group. Argument is an ip_mreqn structure.

```
struct ip_mreqn {

    struct in_addr imr_multiaddr; /* IP multicast group

                                     address */

    struct in_addr imr_address;   /* IP address of local

                                     interface */

    int            imr_ifindex;   /* interface index */
};

```

imr_multiaddr contains the address of the multicast group the application wants to join or leave. It must be a valid multicast address (or setsockopt(2) fails with the error EINVAL). imr_address is the address of the local interface with which the system should join the multicast group; if it is equal to INADDR_ANY, an appropriate interface is chosen by the system. imr_ifindex is the interface index of the interface that should join/leave the imr_multiaddr group, or 0 to indicate any interface.

The ip_mreqn structure is available only since Linux 2.2. For compatibility, the old ip_mreq structure (present since Linux 1.2) is still supported; it differs from ip_mreqn only by not including the imr_ifindex field. (The kernel determines which structure is being passed based on the size passed in optlen.)

IP_ADD_MEMBERSHIP is valid only for setsockopt(2).

IP_ADD_SOURCE_MEMBERSHIP (since Linux 2.4.22 / Linux 2.5.68)

Join a multicast group and allow receiving data only from a specified source. Argument is an ip_mreq_source structure.

```
struct ip_mreq_source {

    struct in_addr imr_multiaddr;  /* IP multicast group

                                      address */

    struct in_addr imr_interface;  /* IP address of local

                                      interface */

    struct in_addr imr_sourceaddr; /* IP address of

                                      multicast source */
};

```

The ip_mreq_source structure is similar to ip_mreqn described under IP_ADD_MEMBERSHIP. The imr_multiaddr field contains the address of the multicast group the application wants to join or leave. The imr_interface field is the address of the local interface with which the system should join the multicast group. Finally, the imr_sourceaddr field contains the address of the source the application wants to receive data from.

This option can be used multiple times to allow receiving data from more than one source.

IP_BIND_ADDRESS_NO_PORT (since Linux 4.2)

Inform the kernel to not reserve an ephemeral port when using bind(2) with a port number of 0. The port will later be automatically chosen at connect(2) time, in a way that allows sharing a source port as long as the 4-tuple is unique.

IP_BLOCK_SOURCE (since Linux 2.4.22 / 2.5.68)

Stop receiving multicast data from a specific source in a given group. This is valid only after the application has subscribed to the multicast group using either IP_ADD_MEMBERSHIP or IP_ADD_SOURCE_MEMBERSHIP.

Argument is an ip_mreq_source structure as described under IP_ADD_SOURCE_MEMBERSHIP.

IP_DROP_MEMBERSHIP (since Linux 1.2)

Leave a multicast group. Argument is an ip_mreqn or ip_mreq structure similar to IP_ADD_MEMBERSHIP.

IP_DROP_SOURCE_MEMBERSHIP (since Linux 2.4.22 / 2.5.68)

Leave a source-specific group—that is, stop receiving data from a given multicast group that come from a given source. If the application has subscribed to multiple sources within the same group, data from the remaining sources will still be delivered. To stop receiving data from all sources at once, use IP_DROP_MEMBERSHIP.

Argument is an ip_mreq_source structure as described under IP_ADD_SOURCE_MEMBERSHIP.

IP_FREEBIND (since Linux 2.4)

If enabled, this boolean option allows binding to an IP address that is nonlocal or does not (yet) exist. This permits listening on a socket, without requiring the underlying network interface or the specified dynamic IP address to be up at the time that the application is trying to bind to it. This option is the per-socket equivalent of the ip_nonlocal_bind /proc interface described below.

IP_HDRINCL (since Linux 2.0)

If enabled, the user supplies an IP header in front of the user data. Valid only for SOCK_RAW sockets; see raw(7) for more information. When this flag is enabled, the values set by IP_OPTIONS, IP_TTL, and IP_TOS are ignored.

IP_LOCAL_PORT_RANGE (since Linux 6.3)

Set or get the per-socket default local port range. This option can be used to clamp down the global local port range, defined by the ip_local_port_range /proc interface described below, for a given socket.

The option takes an uint32_t value with the high 16 bits set to the upper range bound, and the low 16 bits set to the lower range bound. Range bounds are inclusive. The 16-bit values should be in host byte order.

The lower bound has to be less than the upper bound when both bounds are not zero. Otherwise, setting the option fails with EINVAL.

If either bound is outside of the global local port range, or is zero, then that bound has no effect.

To reset the setting, pass zero as both the upper and the lower bound.

IP_MSFILTER (since Linux 2.4.22 / 2.5.68)

This option provides access to the advanced full-state filtering API. Argument is an ip_msfilter structure.

```
struct ip_msfilter {

    struct in_addr imsf_multiaddr; /* IP multicast group

                                      address */

    struct in_addr imsf_interface; /* IP address of local

                                      interface */

    uint32_t       imsf_fmode;     /* Filter-mode */

    uint32_t       imsf_numsrc;    /* Number of sources in

                                      the following array */

    struct in_addr imsf_slist[1];  /* Array of source

                                      addresses */
};

```

There are two macros, MCAST_INCLUDE and MCAST_EXCLUDE, which can be used to specify the filtering mode. Additionally, the IP_MSFILTER_SIZE(n) macro exists to determine how much memory is needed to store ip_msfilter structure with n sources in the source list.

For the full description of multicast source filtering refer to RFC 3376.

IP_MTU (since Linux 2.2)

Retrieve the current known path MTU of the current socket. Returns an integer.

IP_MTU is valid only for getsockopt(2) and can be employed only when the socket has been connected.

IP_MTU_DISCOVER (since Linux 2.2)

Set or receive the Path MTU Discovery setting for a socket. When enabled, Linux will perform Path MTU Discovery as defined in RFC 1191 on SOCK_STREAM sockets. For non-SOCK_STREAM sockets, IP_PMTUDISC_DO forces the don't-fragment flag to be set on all outgoing packets. It is the user's responsibility to packetize the data in MTU-sized chunks and to do the retransmits if necessary. The kernel will reject (with EMSGSIZE) datagrams that are bigger than the known path MTU. IP_PMTUDISC_WANT will fragment a datagram if needed according to the path MTU, or will set the don't-fragment flag otherwise.

The system-wide default can be toggled between IP_PMTUDISC_WANT and IP_PMTUDISC_DONT by writing (respectively, zero and nonzero values) to the /proc/sys/net/ipv4/ip_no_pmtu_disc file. Path MTU discovery value

Meaning

IP_PMTUDISC_WANT

Use per-route settings.

IP_PMTUDISC_DONT

Never do Path MTU Discovery.

IP_PMTUDISC_DO

Always do Path MTU Discovery.

IP_PMTUDISC_PROBE

Set DF but ignore Path MTU.

When PMTU discovery is enabled, the kernel automatically keeps track of the path MTU per destination host. When it is connected to a specific peer with connect(2), the currently known path MTU can be retrieved conveniently using the IP_MTU socket option (e.g., after an EMSGSIZE error occurred). The path MTU may change over time. For connectionless sockets with many destinations, the new MTU for a given destination can also be accessed using the error queue (see IP_RECVERR). A new error will be queued for every incoming MTU update.

While MTU discovery is in progress, initial packets from datagram sockets may be dropped. Applications using UDP should be aware of this and not take it into account for their packet retransmit strategy.

To bootstrap the path MTU discovery process on unconnected sockets, it is possible to start with a big datagram size (headers up to 64 kilobytes long) and let it shrink by updates of the path MTU.

To get an initial estimate of the path MTU, connect a datagram socket to the destination address using connect(2) and retrieve the MTU by calling getsockopt(2) with the IP_MTU option.

It is possible to implement RFC 4821 MTU probing with SOCK_DGRAM or SOCK_RAW sockets by setting a value of IP_PMTUDISC_PROBE (available since Linux 2.6.22). This is also particularly useful for diagnostic tools such as tracepath(8) that wish to deliberately send probe packets larger than the observed Path MTU.

IP_MULTICAST_ALL (since Linux 2.6.31)

This option can be used to modify the delivery policy of multicast messages. The argument is a boolean integer (defaults to 1). If set to 1, the socket will receive messages from all the groups that have been joined globally on the whole system. Otherwise, it will deliver messages only from the groups that have been explicitly joined (for example via the IP_ADD_MEMBERSHIP option) on this particular socket.

IP_MULTICAST_IF (since Linux 1.2)

Set the local device for a multicast socket. The argument for setsockopt(2) is an ip_mreqn or (since Linux 3.5) ip_mreq structure similar to IP_ADD_MEMBERSHIP, or an in_addr structure. (The kernel determines which structure is being passed based on the size passed in optlen.) For getsockopt(2), the argument is an in_addr structure.

IP_MULTICAST_LOOP (since Linux 1.2)

Set or read a boolean integer argument that determines whether sent multicast packets should be looped back to the local sockets.

IP_MULTICAST_TTL (since Linux 1.2)

Set or read the time-to-live value of outgoing multicast packets for this socket. It is very important for multicast packets to set the smallest TTL possible. The default is 1 which means that multicast packets don't leave the local network unless the user program explicitly requests it. Argument is an integer.

IP_NODEFRAG (since Linux 2.6.36)

If enabled (argument is nonzero), the reassembly of outgoing packets is disabled in the netfilter layer. The argument is an integer.

This option is valid only for SOCK_RAW sockets.

IP_OPTIONS (since Linux 2.0)

Set or get the IP options to be sent with every packet from this socket. The arguments are a pointer to a memory buffer containing the options and the option length. The setsockopt(2) call sets the IP options associated with a socket. The maximum option size for IPv4 is 40 bytes. See RFC 791 for the allowed options. When the initial connection request packet for a SOCK_STREAM socket contains IP options, the IP options will be set automatically to the options from the initial packet with routing headers reversed. Incoming packets are not allowed to change options after the connection is established. The processing of all incoming source routing options is disabled by default and can be enabled by using the accept_source_route /proc interface. Other options like timestamps are still handled. For datagram sockets, IP options can be set only by the local user. Calling getsockopt(2) with IP_OPTIONS puts the current IP options used for sending into the supplied buffer.

IP_PASSSEC (since Linux 2.6.17)

If labeled IPSEC or NetLabel is configured on the sending and receiving hosts, this option enables receiving of the security context of the peer socket in an ancillary message of type SCM_SECURITY retrieved using recvmsg(2). This option is supported only for UDP sockets; for TCP or SCTP sockets, see the description of the SO_PEERSEC option below.

The value given as an argument to setsockopt(2) and returned as the result of getsockopt(2) is an integer boolean flag.

The security context returned in the SCM_SECURITY ancillary message is of the same format as the one described under the SO_PEERSEC option below.

Note: the reuse of the SCM_SECURITY message type for the IP_PASSSEC socket option was likely a mistake, since other IP control messages use their own numbering scheme in the IP namespace and often use the socket option value as the message type. There is no conflict currently since the IP option with the same value as SCM_SECURITY is IP_HDRINCL and this is never used for a control message type.

IP_PKTINFO (since Linux 2.2)

Pass an IP_PKTINFO ancillary message that contains a pktinfo structure that supplies some information about the incoming packet. This works only for datagram oriented sockets. The argument is a flag that tells the socket whether the IP_PKTINFO message should be passed or not. The message itself can be sent/retrieved only as a control message with a packet using recvmsg(2) or sendmsg(2).

```
struct in_pktinfo {

    unsigned int   ipi_ifindex;  /* Interface index */

    struct in_addr ipi_spec_dst; /* Local address */

    struct in_addr ipi_addr;     /* Header Destination

                                    address */
};

```

ipi_ifindex is the unique index of the interface the packet was received on. ipi_spec_dst is the local address of the packet and ipi_addr is the destination address in the packet header. If IP_PKTINFO is passed to sendmsg(2) and ipi_spec_dst is not zero, then it is used as the local source address for the routing table lookup and for setting up IP source route options. When ipi_ifindex is not zero, the primary local address of the interface specified by the index overwrites ipi_spec_dst for the routing table lookup.

IP_RECVERR (since Linux 2.2)

Enable extended reliable error message passing. When enabled on a datagram socket, all generated errors will be queued in a per-socket error queue. When the user receives an error from a socket operation, the errors can be received by calling recvmsg(2) with the MSG_ERRQUEUE flag set. The sock_extended_err structure describing the error will be passed in an ancillary message with the type IP_RECVERR and the level IPPROTO_IP. This is useful for reliable error handling on unconnected sockets. The received data portion of the error queue contains the error packet.

The IP_RECVERR control message contains a sock_extended_err structure:

```
#define SO_EE_ORIGIN_NONE    0
#define SO_EE_ORIGIN_LOCAL   1
#define SO_EE_ORIGIN_ICMP    2
#define SO_EE_ORIGIN_ICMP6   3
struct sock_extended_err {

    uint32_t ee_errno;   /* error number */

    uint8_t  ee_origin;  /* where the error originated */

    uint8_t  ee_type;    /* type */

    uint8_t  ee_code;    /* code */

    uint8_t  ee_pad;

    uint32_t ee_info;    /* additional information */

    uint32_t ee_data;    /* other data */

    /* More data may follow */
};
struct sockaddr *SO_EE_OFFENDER(struct sock_extended_err *);

```

ee_errno contains the errno number of the queued error. ee_origin is the origin code of where the error originated. The other fields are protocol-specific. The macro SO_EE_OFFENDER returns a pointer to the address of the network object where the error originated from given a pointer to the ancillary message. If this address is not known, the sa_family member of the sockaddr contains AF_UNSPEC and the other fields of the sockaddr are undefined.

IP uses the sock_extended_err structure as follows: ee_origin is set to SO_EE_ORIGIN_ICMP for errors received as an ICMP packet, or SO_EE_ORIGIN_LOCAL for locally generated errors. Unknown values should be ignored. ee_type and ee_code are set from the type and code fields of the ICMP header. ee_info contains the discovered MTU for EMSGSIZE errors. The message also contains the sockaddr_in of the node caused the error, which can be accessed with the SO_EE_OFFENDER macro. The sin_family field of the SO_EE_OFFENDER address is AF_UNSPEC when the source was unknown. When the error originated from the network, all IP options (IP_OPTIONS, IP_TTL, etc.) enabled on the socket and contained in the error packet are passed as control messages. The payload of the packet causing the error is returned as normal payload. Note that TCP has no error queue; MSG_ERRQUEUE is not permitted on SOCK_STREAM sockets. IP_RECVERR is valid for TCP, but all errors are returned by socket function return or SO_ERROR only.

For raw sockets, IP_RECVERR enables passing of all received ICMP errors to the application, otherwise errors are reported only on connected sockets

It sets or retrieves an integer boolean flag. IP_RECVERR defaults to off.

IP_RECVOPTS (since Linux 2.2)

Pass all incoming IP options to the user in a IP_OPTIONS control message. The routing header and other options are already filled in for the local host. Not supported for SOCK_STREAM sockets.

IP_RECVORIGDSTADDR (since Linux 2.6.29)

This boolean option enables the IP_ORIGDSTADDR ancillary message in recvmsg(2), in which the kernel returns the original destination address of the datagram being received. The ancillary message contains a struct sockaddr_in.

IP_RECVTOS (since Linux 2.2)

If enabled, the IP_TOS ancillary message is passed with incoming packets. It contains a byte which specifies the Type of Service/Precedence field of the packet header. Expects a boolean integer flag.

IP_RECVTTL (since Linux 2.2)

When this flag is set, pass a IP_TTL control message with the time-to-live field of the received packet as a 32 bit integer. Not supported for SOCK_STREAM sockets.

IP_RETOPTS (since Linux 2.2)

Identical to IP_RECVOPTS, but returns raw unprocessed options with timestamp and route record options not filled in for this hop.

IP_ROUTER_ALERT (since Linux 2.2)

Pass all to-be forwarded packets with the IP Router Alert option set to this socket. Valid only for raw sockets. This is useful, for instance, for user-space RSVP daemons. The tapped packets are not forwarded by the kernel; it is the user's responsibility to send them out again. Socket binding is ignored, such packets are filtered only by protocol. Expects an integer flag.

IP_TOS (since Linux 1.0)

Set or receive the Type-Of-Service (TOS) field that is sent with every IP packet originating from this socket. It is used to prioritize packets on the network. TOS is a byte. There are some standard TOS flags defined: IPTOS_LOWDELAY to minimize delays for interactive traffic, IPTOS_THROUGHPUT to optimize throughput, IPTOS_RELIABILITY to optimize for reliability, IPTOS_MINCOST should be used for "filler data" where slow transmission doesn't matter. At most one of these TOS values can be specified. Other bits are invalid and shall be cleared. Linux sends IPTOS_LOWDELAY datagrams first by default, but the exact behavior depends on the configured queueing discipline. Some high-priority levels may require superuser privileges (the CAP_NET_ADMIN capability).

IP_TRANSPARENT (since Linux 2.6.24)

Setting this boolean option enables transparent proxying on this socket. This socket option allows the calling application to bind to a nonlocal IP address and operate both as a client and a server with the foreign address as the local endpoint. NOTE: this requires that routing be set up in a way that packets going to the foreign address are routed through the TProxy box (i.e., the system hosting the application that employs the IP_TRANSPARENT socket option). Enabling this socket option requires superuser privileges (the CAP_NET_ADMIN capability).

TProxy redirection with the iptables TPROXY target also requires that this option be set on the redirected socket.

IP_TTL (since Linux 1.0)

Set or retrieve the current time-to-live field that is used in every packet sent from this socket.

IP_UNBLOCK_SOURCE (since Linux 2.4.22 / 2.5.68)

Unblock previously blocked multicast source. Returns EADDRNOTAVAIL when given source is not being blocked.

Argument is an ip_mreq_source structure as described under IP_ADD_SOURCE_MEMBERSHIP.

SO_PEERSEC (since Linux 2.6.17)

If labeled IPSEC or NetLabel is configured on both the sending and receiving hosts, this read-only socket option returns the security context of the peer socket connected to this socket. By default, this will be the same as the security context of the process that created the peer socket unless overridden by the policy or by a process with the required permissions.

The argument to getsockopt(2) is a pointer to a buffer of the specified length in bytes into which the security context string will be copied. If the buffer length is less than the length of the security context string, then getsockopt(2) returns -1, sets errno to ERANGE, and returns the required length via optlen. The caller should allocate at least NAME_MAX bytes for the buffer initially, although this is not guaranteed to be sufficient. Resizing the buffer to the returned length and retrying may be necessary.

The security context string may include a terminating null character in the returned length, but is not guaranteed to do so: a security context "foo" might be represented as either {'f','o','o'} of length 3 or {'f','o','o','\0'} of length 4, which are considered to be interchangeable. The string is printable, does not contain non-terminating null characters, and is in an unspecified encoding (in particular, it is not guaranteed to be ASCII or UTF-8).

The use of this option for sockets in the AF_INET address family is supported since Linux 2.6.17 for TCP sockets, and since Linux 4.17 for SCTP sockets.

For SELinux, NetLabel conveys only the MLS portion of the security context of the peer across the wire, defaulting the rest of the security context to the values defined in the policy for the netmsg initial security identifier (SID). However, NetLabel can be configured to pass full security contexts over loopback. Labeled IPSEC always passes full security contexts as part of establishing the security association (SA) and looks them up based on the association for each packet.

### /proc interfaces
The IP protocol supports a set of /proc interfaces to configure some global parameters. The parameters can be accessed by reading or writing files in the directory /proc/sys/net/ipv4/. Interfaces described as Boolean take an integer value, with a nonzero value ("true") meaning that the corresponding option is enabled, and a zero value ("false") meaning that the option is disabled.

ip_always_defrag (Boolean; since Linux 2.2.13)

[New with Linux 2.2.13; in earlier kernel versions this feature was controlled at compile time by the CONFIG_IP_ALWAYS_DEFRAG option; this option is not present in Linux 2.4.x and later]

When this boolean flag is enabled (not equal 0), incoming fragments (parts of IP packets that arose when some host between origin and destination decided that the packets were too large and cut them into pieces) will be reassembled (defragmented) before being processed, even if they are about to be forwarded.

Enable only if running either a firewall that is the sole link to your network or a transparent proxy; never ever use it for a normal router or host. Otherwise, fragmented communication can be disturbed if the fragments travel over different links. Defragmentation also has a large memory and CPU time cost.

This is automagically turned on when masquerading or transparent proxying are configured.

ip_autoconfig (since Linux 2.2 to Linux 2.6.17)

Not documented.

ip_default_ttl (integer; default: 64; since Linux 2.2)

Set the default time-to-live value of outgoing packets. This can be changed per socket with the IP_TTL option.

ip_dynaddr (Boolean; default: disabled; since Linux 2.0.31)

Enable dynamic socket address and masquerading entry rewriting on interface address change. This is useful for dialup interface with changing IP addresses. 0 means no rewriting, 1 turns it on and 2 enables verbose mode.

ip_forward (Boolean; default: disabled; since Linux 1.2)

Enable IP forwarding with a boolean flag. IP forwarding can be also set on a per-interface basis.

ip_local_port_range (since Linux 2.2)

This file contains two integers that define the default local port range allocated to sockets that are not explicitly bound to a port number—that is, the range used for ephemeral ports. An ephemeral port is allocated to a socket in the following circumstances:

•

the port number in a socket address is specified as 0 when calling bind(2);

•

listen(2) is called on a stream socket that was not previously bound;

•

connect(2) was called on a socket that was not previously bound;

•

sendto(2) is called on a datagram socket that was not previously bound.

Allocation of ephemeral ports starts with the first number in ip_local_port_range and ends with the second number. If the range of ephemeral ports is exhausted, then the relevant system call returns an error (but see BUGS).

Note that the port range in ip_local_port_range should not conflict with the ports used by masquerading (although the case is handled). Also, arbitrary choices may cause problems with some firewall packet filters that make assumptions about the local ports in use. The first number should be at least greater than 1024, or better, greater than 4096, to avoid clashes with well known ports and to minimize firewall problems.

ip_no_pmtu_disc (Boolean; default: disabled; since Linux 2.2)

If enabled, don't do Path MTU Discovery for TCP sockets by default. Path MTU discovery may fail if misconfigured firewalls (that drop all ICMP packets) or misconfigured interfaces (e.g., a point-to-point link where the both ends don't agree on the MTU) are on the path. It is better to fix the broken routers on the path than to turn off Path MTU Discovery globally, because not doing it incurs a high cost to the network.

ip_nonlocal_bind (Boolean; default: disabled; since Linux 2.4)

If set, allows processes to bind(2) to nonlocal IP addresses, which can be quite useful, but may break some applications.

ip6frag_time (integer; default: 30)

Time in seconds to keep an IPv6 fragment in memory.

ip6frag_secret_interval (integer; default: 600)

Regeneration interval (in seconds) of the hash secret (or lifetime for the hash secret) for IPv6 fragments.

ipfrag_high_thresh (integer), ipfrag_low_thresh (integer)

If the amount of queued IP fragments reaches ipfrag_high_thresh, the queue is pruned down to ipfrag_low_thresh. Contains an integer with the number of bytes.

neigh/*

See arp(7).

### Ioctls
All ioctls described in socket(7) apply to ip.

Ioctls to configure generic device parameters are described in netdevice(7).

## ERRORS
EACCES

The user tried to execute an operation without the necessary permissions. These include: sending a packet to a broadcast address without having the SO_BROADCAST flag set; sending a packet via a prohibit route; modifying firewall settings without superuser privileges (the CAP_NET_ADMIN capability); binding to a privileged port without superuser privileges (the CAP_NET_BIND_SERVICE capability).

EADDRINUSE

Tried to bind to an address already in use.

EADDRNOTAVAIL

A nonexistent interface was requested or the requested source address was not local.

EAGAIN

Operation on a nonblocking socket would block.

EALREADY

A connection operation on a nonblocking socket is already in progress.

ECONNABORTED

A connection was closed during an accept(2).

EHOSTUNREACH

No valid routing table entry matches the destination address. This error can be caused by an ICMP message from a remote router or for the local routing table.

EINVAL

Invalid argument passed. For send operations this can be caused by sending to a blackhole route.

EISCONN

connect(2) was called on an already connected socket.

EMSGSIZE

Datagram is bigger than an MTU on the path and it cannot be fragmented.

ENOBUFS, ENOMEM

Not enough free memory. This often means that the memory allocation is limited by the socket buffer limits, not by the system memory, but this is not 100% consistent.

ENOENT

SIOCGSTAMP was called on a socket where no packet arrived.

ENOPKG

A kernel subsystem was not configured.

ENOPROTOOPT and EOPNOTSUPP

Invalid socket option passed.

ENOTCONN

The operation is defined only on a connected socket, but the socket wasn't connected.

EPERM

User doesn't have permission to set high priority, change configuration, or send signals to the requested process or group.

EPIPE

The connection was unexpectedly closed or shut down by the other end.

ESOCKTNOSUPPORT

The socket is not configured or an unknown socket type was requested.

Other errors may be generated by the overlaying protocols; see tcp(7), raw(7), udp(7), and socket(7).

## NOTES
IP_FREEBIND, IP_MSFILTER, IP_MTU, IP_MTU_DISCOVER, IP_RECVORIGDSTADDR, IP_PASSSEC, IP_PKTINFO, IP_RECVERR, IP_ROUTER_ALERT, and IP_TRANSPARENT are Linux-specific.

Be very careful with the SO_BROADCAST option - it is not privileged in Linux. It is easy to overload the network with careless broadcasts. For new application protocols it is better to use a multicast group instead of broadcasting. Broadcasting is discouraged. See RFC 6762 for an example of a protocol (mDNS) using the more modern multicast approach to communicating with an open-ended group of hosts on the local network.

Some other BSD sockets implementations provide IP_RCVDSTADDR and IP_RECVIF socket options to get the destination address and the interface of received datagrams. Linux has the more general IP_PKTINFO for the same task.

Some BSD sockets implementations also provide an IP_RECVTTL option, but an ancillary message with type IP_RECVTTL is passed with the incoming packet. This is different from the IP_TTL option used in Linux.

Using the SOL_IP socket options level isn't portable; BSD-based stacks use the IPPROTO_IP level.

INADDR_ANY (0.0.0.0) and INADDR_BROADCAST (255.255.255.255) are byte-order-neutral. This means htonl(3) has no effect on them.

### Compatibility
For compatibility with Linux 2.0, the obsolete socket(AF_INET, SOCK_PACKET, protocol) syntax is still supported to open a packet(7) socket. This is deprecated and should be replaced by socket(AF_PACKET, SOCK_RAW, protocol) instead. The main difference is the new sockaddr_ll address structure for generic link layer information instead of the old sockaddr_pkt.

## BUGS
There are too many inconsistent error values.

The error used to diagnose exhaustion of the ephemeral port range differs across the various system calls (connect(2), bind(2), listen(2), sendto(2)) that can assign ephemeral ports.

The ioctls to configure IP-specific interface options and ARP tables are not described.

Receiving the original destination address with MSG_ERRQUEUE in msg_name by recvmsg(2) does not work in some Linux 2.2 kernels.

## SEE ALSO
recvmsg(2), sendmsg(2), byteorder(3), capabilities(7), icmp(7), ipv6(7), netdevice(7), netlink(7), raw(7), socket(7), tcp(7), udp(7), ip(8)

The kernel source file Documentation/networking/ip-sysctl.txt.

RFC 791 for the original IP specification. RFC 1122 for the IPv4 host requirements. RFC 1812 for the IPv4 router requirements.


title: ipc_namespaces(7)

summary: overview of Linux IPC namespaces

text:
# ipc_namespaces(7)

## NAME
ipc_namespaces - overview of Linux IPC namespaces

## DESCRIPTION
IPC namespaces isolate certain IPC resources, namely, System V IPC objects (see sysvipc(7)) and (since Linux 2.6.30) POSIX message queues (see mq_overview(7)). The common characteristic of these IPC mechanisms is that IPC objects are identified by mechanisms other than filesystem pathnames.

Each IPC namespace has its own set of System V IPC identifiers and its own POSIX message queue filesystem. Objects created in an IPC namespace are visible to all other processes that are members of that namespace, but are not visible to processes in other IPC namespaces.

The following /proc interfaces are distinct in each IPC namespace:

•

The POSIX message queue interfaces in /proc/sys/fs/mqueue.

•

The System V IPC interfaces in /proc/sys/kernel, namely: msgmax, msgmnb, msgmni, sem, shmall, shmmax, shmmni, and shm_rmid_forced.

•

The System V IPC interfaces in /proc/sysvipc.

When an IPC namespace is destroyed (i.e., when the last process that is a member of the namespace terminates), all IPC objects in the namespace are automatically destroyed.

Use of IPC namespaces requires a kernel that is configured with the CONFIG_IPC_NS option.

## SEE ALSO
nsenter(1), unshare(1), clone(2), setns(2), unshare(2), mq_overview(7), namespaces(7), sysvipc(7)


title: ipv6(7)

summary: Linux IPv6 protocol implementation

text:
# ipv6(7)

## NAME
ipv6 - Linux IPv6 protocol implementation

## SYNOPSIS

```
#include <sys/socket.h>
#include <netinet/in.h>
```

```
tcp6_socket = socket(AF_INET6, SOCK_STREAM, 0);
raw6_socket = socket(AF_INET6, SOCK_RAW, protocol);
udp6_socket = socket(AF_INET6, SOCK_DGRAM, protocol);
```

## DESCRIPTION
Linux 2.2 optionally implements the Internet Protocol, version 6. This man page contains a description of the IPv6 basic API as implemented by the Linux kernel and glibc 2.1. The interface is based on the BSD sockets interface; see socket(7).

The IPv6 API aims to be mostly compatible with the IPv4 API (see ip(7)). Only differences are described in this man page.

To bind an AF_INET6 socket to any process, the local address should be copied from the in6addr_any variable which has in6_addr type. In static initializations, IN6ADDR_ANY_INIT may also be used, which expands to a constant expression. Both of them are in network byte order.

The IPv6 loopback address (::1) is available in the global in6addr_loopback variable. For initializations, IN6ADDR_LOOPBACK_INIT should be used.

IPv4 connections can be handled with the v6 API by using the v4-mapped-on-v6 address type; thus a program needs to support only this API type to support both protocols. This is handled transparently by the address handling functions in the C library.

IPv4 and IPv6 share the local port space. When you get an IPv4 connection or packet to an IPv6 socket, its source address will be mapped to v6.

### Address format

```
struct sockaddr_in6 {

    sa_family_t     sin6_family;   /* AF_INET6 */

    in_port_t       sin6_port;     /* port number */

    uint32_t        sin6_flowinfo; /* IPv6 flow information */

    struct in6_addr sin6_addr;     /* IPv6 address */

    uint32_t        sin6_scope_id; /* Scope ID (new in Linux 2.4) */
};
struct in6_addr {

    unsigned char   s6_addr[16];   /* IPv6 address */
};
```

sin6_family is always set to AF_INET6; sin6_port is the protocol port (see sin_port in ip(7)); sin6_flowinfo is the IPv6 flow identifier; sin6_addr is the 128-bit IPv6 address. sin6_scope_id is an ID depending on the scope of the address. It is new in Linux 2.4. Linux supports it only for link-local addresses, in that case sin6_scope_id contains the interface index (see netdevice(7))

IPv6 supports several address types: unicast to address a single host, multicast to address a group of hosts, anycast to address the nearest member of a group of hosts (not implemented in Linux), IPv4-on-IPv6 to address an IPv4 host, and other reserved address types.

The address notation for IPv6 is a group of 8 4-digit hexadecimal numbers, separated with a ':'. "::" stands for a string of 0 bits. Special addresses are ::1 for loopback and ::FFFF:<IPv4 address> for IPv4-mapped-on-IPv6.

The port space of IPv6 is shared with IPv4.

### Socket options
IPv6 supports some protocol-specific socket options that can be set with setsockopt(2) and read with getsockopt(2). The socket option level for IPv6 is IPPROTO_IPV6. A boolean integer flag is zero when it is false, otherwise true.

IPV6_ADDRFORM

Turn an AF_INET6 socket into a socket of a different address family. Only AF_INET is currently supported for that. It is allowed only for IPv6 sockets that are connected and bound to a v4-mapped-on-v6 address. The argument is a pointer to an integer containing AF_INET. This is useful to pass v4-mapped sockets as file descriptors to programs that don't know how to deal with the IPv6 API.

IPV6_ADD_MEMBERSHIP, IPV6_DROP_MEMBERSHIP

Control membership in multicast groups. Argument is a pointer to a struct ipv6_mreq.

IPV6_MTU

getsockopt(): Retrieve the current known path MTU of the current socket. Valid only when the socket has been connected. Returns an integer.

setsockopt(): Set the MTU to be used for the socket. The MTU is limited by the device MTU or the path MTU when path MTU discovery is enabled. Argument is a pointer to integer.

IPV6_MTU_DISCOVER

Control path-MTU discovery on the socket. See IP_MTU_DISCOVER in ip(7) for details.

IPV6_MULTICAST_HOPS

Set the multicast hop limit for the socket. Argument is a pointer to an integer. -1 in the value means use the route default, otherwise it should be between 0 and 255.

IPV6_MULTICAST_IF

Set the device for outgoing multicast packets on the socket. This is allowed only for SOCK_DGRAM and SOCK_RAW socket. The argument is a pointer to an interface index (see netdevice(7)) in an integer.

IPV6_MULTICAST_LOOP

Control whether the socket sees multicast packets that it has send itself. Argument is a pointer to boolean.

IPV6_RECVPKTINFO (since Linux 2.6.14)

Set delivery of the IPV6_PKTINFO control message on incoming datagrams. Such control messages contain a struct in6_pktinfo, as per RFC 3542. Allowed only for SOCK_DGRAM or SOCK_RAW sockets. Argument is a pointer to a boolean value in an integer.

IPV6_RTHDR, IPV6_AUTHHDR, IPV6_DSTOPTS, IPV6_HOPOPTS, IPV6_FLOWINFO, IPV6_HOPLIMIT

Set delivery of control messages for incoming datagrams containing extension headers from the received packet. IPV6_RTHDR delivers the routing header, IPV6_AUTHHDR delivers the authentication header, IPV6_DSTOPTS delivers the destination options, IPV6_HOPOPTS delivers the hop options, IPV6_FLOWINFO delivers an integer containing the flow ID, IPV6_HOPLIMIT delivers an integer containing the hop count of the packet. The control messages have the same type as the socket option. All these header options can also be set for outgoing packets by putting the appropriate control message into the control buffer of sendmsg(2). Allowed only for SOCK_DGRAM or SOCK_RAW sockets. Argument is a pointer to a boolean value.

IPV6_RECVERR

Control receiving of asynchronous error options. See IP_RECVERR in ip(7) for details. Argument is a pointer to boolean.

IPV6_ROUTER_ALERT

Pass forwarded packets containing a router alert hop-by-hop option to this socket. Allowed only for SOCK_RAW sockets. The tapped packets are not forwarded by the kernel, it is the user's responsibility to send them out again. Argument is a pointer to an integer. A positive integer indicates a router alert option value to intercept. Packets carrying a router alert option with a value field containing this integer will be delivered to the socket. A negative integer disables delivery of packets with router alert options to this socket.

IPV6_UNICAST_HOPS

Set the unicast hop limit for the socket. Argument is a pointer to an integer. -1 in the value means use the route default, otherwise it should be between 0 and 255.

IPV6_V6ONLY (since Linux 2.4.21 and 2.6)

If this flag is set to true (nonzero), then the socket is restricted to sending and receiving IPv6 packets only. In this case, an IPv4 and an IPv6 application can bind to a single port at the same time.

If this flag is set to false (zero), then the socket can be used to send and receive packets to and from an IPv6 address or an IPv4-mapped IPv6 address.

The argument is a pointer to a boolean value in an integer.

The default value for this flag is defined by the contents of the file /proc/sys/net/ipv6/bindv6only. The default value for that file is 0 (false).

## ERRORS
ENODEV

The user tried to bind(2) to a link-local IPv6 address, but the sin6_scope_id in the supplied sockaddr_in6 structure is not a valid interface index.

## VERSIONS
Linux 2.4 will break binary compatibility for the sockaddr_in6 for 64-bit hosts by changing the alignment of in6_addr and adding an additional sin6_scope_id field. The kernel interfaces stay compatible, but a program including sockaddr_in6 or in6_addr into other structures may not be. This is not a problem for 32-bit hosts like i386.

The sin6_flowinfo field is new in Linux 2.4. It is transparently passed/read by the kernel when the passed address length contains it. Some programs that pass a longer address buffer and then check the outgoing address length may break.

## NOTES
The sockaddr_in6 structure is bigger than the generic sockaddr. Programs that assume that all address types can be stored safely in a struct sockaddr need to be changed to use struct sockaddr_storage for that instead.

SOL_IP, SOL_IPV6, SOL_ICMPV6, and other SOL_* socket options are nonportable variants of IPPROTO_*. See also ip(7).

## BUGS
The IPv6 extended API as in RFC 2292 is currently only partly implemented; although the 2.2 kernel has near complete support for receiving options, the macros for generating IPv6 options are missing in glibc 2.1.

IPSec support for EH and AH headers is missing.

Flow label management is not complete and not documented here.

This man page is not complete.

## SEE ALSO
cmsg(3), ip(7)

RFC 2553: IPv6 BASIC API; Linux tries to be compliant to this. RFC 2460: IPv6 specification.


title: iso_8859-1(7)

text:
# iso_8859-1(7)

## NAME
iso_8859-1 - ISO 8859-1 character set encoded in octal, decimal, and hexadecimal

## DESCRIPTION
The ISO 8859 standard includes several 8-bit extensions to the ASCII character set (also known as ISO 646-IRV). ISO 8859-1 encodes the characters used in many West European languages.

### ISO 8859 alphabets
The full set of ISO 8859 alphabets includes:

ISO 8859-1

West European languages (Latin-1)

ISO 8859-2

Central and East European languages (Latin-2)

ISO 8859-3

Southeast European and miscellaneous languages (Latin-3)

ISO 8859-4

Scandinavian/Baltic languages (Latin-4)

ISO 8859-5

Latin/Cyrillic

ISO 8859-6

Latin/Arabic

ISO 8859-7

Latin/Greek

ISO 8859-8

Latin/Hebrew

ISO 8859-9

Latin-1 modification for Turkish (Latin-5)

ISO 8859-10

Lappish/Nordic/Eskimo languages (Latin-6)

ISO 8859-11

Latin/Thai

ISO 8859-13

Baltic Rim languages (Latin-7)

ISO 8859-14

Celtic (Latin-8)

ISO 8859-15

West European languages (Latin-9)

ISO 8859-16

Romanian (Latin-10)

### ISO 8859-1 characters
The following table displays the characters in ISO 8859-1 that are printable and unlisted in the ascii(7) manual page.

Oct

Dec

Hex

Char

Description

240

160

A0

NO-BREAK SPACE

241

161

A1

¡

INVERTED EXCLAMATION MARK

242

162

A2

¢

CENT SIGN

243

163

A3

£

POUND SIGN

244

164

A4

¤

CURRENCY SIGN

245

165

A5

¥

YEN SIGN

246

166

A6

¦

BROKEN BAR

247

167

A7

§

SECTION SIGN

250

168

A8

¨

DIAERESIS

251

169

A9

©

COPYRIGHT SIGN

252

170

AA

ª

FEMININE ORDINAL INDICATOR

253

171

AB

«

LEFT-POINTING DOUBLE ANGLE QUOTATION MARK

254

172

AC

¬

NOT SIGN

255

173

AD

SOFT HYPHEN

256

174

AE

®

REGISTERED SIGN

257

175

AF

¯

MACRON

260

176

B0

°

DEGREE SIGN

261

177

B1

±

PLUS-MINUS SIGN

262

178

B2

²

SUPERSCRIPT TWO

263

179

B3

³

SUPERSCRIPT THREE

264

180

B4

´

ACUTE ACCENT

265

181

B5

µ

MICRO SIGN

266

182

B6

¶

PILCROW SIGN

267

183

B7

·

MIDDLE DOT

270

184

B8

¸

CEDILLA

271

185

B9

¹

SUPERSCRIPT ONE

272

186

BA

º

MASCULINE ORDINAL INDICATOR

273

187

BB

»

RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK

274

188

BC

¼

VULGAR FRACTION ONE QUARTER

275

189

BD

½

VULGAR FRACTION ONE HALF

276

190

BE

¾

VULGAR FRACTION THREE QUARTERS

277

191

BF

¿

INVERTED QUESTION MARK

300

192

C0

À

LATIN CAPITAL LETTER A WITH GRAVE

301

193

C1

Á

LATIN CAPITAL LETTER A WITH ACUTE

302

194

C2

Â

LATIN CAPITAL LETTER A WITH CIRCUMFLEX

303

195

C3

Ã

LATIN CAPITAL LETTER A WITH TILDE

304

196

C4

Ä

LATIN CAPITAL LETTER A WITH DIAERESIS

305

197

C5

Å

LATIN CAPITAL LETTER A WITH RING ABOVE

306

198

C6

Æ

LATIN CAPITAL LETTER AE

307

199

C7

Ç

LATIN CAPITAL LETTER C WITH CEDILLA

310

200

C8

È

LATIN CAPITAL LETTER E WITH GRAVE

311

201

C9

É

LATIN CAPITAL LETTER E WITH ACUTE

312

202

CA

Ê

LATIN CAPITAL LETTER E WITH CIRCUMFLEX

313

203

CB

Ë

LATIN CAPITAL LETTER E WITH DIAERESIS

314

204

CC

Ì

LATIN CAPITAL LETTER I WITH GRAVE

315

205

CD

Í

LATIN CAPITAL LETTER I WITH ACUTE

316

206

CE

Î

LATIN CAPITAL LETTER I WITH CIRCUMFLEX

317

207

CF

Ï

LATIN CAPITAL LETTER I WITH DIAERESIS

320

208

D0

Ð

LATIN CAPITAL LETTER ETH

321

209

D1

Ñ

LATIN CAPITAL LETTER N WITH TILDE

322

210

D2

Ò

LATIN CAPITAL LETTER O WITH GRAVE

323

211

D3

Ó

LATIN CAPITAL LETTER O WITH ACUTE

324

212

D4

Ô

LATIN CAPITAL LETTER O WITH CIRCUMFLEX

325

213

D5

Õ

LATIN CAPITAL LETTER O WITH TILDE

326

214

D6

Ö

LATIN CAPITAL LETTER O WITH DIAERESIS

327

215

D7

×

MULTIPLICATION SIGN

330

216

D8

Ø

LATIN CAPITAL LETTER O WITH STROKE

331

217

D9

Ù

LATIN CAPITAL LETTER U WITH GRAVE

332

218

DA

Ú

LATIN CAPITAL LETTER U WITH ACUTE

333

219

DB

Û

LATIN CAPITAL LETTER U WITH CIRCUMFLEX

334

220

DC

Ü

LATIN CAPITAL LETTER U WITH DIAERESIS

335

221

DD

Ý

LATIN CAPITAL LETTER Y WITH ACUTE

336

222

DE

Þ

LATIN CAPITAL LETTER THORN

337

223

DF

ß

LATIN SMALL LETTER SHARP S

340

224

E0

à

LATIN SMALL LETTER A WITH GRAVE

341

225

E1

á

LATIN SMALL LETTER A WITH ACUTE

342

226

E2

â

LATIN SMALL LETTER A WITH CIRCUMFLEX

343

227

E3

ã

LATIN SMALL LETTER A WITH TILDE

344

228

E4

ä

LATIN SMALL LETTER A WITH DIAERESIS

345

229

E5

å

LATIN SMALL LETTER A WITH RING ABOVE

346

230

E6

æ

LATIN SMALL LETTER AE

347

231

E7

ç

LATIN SMALL LETTER C WITH CEDILLA

350

232

E8

è

LATIN SMALL LETTER E WITH GRAVE

351

233

E9

é

LATIN SMALL LETTER E WITH ACUTE

352

234

EA

ê

LATIN SMALL LETTER E WITH CIRCUMFLEX

353

235

EB

ë

LATIN SMALL LETTER E WITH DIAERESIS

354

236

EC

ì

LATIN SMALL LETTER I WITH GRAVE

355

237

ED

í

LATIN SMALL LETTER I WITH ACUTE

356

238

EE

î

LATIN SMALL LETTER I WITH CIRCUMFLEX

357

239

EF

ï

LATIN SMALL LETTER I WITH DIAERESIS

360

240

F0

ð

LATIN SMALL LETTER ETH

361

241

F1

ñ

LATIN SMALL LETTER N WITH TILDE

362

242

F2

ò

LATIN SMALL LETTER O WITH GRAVE

363

243

F3

ó

LATIN SMALL LETTER O WITH ACUTE

364

244

F4

ô

LATIN SMALL LETTER O WITH CIRCUMFLEX

365

245

F5

õ

LATIN SMALL LETTER O WITH TILDE

366

246

F6

ö

LATIN SMALL LETTER O WITH DIAERESIS

367

247

F7

÷

DIVISION SIGN

370

248

F8

ø

LATIN SMALL LETTER O WITH STROKE

371

249

F9

ù

LATIN SMALL LETTER U WITH GRAVE

372

250

FA

ú

LATIN SMALL LETTER U WITH ACUTE

373

251

FB

û

LATIN SMALL LETTER U WITH CIRCUMFLEX

374

252

FC

ü

LATIN SMALL LETTER U WITH DIAERESIS

375

253

FD

ý

LATIN SMALL LETTER Y WITH ACUTE

376

254

FE

þ

LATIN SMALL LETTER THORN

377

255

FF

ÿ

LATIN SMALL LETTER Y WITH DIAERESIS

## NOTES
ISO 8859-1 is also known as Latin-1.

## SEE ALSO
ascii(7), charsets(7), cp1252(7), iso_8859-15(7), utf-8(7)


title: iso_8859-10(7)

text:
# iso_8859-10(7)

## NAME
iso_8859-10 - ISO 8859-10 character set encoded in octal, decimal, and hexadecimal

## DESCRIPTION
The ISO 8859 standard includes several 8-bit extensions to the ASCII character set (also known as ISO 646-IRV). ISO 8859-10 encodes the characters used in Nordic languages.

### ISO 8859 alphabets
The full set of ISO 8859 alphabets includes:

ISO 8859-1

West European languages (Latin-1)

ISO 8859-2

Central and East European languages (Latin-2)

ISO 8859-3

Southeast European and miscellaneous languages (Latin-3)

ISO 8859-4

Scandinavian/Baltic languages (Latin-4)

ISO 8859-5

Latin/Cyrillic

ISO 8859-6

Latin/Arabic

ISO 8859-7

Latin/Greek

ISO 8859-8

Latin/Hebrew

ISO 8859-9

Latin-1 modification for Turkish (Latin-5)

ISO 8859-10

Lappish/Nordic/Eskimo languages (Latin-6)

ISO 8859-11

Latin/Thai

ISO 8859-13

Baltic Rim languages (Latin-7)

ISO 8859-14

Celtic (Latin-8)

ISO 8859-15

West European languages (Latin-9)

ISO 8859-16

Romanian (Latin-10)

### ISO 8859-10 characters
The following table displays the characters in ISO 8859-10 that are printable and unlisted in the ascii(7) manual page.

Oct

Dec

Hex

Char

Description

240

160

A0

NO-BREAK SPACE

241

161

A1

Ą

LATIN CAPITAL LETTER A WITH OGONEK

242

162

A2

Ē

LATIN CAPITAL LETTER E WITH MACRON

243

163

A3

Ģ

LATIN CAPITAL LETTER G WITH CEDILLA

244

164

A4

Ī

LATIN CAPITAL LETTER I WITH MACRON

245

165

A5

Ĩ

LATIN CAPITAL LETTER I WITH TILDE

246

166

A6

Ķ

LATIN CAPITAL LETTER K WITH CEDILLA

247

167

A7

§

SECTION SIGN

250

168

A8

Ļ

LATIN CAPITAL LETTER L WITH CEDILLA

251

169

A9

Đ

LATIN CAPITAL LETTER D WITH STROKE

252

170

AA

Š

LATIN CAPITAL LETTER S WITH CARON

253

171

AB

Ŧ

LATIN CAPITAL LETTER T WITH STROKE

254

172

AC

Ž

LATIN CAPITAL LETTER Z WITH CARON

255

173

AD

SOFT HYPHEN

256

174

AE

Ū

LATIN CAPITAL LETTER U WITH MACRON

257

175

AF

Ŋ

LATIN CAPITAL LETTER ENG

260

176

B0

°

DEGREE SIGN

261

177

B1

ą

LATIN SMALL LETTER A WITH OGONEK

262

178

B2

ē

LATIN SMALL LETTER E WITH MACRON

263

179

B3

ģ

LATIN SMALL LETTER G WITH CEDILLA

264

180

B4

ī

LATIN SMALL LETTER I WITH MACRON

265

181

B5

ĩ

LATIN SMALL LETTER I WITH TILDE

266

182

B6

ķ

LATIN SMALL LETTER K WITH CEDILLA

267

183

B7

·

MIDDLE DOT

270

184

B8

ļ

LATIN SMALL LETTER L WITH CEDILLA

271

185

B9

đ

LATIN SMALL LETTER D WITH STROKE

272

186

BA

š

LATIN SMALL LETTER S WITH CARON

273

187

BB

ŧ

LATIN SMALL LETTER T WITH STROKE

274

188

BC

ž

LATIN SMALL LETTER Z WITH CARON

275

189

BD

―

HORIZONTAL BAR

276

190

BE

ū

LATIN SMALL LETTER U WITH MACRON

277

191

BF

ŋ

LATIN SMALL LETTER ENG

300

192

C0

Ā

LATIN CAPITAL LETTER A WITH MACRON

301

193

C1

Á

LATIN CAPITAL LETTER A WITH ACUTE

302

194

C2

Â

LATIN CAPITAL LETTER A WITH CIRCUMFLEX

303

195

C3

Ã

LATIN CAPITAL LETTER A WITH TILDE

304

196

C4

Ä

LATIN CAPITAL LETTER A WITH DIAERESIS

305

197

C5

Å

LATIN CAPITAL LETTER A WITH RING ABOVE

306

198

C6

Æ

LATIN CAPITAL LETTER AE

307

199

C7

Į

LATIN CAPITAL LETTER I WITH OGONEK

310

200

C8

Č

LATIN CAPITAL LETTER C WITH CARON

311

201

C9

É

LATIN CAPITAL LETTER E WITH ACUTE

312

202

CA

Ę

LATIN CAPITAL LETTER E WITH OGONEK

312

202

CB

Ë

LATIN CAPITAL LETTER E WITH DIAERESIS

314

204

CC

Ė

LATIN CAPITAL LETTER E WITH DOT ABOVE

315

205

CD

Í

LATIN CAPITAL LETTER I WITH ACUTE

316

206

CE

Î

LATIN CAPITAL LETTER I WITH CIRCUMFLEX

317

207

CF

Ï

LATIN CAPITAL LETTER I WITH DIAERESIS

320

208

D0

Ð

LATIN CAPITAL LETTER ETH

321

209

D1

Ņ

LATIN CAPITAL LETTER N WITH CEDILLA

322

210

D2

Ō

LATIN CAPITAL LETTER O WITH MACRON

323

211

D3

Ó

LATIN CAPITAL LETTER O WITH ACUTE

324

212

D4

Ô

LATIN CAPITAL LETTER O WITH CIRCUMFLEX

325

213

D5

Õ

LATIN CAPITAL LETTER O WITH TILDE

326

214

D6

Ö

LATIN CAPITAL LETTER O WITH DIAERESIS

327

215

D7

Ũ

LATIN CAPITAL LETTER U WITH TILDE

330

216

D8

Ø

LATIN CAPITAL LETTER O WITH STROKE

331

217

D9

Ų

LATIN CAPITAL LETTER U WITH OGONEK

332

218

DA

Ú

LATIN CAPITAL LETTER U WITH ACUTE

333

219

DB

Û

LATIN CAPITAL LETTER U WITH CIRCUMFLEX

334

220

DC

Ü

LATIN CAPITAL LETTER U WITH DIAERESIS

335

221

DD

Ý

LATIN CAPITAL LETTER Y WITH ACUTE

336

222

DE

Þ

LATIN CAPITAL LETTER THORN

337

223

DF

ß

LATIN SMALL LETTER SHARP S

340

224

E0

ā

LATIN SMALL LETTER A WITH MACRON

341

225

E1

á

LATIN SMALL LETTER A WITH ACUTE

342

226

E2

â

LATIN SMALL LETTER A WITH CIRCUMFLEX

343

227

E3

ã

LATIN SMALL LETTER A WITH TILDE

344

228

E4

ä

LATIN SMALL LETTER A WITH DIAERESIS

345

229

E5

å

LATIN SMALL LETTER A WITH RING ABOVE

346

230

E6

æ

LATIN SMALL LETTER AE

347

231

E7

į

LATIN SMALL LETTER I WITH OGONEK

350

232

E8

č

LATIN SMALL LETTER C WITH CARON

351

233

E9

é

LATIN SMALL LETTER E WITH ACUTE

352

234

EA

ę

LATIN SMALL LETTER E WITH OGONEK

353

235

EB

ë

LATIN SMALL LETTER E WITH DIAERESIS

354

236

EC

ė

LATIN SMALL LETTER E WITH DOT ABOVE

355

237

ED

í

LATIN SMALL LETTER I WITH ACUTE

356

238

EE

î

LATIN SMALL LETTER I WITH CIRCUMFLEX

357

239

EF

ï

LATIN SMALL LETTER I WITH DIAERESIS

360

240

F0

ð

LATIN SMALL LETTER ETH

361

241

F1

ņ

LATIN SMALL LETTER N WITH CEDILLA

362

242

F2

ō

LATIN SMALL LETTER O WITH MACRON

363

243

F3

ó

LATIN SMALL LETTER O WITH ACUTE

364

244

F4

ô

LATIN SMALL LETTER O WITH CIRCUMFLEX

365

245

F5

õ

LATIN SMALL LETTER O WITH TILDE

366

246

F6

ö

LATIN SMALL LETTER O WITH DIAERESIS

367

247

F7

ũ

LATIN SMALL LETTER U WITH TILDE

370

248

F8

ø

LATIN SMALL LETTER O WITH STROKE

371

249

F9

ų

LATIN SMALL LETTER U WITH OGONEK

372

250

FA

ú

LATIN SMALL LETTER U WITH ACUTE

373

251

FB

û

LATIN SMALL LETTER U WITH CIRCUMFLEX

374

252

FC

ü

LATIN SMALL LETTER U WITH DIAERESIS

375

253

FD

ý

LATIN SMALL LETTER Y WITH ACUTE

376

254

FE

þ

LATIN SMALL LETTER THORN

377

255

FF

ĸ

LATIN SMALL LETTER KRA

## NOTES
ISO 8859-10 is also known as Latin-6.

## SEE ALSO
ascii(7), charsets(7), utf-8(7)