---
name: "setfib"
section: "2"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/setfib/2"
---

# setfib(2)

set the default FIB (routing table) for the calling process

## NAME

**setfib** – set the default FIB (routing table) for the calling process

## LIBRARY

Standard C Library (libc, -lc)

## SYNOPSIS

**#include \<sys/socket.h\>**

*int*\

**setfib**(*int fib*);

## DESCRIPTION

The **setfib**() system call sets the associated FIB (routing table) for all sockets opened subsequent to the call, to be that of the argument *fib*. The *fib* argument must be greater than or equal to 0 and less than the current system maximum which may be retrieved by the *net.fibs* sysctl. The system maximum is set in the kernel configuration file with

**options ROUTETABLES=***N*

or in */boot/loader.conf* or */etc/sysctl.conf* with

```
net.fibs="N"
```

where *N* is an integer smaller than 65536. Note that the number of FIBs may be increased after booting, but cannot be reduced.

The maximum of 65536 is due to the implementation storing the FIB number in a 16-bit field in the [mbuf(9)](/mbuf/9.md) packet header, however it is not suggested that one use such a large number as memory is allocated for every FIB regardless of whether it is used, and there are places where all FIBs are iterated over.

The default FIB of the process will be applied to all protocol families that support multiple FIBs, and ignored by those that do not. The default FIB for a process may be overridden for a socket with the use of the SO\_SETFIB socket option.

## RETURN VALUES

The **setfib()** function returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error.

## ERRORS

The **setfib**() system call will fail and no action will be taken and return EINVAL if the *fib* argument is greater than the current system maximum.

## SEE ALSO

[setfib(1)](/setfib/1.md), [setsockopt(2)](/setsockopt/2.md)

## STANDARDS

The **setfib**() system call is a FreeBSD extension however similar extensions have been added to many other UNIX style kernels.

## HISTORY

The **setfib**() function appeared in FreeBSD 7.1.
