Full Code of rsmarples/dhcpcd for AI

master 9a298fd9b45e cached
158 files
1.5 MB
495.4k tokens
2109 symbols
1 requests
Download .txt
Showing preview only (1,567K chars total). Download the full file or copy to clipboard to get everything.
Repository: rsmarples/dhcpcd
Branch: master
Commit: 9a298fd9b45e
Files: 158
Total size: 1.5 MB

Directory structure:
gitextract_70kvohjb/

├── .clang-format
├── .clang-tidy
├── .clangd
├── .github/
│   └── workflows/
│       ├── build.yml
│       └── format.yml
├── .gitignore
├── BUILDING.md
├── LICENSE
├── Makefile
├── Makefile.inc
├── README.md
├── compat/
│   ├── _strtoi.h
│   ├── arc4random.c
│   ├── arc4random.h
│   ├── arc4random_uniform.c
│   ├── arc4random_uniform.h
│   ├── bitops.h
│   ├── chacha_private.h
│   ├── closefrom.c
│   ├── closefrom.h
│   ├── consttime_memequal.h
│   ├── crypt/
│   │   ├── hmac.c
│   │   ├── hmac.h
│   │   ├── md5.c
│   │   ├── md5.h
│   │   ├── sha256.c
│   │   └── sha256.h
│   ├── crypt_openssl/
│   │   ├── hmac.c
│   │   ├── hmac.h
│   │   ├── sha256.c
│   │   └── sha256.h
│   ├── dprintf.c
│   ├── dprintf.h
│   ├── endian.h
│   ├── pidfile.c
│   ├── pidfile.h
│   ├── queue.h
│   ├── reallocarray.c
│   ├── reallocarray.h
│   ├── setproctitle.c
│   ├── setproctitle.h
│   ├── strlcpy.c
│   ├── strlcpy.h
│   ├── strtoi.c
│   ├── strtoi.h
│   └── strtou.c
├── config-null.mk
├── configure
├── hooks/
│   ├── 01-test
│   ├── 10-wpa_supplicant
│   ├── 15-timezone
│   ├── 20-resolv.conf
│   ├── 29-lookup-hostname
│   ├── 30-hostname.in
│   ├── 50-dhcpcd-compat
│   ├── 50-ntp.conf
│   ├── 50-timesyncd.conf
│   ├── 50-yp.conf
│   ├── 50-ypbind.in
│   ├── Makefile
│   ├── dhcpcd-run-hooks.8.in
│   └── dhcpcd-run-hooks.in
├── iconfig.mk
├── src/
│   ├── GNUmakefile
│   ├── Makefile
│   ├── Makefile.inc
│   ├── arp.c
│   ├── arp.h
│   ├── auth.c
│   ├── auth.h
│   ├── bpf-bsd.c
│   ├── bpf-dlpi.c
│   ├── bpf-dlpi.h
│   ├── bpf-linux.c
│   ├── bpf-pcap.c
│   ├── bpf.c
│   ├── bpf.h
│   ├── common.c
│   ├── common.h
│   ├── control.c
│   ├── control.h
│   ├── defs.h
│   ├── dev/
│   │   ├── Makefile
│   │   └── udev.c
│   ├── dev.c
│   ├── dev.h
│   ├── dhcp-common.c
│   ├── dhcp-common.h
│   ├── dhcp.c
│   ├── dhcp.h
│   ├── dhcp6.c
│   ├── dhcp6.h
│   ├── dhcpcd-definitions-small.conf
│   ├── dhcpcd-definitions.conf
│   ├── dhcpcd-embedded.c.in
│   ├── dhcpcd-embedded.h.in
│   ├── dhcpcd.8.in
│   ├── dhcpcd.c
│   ├── dhcpcd.conf
│   ├── dhcpcd.conf.5.in
│   ├── dhcpcd.h
│   ├── duid.c
│   ├── duid.h
│   ├── eloop.c
│   ├── eloop.h
│   ├── genembedc
│   ├── genembedh
│   ├── if-bsd.c
│   ├── if-linux-wext.c
│   ├── if-linux.c
│   ├── if-options.c
│   ├── if-options.h
│   ├── if-sun.c
│   ├── if.c
│   ├── if.h
│   ├── ipv4.c
│   ├── ipv4.h
│   ├── ipv4ll.c
│   ├── ipv4ll.h
│   ├── ipv6.c
│   ├── ipv6.h
│   ├── ipv6nd.c
│   ├── ipv6nd.h
│   ├── logerr.c
│   ├── logerr.h
│   ├── privsep-bpf.c
│   ├── privsep-bpf.h
│   ├── privsep-bsd.c
│   ├── privsep-control.c
│   ├── privsep-control.h
│   ├── privsep-inet.c
│   ├── privsep-inet.h
│   ├── privsep-linux.c
│   ├── privsep-root.c
│   ├── privsep-root.h
│   ├── privsep-sun.c
│   ├── privsep.c
│   ├── privsep.h
│   ├── queue.h
│   ├── route.c
│   ├── route.h
│   ├── sa.c
│   ├── sa.h
│   ├── script.c
│   └── script.h
├── tests/
│   ├── Makefile
│   └── crypt/
│       ├── .gitignore
│       ├── GNUmakefile
│       ├── Makefile
│       ├── README.md
│       ├── run-test.c
│       ├── test.h
│       ├── test_hmac_md5.c
│       └── test_sha256.c
└── vendor/
    ├── README.md
    ├── queue.h
    ├── rbtree.c
    └── rbtree.h

================================================
FILE CONTENTS
================================================

================================================
FILE: .clang-format
================================================
# Basic .clang-format taken from FreeBSD
---
BasedOnStyle: WebKit
AlignAfterOpenBracket: DontAlign
AlignConsecutiveMacros: AcrossEmptyLines
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: false
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: InlineOnly
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: TopLevelDefinitions
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: true
BinPackParameters: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: WebKit
BreakBeforeTernaryOperators: false
# TODO: BreakStringLiterals can cause very strange formatting so turn it off?
BreakStringLiterals: false
# Prefer:
# some_var = function(arg1,
#    arg2)
# over:
# some_var =
#     function(arg1, arg2)
PenaltyBreakAssignment: 100
# Prefer:
# some_long_function(arg1, arg2
#     arg3)
# over:
# some_long_function(
#     arg1, arg2, arg3)
PenaltyBreakBeforeFirstCallParameter: 100
CompactNamespaces: true
DerivePointerAlignment: false
DisableFormat: false
ForEachMacros:
  - ARB_ARRFOREACH
  - ARB_ARRFOREACH_REVWCOND
  - ARB_ARRFOREACH_REVERSE
  - ARB_FOREACH
  - ARB_FOREACH_FROM
  - ARB_FOREACH_SAFE
  - ARB_FOREACH_REVERSE
  - ARB_FOREACH_REVERSE_FROM
  - ARB_FOREACH_REVERSE_SAFE
  - BIT_FOREACH_ISCLR
  - BIT_FOREACH_ISSET
  - CPU_FOREACH
  - CPU_FOREACH_ISCLR
  - CPU_FOREACH_ISSET
  - FOREACH_THREAD_IN_PROC
  - FOREACH_PROC_IN_SYSTEM
  - FOREACH_PRISON_CHILD
  - FOREACH_PRISON_DESCENDANT
  - FOREACH_PRISON_DESCENDANT_LOCKED
  - FOREACH_PRISON_DESCENDANT_LOCKED_LEVEL
  - MNT_VNODE_FOREACH_ALL
  - MNT_VNODE_FOREACH_ACTIVE
  - RB_FOREACH
  - RB_FOREACH_FROM
  - RB_FOREACH_SAFE
  - RB_FOREACH_REVERSE
  - RB_FOREACH_REVERSE_FROM
  - RB_FOREACH_REVERSE_SAFE
  - SLIST_FOREACH
  - SLIST_FOREACH_FROM
  - SLIST_FOREACH_FROM_SAFE
  - SLIST_FOREACH_SAFE
  - SLIST_FOREACH_PREVPTR
  - SPLAY_FOREACH
  - LIST_FOREACH
  - LIST_FOREACH_FROM
  - LIST_FOREACH_FROM_SAFE
  - LIST_FOREACH_SAFE
  - STAILQ_FOREACH
  - STAILQ_FOREACH_FROM
  - STAILQ_FOREACH_FROM_SAFE
  - STAILQ_FOREACH_SAFE
  - TAILQ_FOREACH
  - TAILQ_FOREACH_FROM
  - TAILQ_FOREACH_FROM_SAFE
  - TAILQ_FOREACH_REVERSE
  - TAILQ_FOREACH_REVERSE_FROM
  - TAILQ_FOREACH_REVERSE_FROM_SAFE
  - TAILQ_FOREACH_REVERSE_SAFE
  - TAILQ_FOREACH_SAFE
  - VM_MAP_ENTRY_FOREACH
  - VM_PAGE_DUMP_FOREACH
SpaceBeforeParens: ControlStatementsExceptForEachMacros
IndentCaseLabels: false
IndentPPDirectives: None
Language: Cpp
NamespaceIndentation: None
PointerAlignment: Right
ContinuationIndentWidth: 4
IndentWidth: 8
TabWidth: 8
ColumnLimit: 80
UseTab: Always
SpaceAfterCStyleCast: false
IncludeBlocks: Regroup
IncludeCategories:
  - Regex: '^\"opt_.*\.h\"'
    Priority: 1
    SortPriority: 10
  - Regex: '^<sys/cdefs\.h>'
    Priority: 2
    SortPriority: 20
  - Regex: '^<sys/types\.h>'
    Priority: 2
    SortPriority: 21
  - Regex: '^<sys/param\.h>'
    Priority: 2
    SortPriority: 22
  - Regex: '^<sys/systm\.h>'
    Priority: 2
    SortPriority: 23
  - Regex: '^<sys.*/'
    Priority: 2
    SortPriority: 24
  - Regex: '^<vm/vm\.h>'
    Priority: 3
    SortPriority: 30
  - Regex: '^<vm/'
    Priority: 3
    SortPriority: 31
  - Regex: '^<machine/'
    Priority: 4
    SortPriority: 40
  - Regex: '^<(x86|amd64|i386|xen)/'
    Priority: 5
    SortPriority: 50
  - Regex: '^<dev/'
    Priority: 6
    SortPriority: 60
# Most BSD require <netinet/in.h> before this ...
  - Regex: '^<netinet/if_ether.h>'
    Priority: 7
    SortPriority:  71
# Most BSD require <netinet/in.h> before this ...
  - Regex: '^<netinet/icmp6.h>'
    Priority: 7
    SortPriority:  71
  - Regex: '^<net.*/'
    Priority: 7
    SortPriority: 70
  - Regex: '^<protocols/'
    Priority: 7
    SortPriority: 72
  - Regex: '^<(fs|nfs(|client|server)|ufs)/'
    Priority: 8
    SortPriority: 80
  - Regex: '^<[^/].*\.h'
    Priority: 9
    SortPriority: 90
  - Regex: '^\".*\.h\"'
    Priority: 10
    SortPriority: 100
# LLVM's header include ordering style is almost the exact opposite of ours.
# Unfortunately, they have hard-coded their preferences into clang-format.
# Clobbering this regular expression to avoid matching prevents non-system
# headers from being forcibly moved to the top of the include list.
# http://llvm.org/docs/CodingStandards.html#include-style
IncludeIsMainRegex: 'BLAH_DONT_MATCH_ANYTHING'
SortIncludes: true
KeepEmptyLinesAtTheStartOfBlocks: false
TypenameMacros:
  - ARB_ELMTYPE
  - ARB_HEAD
  - ARB8_HEAD
  - ARB16_HEAD
  - ARB32_HEAD
  - ARB_ENTRY
  - ARB8_ENTRY
  - ARB16_ENTRY
  - ARB32_ENTRY
  - LIST_CLASS_ENTRY
  - LIST_CLASS_HEAD
  - LIST_ENTRY
  - LIST_HEAD
  - QUEUE_TYPEOF
  - RB_ENTRY
  - RB_HEAD
  - SLIST_CLASS_HEAD
  - SLIST_CLASS_ENTRY
  - SLIST_HEAD
  - SLIST_ENTRY
  - SMR_POINTER
  - SPLAY_ENTRY
  - SPLAY_HEAD
  - STAILQ_CLASS_ENTRY
  - STAILQ_CLASS_HEAD
  - STAILQ_ENTRY
  - STAILQ_HEAD
  - TAILQ_CLASS_ENTRY
  - TAILQ_CLASS_HEAD
  - TAILQ_ENTRY
  - TAILQ_HEAD


================================================
FILE: .clang-tidy
================================================
# Disable DeprecatedOrUnsafeBufferHandling - our use of these is fine
# and musl does not support the the _s variants.
# Disable valist due to clang-tidy bug fixed in v19?
Checks: "cert-*,-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,-clang-analyzer-valist.Uninitialized"
HeaderFilterRegex: ".*"


================================================
FILE: .clangd
================================================
If:
  PathMatch: src/dev/.*\.c
CompileFlags:
  Add: [-I.., -I../.., -I../../compat, -I../../vendor]
---
If:
  PathMatch: src/.*\.(c|h)
CompileFlags:
  Add: [-I.., -I../compat, -I../vendor]
---
CompileFlags:
  Add: [-DINET, -DARP, -DARPING, -DIPV4LL, -DINET6, -DDHCP6, -DPLUGIN_DEV, -DAUTH, -DPRIVSEP]


================================================
FILE: .github/workflows/build.yml
================================================
name: Build

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

env:
  CC: clang

jobs:
  ubuntu:
    strategy:
      matrix:
        os: [ ubuntu-latest, ubuntu-22.04 ]
    runs-on: ${{ matrix.os }}

    steps:
    - uses: actions/checkout@v2
    
    - name: Configure
      run: ./configure

    - name: Build
      run: make

    - name: Tests
      run: make tests

  # Sadly the BSDs have stopped building ....
  
  # openbsd:
  #   runs-on: ubuntu-latest
  #   steps:
  #   - name: Bootstrap OpenBSD-latest
  #     uses: mario-campos/emulate@v1
  #     with:
  #       operating-system: openbsd-latest

  #   - name: Install Dependencies
  #     run: pkg_add git

  #   - name: Build
  #     run: |
  #       git clone --depth=1 "${{ github.server_url }}/${{ github.repository }}" build
  #       cd build
  #       [ "${{ github.event.pull_request.number }}" = "" ] || (echo "fetching PR ${{ github.event.pull_request.number }}"; git fetch origin pull/${{ github.event.pull_request.number }}/head:pr-${{ github.event.pull_request.number }} && git checkout "pr-${{ github.event.pull_request.number }}")
  #       ./configure
  #       make

  #   - name: Tests
  #     run: |
  #       ulimit -n 1024
  #       cd build
  #       make tests

  # freebsd:
  #   runs-on: ubuntu-latest
  #   steps:
  #   - name: Bootstrap FreeBSD-latest
  #     uses: mario-campos/emulate@v1
  #     with:
  #       operating-system: freebsd-latest

  #   - name: Install Dependencies
  #     run: pkg install -y git

  #   - name: Build
  #     run: |
  #       git clone --depth=1 "${{ github.server_url }}/${{ github.repository }}" build
  #       cd build
  #       [ "${{ github.event.pull_request.number }}" = "" ] || (echo "fetching PR ${{ github.event.pull_request.number }}"; git fetch origin pull/${{ github.event.pull_request.number }}/head:pr-${{ github.event.pull_request.number }} && git checkout "pr-${{ github.event.pull_request.number }}")
  #       ./configure
  #       make

  #   - name: Tests
  #     run: |
  #        cd build
  #        make tests

  # netbsd:
  #   strategy:
  #     matrix:
  #       args:
  #         -
  #         - --disable-ipv4
  #         - --disable-arp
  #         - --disable-ipv4ll
  #         - --disable-ipv6
  #         - --disable-dhcp6
  #       cppflags:
  #         -
  #         - -DSMALL
  #   runs-on: ubuntu-latest
  #   steps:
  #   - name: Bootstrap NetBSD-latest
  #     uses: mario-campos/emulate@v1
  #     with:
  #       operating-system: netbsd-latest

  #   - name: Build
  #     run: |
  #       git clone --depth=1 "${{ github.server_url }}/${{ github.repository }}" build
  #       cd build
  #       [ "${{ github.event.pull_request.number }}" = "" ] || (echo "fetching PR ${{ github.event.pull_request.number }}"; git fetch origin pull/${{ github.event.pull_request.number }}/head:pr-${{ github.event.pull_request.number }} && git checkout "pr-${{ github.event.pull_request.number }}")
  #       CFLAGS=-Werror CPPFLAGS="${{ matrix.cppflags }}" ./configure ${{ matrix.args }}
  #       make

  #   - name: Tests
  #     run: |
  #       cd build
  #       make tests


================================================
FILE: .github/workflows/format.yml
================================================
name: Clang Format Checker
on:
  push:
  pull_request:
    branches: [master]
jobs:
  clang-format-checking:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
        # This is pinned to clang-format v19
      - uses: RafikFarhad/clang-format-github-action@v5
        with:
          style: "file"
          sources: "src/**/*.h,src/**/*.c"


================================================
FILE: .gitignore
================================================
# Ignore configure generated files
config.h
config.mk
config.log

# Ignore object files
.depend
*.o
*.So
*.so
dhcpcd

# Ignore generated embedded files
dhcpcd-embedded.c
dhcpcd-embedded.h

# Ignore generated man pages and scripts
dhcpcd.8
dhcpcd-run-hooks
dhcpcd-run-hooks.8
dhcpcd.conf.5
hooks/30-hostname
hooks/50-ypbind

# Ignore distribution
dhcpcd*.xz*

# Ignore patch files
*.diff
*.patch
*.orig
*.rej

# Ignore swap files
*.swp

# Ignore Coverity
cov-int

# Ignore VSCode
.vscode

# Ignore macOS hidden files
.DS_Store


================================================
FILE: BUILDING.md
================================================
<!-- SPDX-License-Identifier: BSD-2-Clause -->
<!-- Copyright (c) 2017-2025 Roy Marples <roy@marples.name> -->

# Building dhcpcd

This attempts to document various ways of building dhcpcd for your
platform.
`./configure` is a POSIX shell script that works in a similar way
to GNU configure.
This works fine provided you don't force any exotic options down
which may or may not be silently discarded.

Some build time warnings are expected - the only platforms with zero
warnings are DragonFlyBSD and NetBSD.
It is expected that the platforms be improvded to support dhcpcd
better.
There maybe some loss of functionality, but for the most part,
dhcpcd can work around these deficiencies.

## Size is an issue
To compile small dhcpcd, maybe to be used for installation media where
size is a concern, you can use the `--small` configure option to enable
a reduced feature set within dhcpcd.
Currently this just removes non important options out of
`dhcpcd-definitions.conf`, the logfile option,
DHCPv6 Prefix Delegation and IPv6 address announcement *(to prefer an
address on another interface)*.
Other features maybe dropped as and when required.
dhcpcd can also be made smaller by removing the IPv4 or IPv6 stack:
  *  `--disable-inet`
  *  `--disable-inet6`

Or by removing the following features:
  *  `--disable-auth`
  *  `--disable-arp`
  *  `--disable-arping`
  *  `--disable-ipv4ll`
  *  `--disable-dhcp6`
  *  `--disable-privsep`

You can also move the embedded extended configuration from the dhcpcd binary
to an external file (LIBEXECDIR/dhcpcd-definitions.conf)
  *  `--disable-embedded`
If dhcpcd cannot load this file at runtime, dhcpcd will work but will not be
able to decode any DHCP/DHCPv6 options that are not defined by the user
in /etc/dhcpcd.conf. This does not really change the total on disk size.

## Cross compiling
If you're cross compiling you may need set the platform if OS is different
from the host.  
`--target=sparc-sun-netbsd5.0`

If you're building for an MMU-less system where fork() does not work, you
should `./configure --disable-fork`.
This also puts the `--no-background` flag on and stops the `--background` flag
from working.

## Default directories
You can change the default dirs with these knobs.
For example, to satisfy FHS compliance you would do this:
`./configure --libexecdir=/lib/dhcpcd dbdir=/var/lib/dhcpcd`

## Compile Issues
We now default to using `-std=c99`. For 64-bit linux, this always works, but
for 32-bit linux it requires either gnu99 or a patch to `asm/types.h`.
Most distros patch linux headers so this should work fine.
linux-2.6.24 finally ships with a working 32-bit header.
If your linux headers are older, or your distro hasn't patched them you can
set `CSTD=gnu99` to work around this.

ArchLinux presently sanitises all kernel headers to the latest version
regardless of the version for your CPU. As such, Arch presently ships a
3.12 kernel with 3.17 headers which claim that it supports temporary address
management and no automatic prefix route generation, both of which are
obviously false. You will have to patch support either in the kernel or
out of the headers (or dhcpcd itself) to have correct operation.

Linux netlink headers cause a sign conversion error.
I [submitted a patch](https://lkml.org/lkml/2019/12/17/680),
but as yet it's not upstreamed.

GLIBC ships an icmp6.h header which will result in signedness warnings.
Their [bug #22489](https://sourceware.org/bugzilla/show_bug.cgi?id=22489)
will solve this once it's actually applied.

## OS specific issues
Some BSD systems do not allow the manipulation of automatically added subnet
routes. You can find discussion here:
    http://mail-index.netbsd.org/tech-net/2008/12/03/msg000896.html
BSD systems where this has been fixed or is known to work are:
    NetBSD-5.0
    FreeBSD-10.0

Some BSD systems protect against IPv6 NS/NA messages by ensuring that the
source address matches a prefix on the recieved by a RA message.
This is an error as the correct check is for on-link prefixes as the
kernel may not be handling RA itself.
BSD systems where this has been fixed or is known to work are:
    NetBSD-7.0
    OpenBSD-5.0
    patch submitted against FreeBSD-10.0

Some BSD systems do not announce IPv6 address flag changes, such as
`IN6_IFF_TENTATIVE`, `IN6_IFF_DUPLICATED`, etc. On these systems,
dhcpcd will poll a freshly added address until either `IN6_IFF_TENTATIVE` is
cleared or `IN6_IFF_DUPLICATED` is set and take action accordingly.
BSD systems where this has been fixed or is known to work are:
    NetBSD-7.0

OpenBSD will always add it's own link-local address if no link-local address
exists, because it doesn't check if the address we are adding is a link-local
address or not.

Some BSD systems do not announce cached neighbour route changes based
on reachability to userland. For such systems, IPv6 routers will always
be assumed to be reachable until they either stop being a router or expire.
BSD systems where this has been fixed or is known to work are:
    NetBSD-7.99.3

Linux prior to 3.17 won't allow userland to manage IPv6 temporary addresses.
Either upgrade or don't allow dhcpcd to manage the RA,
so don't set either `ipv6ra_own` or `slaac private` in `dhcpcd.conf` if you
want to have working IPv6 temporary addresses.
SLAAC private addresses are just as private, just stable.

Linux SECCOMP is very dependant on libc vs kernel.
When libc is changed and uses a syscall that dhcpcd is unaware of,
SECCOMP may break dhcpcd.
When this happens you can configure dhcpcd with --disable-seccomp
so dhcpcd can use a POSIX resource limited sandbox with privilege separation
still. If you do this, please report the issue so that we can adjust the
SECCOMP filter so that dhcpcd can use SECCOMP once more.
Or convince the libc/kernel people to adpot something more maintainable
like FreeBSD's capsicum or OpenBSD's pledge.
To test ASAN with privsep you need to add ASAN to CPPFLAGS.
To test Valgrind with privsep you can optionally add VALGRIND to CPPFLAGS.
For both they need some syscalls which are potentially dangerous and thus
are disabled by default.
For Valgrind, it needs to unlink the pipe files which it can't do anyway
as it's dropped permissions. Otherwise it works fine.

Enable libpcap support with --with-libpcap.
This should only be done on systems that lack the needed kernel hooks
as libpcap does not support a write filter and is vulnerable
if the application is exploited.
An upstream PR has been submitted to add `pcap_setwritefilter()` and
`pcap_lockfilter()` to libpcap:
    https://github.com/the-tcpdump-group/libpcap/pull/1683

## Init systems
We try and detect how dhcpcd should interact with system services at runtime.
If we cannot auto-detect how do to this, or it is wrong then
you can change this by passing shell commands to `--serviceexists`,
`--servicecmd` and optionally `--servicestatus` to `./configure` or overriding
the service variables in a hook.


## /dev management
Some systems have `/dev` management systems and some of these like to rename
interfaces. As this system would listen in the same way as dhcpcd to new
interface arrivals, dhcpcd needs to listen to the `/dev` management sytem
instead of the kernel. However, if the `/dev` management system breaks, stops
working, or changes to a new one, dhcpcd should still try and continue to work.
To facilitate this, dhcpcd allows a plugin to load to instruct dhcpcd when it
can use an interface. As of the time of writing only udev support is included.
You can disable this with `--without-dev`, or `without-udev`.
NOTE: in Gentoo at least, `sys-fs/udev` as provided by systemd leaks memory
`sys-fs/eudev`, the fork of udev does not and as such is recommended.

## crypto
dhcpcd ships with some cryptographic routines taken from various upstreams.
These are routinely monitored and try to be as up to date as possible.
You can optionally configure dhcpcd with `--with-openssl` to use libcrypto
to use these instead.
This is not enabled by default, even if libcrypto is found because libcrypto
generally lives in /usr and dhcpcd in /sbin which could be a separate
filesystem.

## Importing into another source control system
To import the full sources, use the import target.
To import only the needed sources and documentation, use the import-src
target.
Both targets support DESTDIR to set the installation directory,
if unset it defaults to `/tmp/dhcpcd-$VERSION`
Example: `make DESTDIR=/usr/src/contrib/dhcpcd import-src`


## Hooks
Not all the hooks in dhcpcd-hooks are installed by default.
By default we install `01-test`, `20-resolv.conf`and `30-hostname`.
The other hooks, `10-wpa_supplicant`, `15-timezone` and `29-lookup-hostname`
are installed to `$(datadir)/dhcpcd/hooks` by default and need to be
copied to `$(libexecdir)/dhcpcd-hooks` for use.
The configure program attempts to find hooks for systems you have installed.
To add more simply
`./configure -with-hook=ntp.conf`

If using resolvconf, the `20-resolv.conf` hook now requires a version with the
`-C` and `-c` options to deprecate and activate interfaces to support wireless
roaming (Linux) or carrier just drops (NetBSD).
If your resolvconf does not support this then you will see a warning
about an illegal option when the carrier changes, but things should still work.
In this instance the DNS information cannot be Deprecated and may not
be optimal for multi-homed hosts.


================================================
FILE: LICENSE
================================================
Copyright (c) 2006-2025 Roy Marples <roy@marples.name>
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in the
   documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.


================================================
FILE: Makefile
================================================
# SPDX-License-Identifier: BSD-2-Clause
# Copyright (c) 2006-2025 Roy Marples <roy@marples.name>

SUBDIRS=	src hooks

PACKAGE=	dhcpcd
VERSION!=	sed -n 's/\#define VERSION[[:space:]]*"\(.*\)".*/\1/p' src/defs.h

DIST!=		if test -d .git; then echo "dist-git"; \
		else echo "dist-inst"; fi
FOSSILID?=	current
GITREF?=	HEAD

DISTSUFFIX=
DISTPREFIX?=	${PACKAGE}-${VERSION}${DISTSUFFIX}
DISTFILE?=	${DISTPREFIX}.tar.xz
DISTINFO=	${DISTFILE}.distinfo
DISTINFOMD=	${DISTINFO}.md
DISTSIGN=	${DISTFILE}.asc

CLEANFILES+=	*.tar.xz

.PHONY:		hooks import import-bsd tests

.SUFFIXES:	.in

all: config.h
	for x in ${SUBDIRS}; do cd $$x; ${MAKE} $@ || exit $$?; cd ..; done

depend: config.h
	for x in ${SUBDIRS}; do cd $$x; ${MAKE} $@ || exit $$?; cd ..; done

tests:
	cd $@; ${MAKE} $@

test: tests

hooks:
	cd $@; ${MAKE}

eginstall:
	for x in ${SUBDIRS}; do cd $$x; ${MAKE} $@ || exit $$?; cd ..; done

install:
	for x in ${SUBDIRS}; do cd $$x; ${MAKE} $@ || exit $$?; cd ..; done

proginstall:
	for x in ${SUBDIRS}; do cd $$x; ${MAKE} $@ || exit $$?; cd ..; done

clean:
	rm -rf cov-int dhcpcd.xz
	for x in ${SUBDIRS} tests; do cd $$x; ${MAKE} $@ || exit $$?; cd ..; done

distclean: clean
	rm -f config.h config.mk config.log \
		${DISTFILE} ${DISTINFO} ${DISTINFOMD} ${DISTSIGN}
	rm -f *.diff *.patch *.orig *.rej
	for x in ${SUBDIRS} tests; do cd $$x; ${MAKE} $@ || exit $$?; cd ..; done

dist-git:
	git archive --prefix=${DISTPREFIX}/ v${VERSION} | xz >${DISTFILE}

dist-inst:
	mkdir /tmp/${DISTPREFIX}
	cp -RPp * /tmp/${DISTPREFIX}
	(cd /tmp/${DISTPREFIX}; make clean)
	tar -cvJpf ${DISTFILE} -C /tmp ${DISTPREFIX}
	rm -rf /tmp/${DISTPREFIX}

dist: ${DIST}

distinfo: dist
	rm -f ${DISTINFO} ${DISTSIGN}
	${SHA256} ${DISTFILE} >${DISTINFO}
	wc -c <${DISTFILE} \
		| xargs printf 'Size   (${DISTFILE}) = %s\n' >>${DISTINFO}
	${PGP} --sign --armour --detach ${DISTFILE}
	chmod 644 ${DISTSIGN}
	ls -l ${DISTFILE} ${DISTINFO} ${DISTSIGN}

${DISTINFOMD}: ${DISTINFO}
	echo '```' >${DISTINFOMD}
	cat ${DISTINFO} >>${DISTINFOMD}
	echo '```' >>${DISTINFOMD}

release: distinfo ${DISTINFOMD}
	gh release create v${VERSION} \
		--title "${PACKAGE} ${VERSION}" --draft --generate-notes \
		--notes-file ${DISTINFOMD} \
		${DISTFILE} ${DISTSIGN}

snapshot:
	rm -rf /tmp/${DISTPREFIX}
	${INSTALL} -d /tmp/${DISTPREFIX}
	cp -RPp * /tmp/${DISTPREFIX}
	${MAKE} -C /tmp/${DISTPREFIX} distclean
	tar cf - -C /tmp ${DISTPREFIX} | xz >${DISTFILE}
	ls -l ${DISTFILE}

_import: dist
	rm -rf ${DESTDIR}/*
	${INSTALL} -d ${DESTDIR}
	tar xvpf ${DISTFILE} -C ${DESTDIR} --strip 1
	@${ECHO}
	@${ECHO} "============================================================="
	@${ECHO} "${PACKAGE}-${VERSION} imported to ${DESTDIR}"

import:
	${MAKE} _import DESTDIR=`if [ -n "${DESTDIR}" ]; then echo "${DESTDIR}"; else  echo /tmp/${DISTPREFIX}; fi`


_import-src: clean
	rm -rf ${DESTDIR}/*
	${INSTALL} -d ${DESTDIR}
	cp LICENSE README.md ${DESTDIR};
	for x in ${SUBDIRS}; do cd $$x; ${MAKE} DESTDIR=${DESTDIR} $@ || exit $$?; cd ..; done
	@${ECHO}
	@${ECHO} "============================================================="
	@${ECHO} "${PACKAGE}-${VERSION} imported to ${DESTDIR}"

import-src:
	${MAKE} _import-src DESTDIR=`if [ -n "${DESTDIR}" ]; then echo "${DESTDIR}"; else  echo /tmp/${DISTPREFIX}; fi`

include Makefile.inc


================================================
FILE: Makefile.inc
================================================
# SPDX-License-Identifier: BSD-2-Clause
# Copyright (c) 2009-2025 Roy Marples <roy@marples.name>

# System definitions

PICFLAG?=	-fPIC

BINMODE?=	0555
NONBINMODE?=	0444
MANMODE?=	${NONBINMODE}
CONFMODE?=	0644
DBMODE?=	0750

CC?=		cc
ECHO?=		echo
INSTALL?=	install
LINT?=		lint
SED?=		sed
HOST_SH?=	/bin/sh

# This isn't very portable, but I generaly make releases from NetBSD
SHA256?=	sha256
# Force gpg2 to avoid SHA1 signatures from gpg1
PGP?=		gpg2

SCRIPT=		${LIBEXECDIR}/dhcpcd-run-hooks
HOOKDIR=	${LIBEXECDIR}/dhcpcd-hooks

SED_RUNDIR=		-e 's:@RUNDIR@:${RUNDIR}:g'
SED_DBDIR=		-e 's:@DBDIR@:${DBDIR}:g'
SED_LIBDIR=		-e 's:@LIBDIR@:${LIBDIR}:g'
SED_DATADIR=		-e 's:@DATADIR@:${DATADIR}:g'
SED_HOOKDIR=		-e 's:@HOOKDIR@:${HOOKDIR}:g'
SED_SERVICEEXISTS=	-e 's:@SERVICEEXISTS@:${SERVICEEXISTS}:g'
SED_SERVICECMD=		-e 's:@SERVICECMD@:${SERVICECMD}:g'
SED_SERVICESTATUS=	-e 's:@SERVICESTATUS@:${SERVICESTATUS}:g'
SED_STATUSARG=		-e 's:@STATUSARG@:${STATUSARG}:g'
SED_SCRIPT=		-e 's:@SCRIPT@:${SCRIPT}:g'
SED_SYS=		-e 's:@SYSCONFDIR@:${SYSCONFDIR}:g'
SED_DEFAULT_HOSTNAME=	-e 's:@DEFAULT_HOSTNAME@:${DEFAULT_HOSTNAME}:g'


================================================
FILE: README.md
================================================
<!-- SPDX-License-Identifier: BSD-2-Clause -->
<!-- Copyright (c) 2017-2023 Roy Marples <roy@marples.name> -->

# dhcpcd

dhcpcd is a
[DHCP](https://en.wikipedia.org/wiki/Dynamic_Host_Configuration_Protocol) and a
[DHCPv6](https://en.wikipedia.org/wiki/DHCPv6) client.
It's also an IPv4LL (aka [ZeroConf](https://en.wikipedia.org/wiki/Zeroconf))
client.
In layperson's terms, dhcpcd runs on your machine and silently configures your
computer to work on the attached networks without trouble and mostly without
configuration.

If you're a desktop user then you may also be interested in
[Network Configurator (dhcpcd-ui)](http://roy.marples.name/projects/dhcpcd-ui)
which sits in the notification area and monitors the state of the network via
dhcpcd.
It also has a nice configuration dialog and the ability to enter a pass phrase
for wireless networks.

dhcpcd may not be the only daemon running that wants to configure DNS on the
host, so it uses [openresolv](http://roy.marples.name/projects/openresolv)
to ensure they can co-exist.

See [BUILDING.md](BUILDING.md) for how to build dhcpcd.

## Configuration

You should read the dhcpcd.conf man page
and put your options into `/etc/dhcpcd.conf`.
The default configuration file should work for most people just fine.
Here it is, in case you lose it.

```
# A sample configuration for dhcpcd.
# See dhcpcd.conf(5) for details.

# Allow users of this group to interact with dhcpcd via the control socket.
#controlgroup wheel

# Inform the DHCP server of our hostname for DDNS.
hostname

# Use the hardware address of the interface for the Client ID.
#clientid
# or
# Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361.
# Some non-RFC compliant DHCP servers do not reply with this set.
# In this case, comment out duid and enable clientid above.
duid

# Persist interface configuration when dhcpcd exits.
persistent

# Rapid commit support.
# Safe to enable by default because it requires the equivalent option set
# on the server to actually work.
option rapid_commit

# A list of options to request from the DHCP server.
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
# Respect the network MTU. This is applied to DHCP routes.
option interface_mtu

# Most distributions have NTP support.
#option ntp_servers

# A ServerID is required by RFC2131.
require dhcp_server_identifier

# Generate SLAAC address using the Hardware Address of the interface
#slaac hwaddr
# OR generate Stable Private IPv6 Addresses based from the DUID
slaac private
```

The dhcpcd man page has a lot of the same options and more,
which only apply to calling dhcpcd from the command line.


## Compatibility
dhcpcd-5 is only fully command line compatible with dhcpcd-4. 
For compatibility with older versions, use dhcpcd-4.

## Upgrading
dhcpcd-7 defaults the database directory to `/var/db/dhcpcd` instead of
`/var/db` and now stores dhcpcd.duid and dhcpcd.secret in there instead of
in /etc.

dhcpcd-9 defaults the run directory to `/var/run/dhcpcd` instead of
`/var/run` and the prefix of dhcpcd has been removed from the files therein.

## ChangeLog
We no longer supply a ChangeLog.
However, you're more than welcome to read the
[commit log](https://github.com/NetworkConfiguration/dhcpcd/commits) and
[release announcements](https://github.com/NetworkConfiguration/dhcpcd/releases).


================================================
FILE: compat/_strtoi.h
================================================
/*	$NetBSD: _strtoi.h,v 1.1 2015/01/22 02:15:59 christos Exp $	*/

/*-
 * SPDX-License-Identifier: BSD-3-Clause
 * Copyright (c) 1990, 1993
 *	The Regents of the University of California.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * Original version ID:
 * NetBSD: src/lib/libc/locale/_wcstoul.h,v 1.2 2003/08/07 16:43:03 agc Exp
 *
 * Created by Kamil Rytarowski, based on ID:
 * NetBSD: src/common/lib/libc/stdlib/_strtoul.h,v 1.7 2013/05/17 12:55:56 joerg Exp
 */

#ifndef _STRTOI_H
#define	_STRTOI_H

/*
 * function template for strtoi and strtou
 *
 * parameters:
 *	_FUNCNAME    : function name
 *      __TYPE       : return and range limits type
 *      __WRAPPED    : wrapped function, strtoimax or strtoumax
 */

__TYPE
_FUNCNAME(const char * __restrict nptr, char ** __restrict endptr, int base,
          __TYPE lo, __TYPE hi, int * rstatus)
{
	int serrno;
	__TYPE im;
	char *ep;
	int rep;

	/* endptr may be NULL */

	if (endptr == NULL)
		endptr = &ep;

	if (rstatus == NULL)
		rstatus = &rep;

	serrno = errno;
	errno = 0;

	im = __WRAPPED(nptr, endptr, base);

	*rstatus = errno;
	errno = serrno;

	if (*rstatus == 0) {
		/* No digits were found */
		if (nptr == *endptr)
			*rstatus = ECANCELED;
		/* There are further characters after number */
		else if (**endptr != '\0')
			*rstatus = ENOTSUP;
	}

	if (im < lo) {
		if (*rstatus == 0)
			*rstatus = ERANGE;
		return lo;
	}
	if (im > hi) {
		if (*rstatus == 0)
			*rstatus = ERANGE;
		return hi;
	}

	return im;
}
#endif


================================================
FILE: compat/arc4random.c
================================================
/*	$OpenBSD: arc4random.c,v 1.58 2022/07/31 13:41:45 tb Exp $	*/

/*
 * SPDX-License-Identifier: ISC
 * Copyright (c) 1996, David Mazieres <dm@uun.org>
 * Copyright (c) 2008, Damien Miller <djm@openbsd.org>
 * Copyright (c) 2013, Markus Friedl <markus@openbsd.org>
 * Copyright (c) 2014, Theo de Raadt <deraadt@openbsd.org>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

/*
 * ChaCha based random number generator for OpenBSD.
 */

/*
 * OPENBSD ORIGINAL: lib/libc/crypt/arc4random.c
 *                   lib/libc/crypt/arc4random.h
 */

#include "config.h"

#include <fcntl.h>
#include <limits.h>
#include <signal.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/time.h>

#if defined(HAVE_OPENSSL)
#include <openssl/rand.h>
#endif

#define KEYSTREAM_ONLY
#include "chacha_private.h"

#define minimum(a, b) ((a) < (b) ? (a) : (b))

#if defined(__GNUC__) || defined(_MSC_VER)
#define inline __inline
#else				/* __GNUC__ || _MSC_VER */
#define inline
#endif				/* !__GNUC__ && !_MSC_VER */

#define KEYSZ	32
#define IVSZ	8
#define BLOCKSZ	64
#define RSBUFSZ	(16*BLOCKSZ)

#define REKEY_BASE	(1024*1024) /* NB. should be a power of 2 */

/* Marked MAP_INHERIT_ZERO, so zero'd out in fork children. */
static struct _rs {
	size_t		rs_have;	/* valid bytes at end of rs_buf */
	size_t		rs_count;	/* bytes till reseed */
} *rs;

/* Maybe be preserved in fork children, if _rs_allocate() decides. */
static struct _rsx {
	chacha_ctx	rs_chacha;	/* chacha context for random keystream */
	u_char		rs_buf[RSBUFSZ];	/* keystream blocks */
} *rsx;

static int _dhcpcd_rand_fd = -1;	/* /dev/urandom fd */

static int _dhcpcd_getentropy(void *, size_t);
static inline int _rs_allocate(struct _rs **, struct _rsx **);

/* dhcpcd needs to hold onto the fd at fork due to privsep */
#if 0
static inline void _rs_forkdetect(void);
#else
#define _rs_forkdetect()
#define _rs_forkhandler()
#endif

/* Inline "arc4random.h" */
#include <sys/types.h>
#include <sys/mman.h>

static inline void _rs_rekey(u_char *dat, size_t datlen);

/* dhcpcd isn't multithreaded */
#define _ARC4_LOCK()
#define _ARC4_UNLOCK()

static int
_dhcpcd_getentropy(void *buf, size_t length)
{
	struct timeval	 tv;
	uint8_t		*rand = (uint8_t *)buf;

#if defined (HAVE_OPENSSL)
	if (RAND_priv_bytes(buf, (int)length) == 1)
		return (0);
#endif

	if (length < sizeof(tv)) {
		gettimeofday(&tv, NULL);
		memcpy(buf, &tv, sizeof(tv));
		length -= sizeof(tv);
		rand += sizeof(tv);
	}
	if (_dhcpcd_rand_fd == -1)
		_dhcpcd_rand_fd = open("/dev/urandom", O_RDONLY | O_NONBLOCK);
	if (_dhcpcd_rand_fd != -1) {
		/* coverity[check_return] */
		(void)read(_dhcpcd_rand_fd, rand, length);
	}

	/* Never fail. If there is an error reading from /dev/urandom,
         * just use what is on the stack. */
	return (0);
}

static inline void
_getentropy_fail(void)
{
	raise(SIGKILL);
}

#if 0
static volatile sig_atomic_t _rs_forked;

static inline void
_rs_forkhandler(void)
{
	_rs_forked = 1;
}

static inline void
_rs_forkdetect(void)
{
	static pid_t _rs_pid = 0;
	pid_t pid = getpid();

        /* XXX unusual calls to clone() can bypass checks */
	if (_rs_pid == 0 || _rs_pid == 1 || _rs_pid != pid || _rs_forked) {
		_rs_pid = pid;
		_rs_forked = 0;
		if (rs)
			memset(rs, 0, sizeof(*rs));
	}
}
#endif

static inline int
_rs_allocate(struct _rs **rsp, struct _rsx **rsxp)
{
	if ((*rsp = mmap(NULL, sizeof(**rsp), PROT_READ|PROT_WRITE,
	    MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED)
		return (-1);

	if ((*rsxp = mmap(NULL, sizeof(**rsxp), PROT_READ|PROT_WRITE,
	    MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) {
		munmap(*rsp, sizeof(**rsp));
		*rsp = NULL;
		return (-1);
	}

	_rs_forkhandler();
	return (0);
}

static inline void
_rs_init(u_char *buf, size_t n)
{
	if (n < KEYSZ + IVSZ)
		return;

	if (rs == NULL) {
		if (_rs_allocate(&rs, &rsx) == -1)
			_exit(1);
	}

	chacha_keysetup(&rsx->rs_chacha, buf, KEYSZ * 8);
	chacha_ivsetup(&rsx->rs_chacha, buf + KEYSZ);
}

static void
_rs_stir(void)
{
	u_char rnd[KEYSZ + IVSZ];
	uint32_t rekey_fuzz = 0;

	if (_dhcpcd_getentropy(rnd, sizeof rnd) == -1)
		_getentropy_fail();

	if (!rs)
		_rs_init(rnd, sizeof(rnd));
	else
		_rs_rekey(rnd, sizeof(rnd));
#if defined(HAVE_EXPLICIT_BZERO)
	explicit_bzero(rnd, sizeof(rnd));	/* discard source seed */
#elif defined(HAVE_MEMSET_EXPLICIT)
	(void)memset_explicit(rnd, 0, sizeof(rnd));
#elif defined(HAVE_MEMSET_S)
	(void)memset_s(rnd, sizeof(rnd), 0, sizeof(rnd));
#else
#warning potentially insecure use of memset discarding the source seed
	(void)memset(rnd, 0, sizeof(rnd));	/* discard source seed */
#endif

	/* invalidate rs_buf */
	rs->rs_have = 0;
	memset(rsx->rs_buf, 0, sizeof(rsx->rs_buf));

	/* rekey interval should not be predictable */
	chacha_encrypt_bytes(&rsx->rs_chacha, (uint8_t *)&rekey_fuzz,
	    (uint8_t *)&rekey_fuzz, sizeof(rekey_fuzz));
	rs->rs_count = REKEY_BASE + (rekey_fuzz % REKEY_BASE);
}

static inline void
_rs_stir_if_needed(size_t len)
{
	_rs_forkdetect();
	if (!rs || rs->rs_count <= len)
		_rs_stir();
	if (rs->rs_count <= len)
		rs->rs_count = 0;
	else
		rs->rs_count -= len;
}

static inline void
_rs_rekey(u_char *dat, size_t datlen)
{
#ifndef KEYSTREAM_ONLY
	memset(rsx->rs_buf, 0, sizeof(rsx->rs_buf));
#endif
	/* fill rs_buf with the keystream */
	chacha_encrypt_bytes(&rsx->rs_chacha, rsx->rs_buf,
	    rsx->rs_buf, sizeof(rsx->rs_buf));
	/* mix in optional user provided data */
	if (dat) {
		size_t i, m;

		m = minimum(datlen, KEYSZ + IVSZ);
		for (i = 0; i < m; i++)
			rsx->rs_buf[i] ^= dat[i];
	}
	/* immediately reinit for backtracking resistance */
	_rs_init(rsx->rs_buf, KEYSZ + IVSZ);
	memset(rsx->rs_buf, 0, KEYSZ + IVSZ);
	rs->rs_have = sizeof(rsx->rs_buf) - KEYSZ - IVSZ;
}

static inline void
_rs_random_buf(void *_buf, size_t n)
{
	u_char *buf = (u_char *)_buf;
	u_char *keystream;
	size_t m;

	_rs_stir_if_needed(n);
	while (n > 0) {
		if (rs->rs_have > 0) {
			m = minimum(n, rs->rs_have);
			keystream = rsx->rs_buf + sizeof(rsx->rs_buf)
			    - rs->rs_have;
			memcpy(buf, keystream, m);
			memset(keystream, 0, m);
			buf += m;
			n -= m;
			rs->rs_have -= m;
		}
		if (rs->rs_have == 0)
			_rs_rekey(NULL, 0);
	}
}

static inline void
_rs_random_u32(uint32_t *val)
{
	u_char *keystream;

	_rs_stir_if_needed(sizeof(*val));
	if (rs->rs_have < sizeof(*val))
		_rs_rekey(NULL, 0);
	keystream = rsx->rs_buf + sizeof(rsx->rs_buf) - rs->rs_have;
	memcpy(val, keystream, sizeof(*val));
	memset(keystream, 0, sizeof(*val));
	rs->rs_have -= sizeof(*val);
}

uint32_t
arc4random(void)
{
	uint32_t val;

	_ARC4_LOCK();
	_rs_random_u32(&val);
	_ARC4_UNLOCK();
	return val;
}

void
arc4random_buf(void *buf, size_t n)
{
	_ARC4_LOCK();
	_rs_random_buf(buf, n);
	_ARC4_UNLOCK();
}


================================================
FILE: compat/arc4random.h
================================================
/*
 * Arc4 random number generator for OpenBSD.
 * SPDX-License-Identifier: ISC
 * Copyright 1996 David Mazieres <dm@lcs.mit.edu>.
 *
 * Modification and redistribution in source and binary forms is
 * permitted provided that due credit is given to the author and the
 * OpenBSD project by leaving this copyright notice intact.
 */

#ifndef ARC4RANDOM_H
#define ARC4RANDOM_H

#include <stdint.h>

uint32_t arc4random(void);
void arc4random_buf(void *, size_t);

#endif


================================================
FILE: compat/arc4random_uniform.c
================================================
/*	$OpenBSD: arc4random_uniform.c,v 1.3 2019/01/20 02:59:07 bcook Exp $	*/

/*
 * SPDX-License-Identifier: ISC
 * Copyright (c) 2008, Damien Miller <djm@openbsd.org>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <stdint.h>
#include <stdlib.h>

/* We need to include config.h so we pickup either the system arc4random
 * or our compat one. */
#include "config.h"

/*
 * Calculate a uniformly distributed random number less than upper_bound
 * avoiding "modulo bias".
 *
 * Uniformity is achieved by generating new random numbers until the one
 * returned is outside the range [0, 2**32 % upper_bound).  This
 * guarantees the selected random number will be inside
 * [2**32 % upper_bound, 2**32) which maps back to [0, upper_bound)
 * after reduction modulo upper_bound.
 */
uint32_t
arc4random_uniform(uint32_t upper_bound)
{
	uint32_t r, min;

	if (upper_bound < 2)
		return 0;

	/* 2**32 % x == (2**32 - x) % x */
	min = -upper_bound % upper_bound;

	/*
	 * This could theoretically loop forever but each retry has
	 * p > 0.5 (worst case, usually far better) of selecting a
	 * number inside the range we need, so it should rarely need
	 * to re-roll.
	 */
	for (;;) {
		r = arc4random();
		if (r >= min)
			break;
	}

	return r % upper_bound;
}


================================================
FILE: compat/arc4random_uniform.h
================================================
/*
 * SPDX-License-Identifier: ISC
 * Copyright (c) 2008, Damien Miller <djm@openbsd.org>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#ifndef ARC4RANDOM_UNIFORM_H
#define ARC4RANDOM_UNIFORM_H

#include <stdint.h>

uint32_t arc4random_uniform(uint32_t);
#endif


================================================
FILE: compat/bitops.h
================================================
/*	$NetBSD: bitops.h,v 1.11 2012/12/07 02:27:58 christos Exp $	*/

/*-
 * SPDX-License-Identifier: BSD-2-Clause
 * Copyright (c) 2007, 2010 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Christos Zoulas and Joerg Sonnenberger.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef COMPAT_BITOPS_H
#define COMPAT_BITOPS_H

#include <stdint.h>
#include "common.h"

/*
 * Find First Set functions
 */
#ifndef ffs32
static inline int __unused
ffs32(uint32_t _n)
{
	int _v;

	if (!_n)
		return 0;

	_v = 1;
	if ((_n & 0x0000FFFFU) == 0) {
		_n >>= 16;
		_v += 16;
	}
	if ((_n & 0x000000FFU) == 0) {
		_n >>= 8;
		_v += 8;
	}
	if ((_n & 0x0000000FU) == 0) {
		_n >>= 4;
		_v += 4;
	}
	if ((_n & 0x00000003U) == 0) {
		_n >>= 2;
		_v += 2;
	}
	if ((_n & 0x00000001U) == 0) {
		//_n >>= 1;
		_v += 1;
	}
	return _v;
}
#endif

#ifndef ffs64
static inline int __unused
ffs64(uint64_t _n)
{
	int _v;

	if (!_n)
		return 0;

	_v = 1;
	if ((_n & 0x00000000FFFFFFFFULL) == 0) {
		_n >>= 32;
		_v += 32;
	}
	if ((_n & 0x000000000000FFFFULL) == 0) {
		_n >>= 16;
		_v += 16;
	}
	if ((_n & 0x00000000000000FFULL) == 0) {
		_n >>= 8;
		_v += 8;
	}
	if ((_n & 0x000000000000000FULL) == 0) {
		_n >>= 4;
		_v += 4;
	}
	if ((_n & 0x0000000000000003ULL) == 0) {
		_n >>= 2;
		_v += 2;
	}
	if ((_n & 0x0000000000000001ULL) == 0) {
		//_n >>= 1;
		_v += 1;
	}
	return _v;
}
#endif

/*
 * Find Last Set functions
 */
#ifndef fls32
static __inline int __unused
fls32(uint32_t _n)
{
	int _v;

	if (!_n)
		return 0;

	_v = 32;
	if ((_n & 0xFFFF0000U) == 0) {
		_n <<= 16;
		_v -= 16;
	}
	if ((_n & 0xFF000000U) == 0) {
		_n <<= 8;
		_v -= 8;
	}
	if ((_n & 0xF0000000U) == 0) {
		_n <<= 4;
		_v -= 4;
	}
	if ((_n & 0xC0000000U) == 0) {
		_n <<= 2;
		_v -= 2;
	}
	if ((_n & 0x80000000U) == 0) {
		//_n <<= 1;
		_v -= 1;
	}
	return _v;
}
#endif

#ifndef fls64
static int __unused
fls64(uint64_t _n)
{
	int _v;

	if (!_n)
		return 0;

	_v = 64;
	if ((_n & 0xFFFFFFFF00000000ULL) == 0) {
		_n <<= 32;
		_v -= 32;
	}
	if ((_n & 0xFFFF000000000000ULL) == 0) {
		_n <<= 16;
		_v -= 16;
	}
	if ((_n & 0xFF00000000000000ULL) == 0) {
		_n <<= 8;
		_v -= 8;
	}
	if ((_n & 0xF000000000000000ULL) == 0) {
		_n <<= 4;
		_v -= 4;
	}
	if ((_n & 0xC000000000000000ULL) == 0) {
		_n <<= 2;
		_v -= 2;
	}
	if ((_n & 0x8000000000000000ULL) == 0) {
		//_n <<= 1;
		_v -= 1;
	}
	return _v;
}
#endif

#endif /* COMPAT_BITOPS_H_ */


================================================
FILE: compat/chacha_private.h
================================================
/*
 * SPDX-License-Identifier: CC0-1.0
 *
 * chacha-merged.c version 20080118
 * D. J. Bernstein
 * Public domain.
 */

/* $OpenBSD: chacha_private.h,v 1.3 2022/02/28 21:56:29 dtucker Exp $ */

typedef unsigned char u8;
typedef unsigned int u32;

typedef struct
{
  u32 input[16]; /* could be compressed */
} chacha_ctx;

#define U8C(v) (v##U)
#define U32C(v) (v##U)

#define U8V(v) ((u8)(v) & U8C(0xFF))
#define U32V(v) ((u32)(v) & U32C(0xFFFFFFFF))

#define ROTL32(v, n) \
  (U32V((v) << (n)) | ((v) >> (32 - (n))))

#define U8TO32_LITTLE(p) \
  (((u32)((p)[0])      ) | \
   ((u32)((p)[1]) <<  8) | \
   ((u32)((p)[2]) << 16) | \
   ((u32)((p)[3]) << 24))

#define U32TO8_LITTLE(p, v) \
  do { \
    (p)[0] = U8V((v)      ); \
    (p)[1] = U8V((v) >>  8); \
    (p)[2] = U8V((v) >> 16); \
    (p)[3] = U8V((v) >> 24); \
  } while (0)

#define ROTATE(v,c) (ROTL32(v,c))
#define XOR(v,w) ((v) ^ (w))
#define PLUS(v,w) (U32V((v) + (w)))
#define PLUSONE(v) (PLUS((v),1))

#define QUARTERROUND(a,b,c,d) \
  a = PLUS(a,b); d = ROTATE(XOR(d,a),16); \
  c = PLUS(c,d); b = ROTATE(XOR(b,c),12); \
  a = PLUS(a,b); d = ROTATE(XOR(d,a), 8); \
  c = PLUS(c,d); b = ROTATE(XOR(b,c), 7);

static const char sigma[16] = "expand 32-byte k";
static const char tau[16] = "expand 16-byte k";

static void
chacha_keysetup(chacha_ctx *x,const u8 *k,u32 kbits)
{
  const char *constants;

  x->input[4] = U8TO32_LITTLE(k + 0);
  x->input[5] = U8TO32_LITTLE(k + 4);
  x->input[6] = U8TO32_LITTLE(k + 8);
  x->input[7] = U8TO32_LITTLE(k + 12);
  if (kbits == 256) { /* recommended */
    k += 16;
    constants = sigma;
  } else { /* kbits == 128 */
    constants = tau;
  }
  x->input[8] = U8TO32_LITTLE(k + 0);
  x->input[9] = U8TO32_LITTLE(k + 4);
  x->input[10] = U8TO32_LITTLE(k + 8);
  x->input[11] = U8TO32_LITTLE(k + 12);
  x->input[0] = U8TO32_LITTLE(constants + 0);
  x->input[1] = U8TO32_LITTLE(constants + 4);
  x->input[2] = U8TO32_LITTLE(constants + 8);
  x->input[3] = U8TO32_LITTLE(constants + 12);
}

static void
chacha_ivsetup(chacha_ctx *x,const u8 *iv)
{
  x->input[12] = 0;
  x->input[13] = 0;
  x->input[14] = U8TO32_LITTLE(iv + 0);
  x->input[15] = U8TO32_LITTLE(iv + 4);
}

static void
chacha_encrypt_bytes(chacha_ctx *x,const u8 *m,u8 *c,u32 bytes)
{
  u32 x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15;
  u32 j0, j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14, j15;
  u8 *ctarget = NULL;
  u8 tmp[64];
  u_int i;

  if (!bytes) return;

  j0 = x->input[0];
  j1 = x->input[1];
  j2 = x->input[2];
  j3 = x->input[3];
  j4 = x->input[4];
  j5 = x->input[5];
  j6 = x->input[6];
  j7 = x->input[7];
  j8 = x->input[8];
  j9 = x->input[9];
  j10 = x->input[10];
  j11 = x->input[11];
  j12 = x->input[12];
  j13 = x->input[13];
  j14 = x->input[14];
  j15 = x->input[15];

  for (;;) {
    if (bytes < 64) {
      for (i = 0;i < bytes;++i) tmp[i] = m[i];
      m = tmp;
      ctarget = c;
      c = tmp;
    }
    x0 = j0;
    x1 = j1;
    x2 = j2;
    x3 = j3;
    x4 = j4;
    x5 = j5;
    x6 = j6;
    x7 = j7;
    x8 = j8;
    x9 = j9;
    x10 = j10;
    x11 = j11;
    x12 = j12;
    x13 = j13;
    x14 = j14;
    x15 = j15;
    for (i = 20;i > 0;i -= 2) {
      QUARTERROUND( x0, x4, x8,x12)
      QUARTERROUND( x1, x5, x9,x13)
      QUARTERROUND( x2, x6,x10,x14)
      QUARTERROUND( x3, x7,x11,x15)
      QUARTERROUND( x0, x5,x10,x15)
      QUARTERROUND( x1, x6,x11,x12)
      QUARTERROUND( x2, x7, x8,x13)
      QUARTERROUND( x3, x4, x9,x14)
    }
    x0 = PLUS(x0,j0);
    x1 = PLUS(x1,j1);
    x2 = PLUS(x2,j2);
    x3 = PLUS(x3,j3);
    x4 = PLUS(x4,j4);
    x5 = PLUS(x5,j5);
    x6 = PLUS(x6,j6);
    x7 = PLUS(x7,j7);
    x8 = PLUS(x8,j8);
    x9 = PLUS(x9,j9);
    x10 = PLUS(x10,j10);
    x11 = PLUS(x11,j11);
    x12 = PLUS(x12,j12);
    x13 = PLUS(x13,j13);
    x14 = PLUS(x14,j14);
    x15 = PLUS(x15,j15);

#ifndef KEYSTREAM_ONLY
    x0 = XOR(x0,U8TO32_LITTLE(m + 0));
    x1 = XOR(x1,U8TO32_LITTLE(m + 4));
    x2 = XOR(x2,U8TO32_LITTLE(m + 8));
    x3 = XOR(x3,U8TO32_LITTLE(m + 12));
    x4 = XOR(x4,U8TO32_LITTLE(m + 16));
    x5 = XOR(x5,U8TO32_LITTLE(m + 20));
    x6 = XOR(x6,U8TO32_LITTLE(m + 24));
    x7 = XOR(x7,U8TO32_LITTLE(m + 28));
    x8 = XOR(x8,U8TO32_LITTLE(m + 32));
    x9 = XOR(x9,U8TO32_LITTLE(m + 36));
    x10 = XOR(x10,U8TO32_LITTLE(m + 40));
    x11 = XOR(x11,U8TO32_LITTLE(m + 44));
    x12 = XOR(x12,U8TO32_LITTLE(m + 48));
    x13 = XOR(x13,U8TO32_LITTLE(m + 52));
    x14 = XOR(x14,U8TO32_LITTLE(m + 56));
    x15 = XOR(x15,U8TO32_LITTLE(m + 60));
#endif

    j12 = PLUSONE(j12);
    if (!j12) {
      j13 = PLUSONE(j13);
      /* stopping at 2^70 bytes per nonce is user's responsibility */
    }

    U32TO8_LITTLE(c + 0,x0);
    U32TO8_LITTLE(c + 4,x1);
    U32TO8_LITTLE(c + 8,x2);
    U32TO8_LITTLE(c + 12,x3);
    U32TO8_LITTLE(c + 16,x4);
    U32TO8_LITTLE(c + 20,x5);
    U32TO8_LITTLE(c + 24,x6);
    U32TO8_LITTLE(c + 28,x7);
    U32TO8_LITTLE(c + 32,x8);
    U32TO8_LITTLE(c + 36,x9);
    U32TO8_LITTLE(c + 40,x10);
    U32TO8_LITTLE(c + 44,x11);
    U32TO8_LITTLE(c + 48,x12);
    U32TO8_LITTLE(c + 52,x13);
    U32TO8_LITTLE(c + 56,x14);
    U32TO8_LITTLE(c + 60,x15);

    if (bytes <= 64) {
      if (bytes < 64) {
        for (i = 0;i < bytes;++i) ctarget[i] = c[i];
      }
      x->input[12] = j12;
      x->input[13] = j13;
      return;
    }
    bytes -= 64;
    c += 64;
#ifndef KEYSTREAM_ONLY
    m += 64;
#endif
  }
}


================================================
FILE: compat/closefrom.c
================================================
/*
 * SPDX-License-Identifier: ISC
 *
 * Copyright (c) 2004-2005, 2007, 2010, 2012-2015, 2017-2018
 *	Todd C. Miller <Todd.Miller@sudo.ws>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include "config.h"

#ifdef __linux__
# include <sys/syscall.h>
# if defined(__NR_close_range) && !defined(SYS_close_range)
#  define SYS_close_range __NR_close_range
# endif
#endif

#include <fcntl.h>
#include <limits.h>
#include <unistd.h>

#if defined(__linux__) && defined(SYS_close_range)
static inline int
sys_close_range(unsigned int fd, unsigned int max_fd, unsigned int flags)
{

	return (int)syscall(SYS_close_range, fd, max_fd, flags);
}
#endif

/*
 * Close all file descriptors greater than or equal to lowfd.
 * This is the expensive (fallback) method.
 */
static int
closefrom_fallback(int lowfd)
{
	int fd, maxfd;

#ifdef _SC_OPEN_MAX
	maxfd = (int)sysconf(_SC_OPEN_MAX);
#else
	maxfd = getdtablesize();
#endif
	if (maxfd == -1)
		return -1;

	for (fd = lowfd; fd < maxfd; fd++)
	       close(fd);
	return 0;
}

/*
 *  * Close all file descriptors greater than or equal to lowfd.
 *   * We try the fast way first, falling back on the slow method.
 *    */
void
closefrom(int lowfd)
{

#if defined(__linux__) && defined(SYS_close_range)
	if (sys_close_range((unsigned int)lowfd, UINT_MAX, 0) == 0)
		return;
#endif

	closefrom_fallback(lowfd);
}


================================================
FILE: compat/closefrom.h
================================================
/*
 * SPDX-License-Identifier: ISC
 * Copyright (c) 2004-2005, 2007, 2010, 2012-2015, 2017-2018
 *	Todd C. Miller <Todd.Miller@sudo.ws>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */
#ifndef CLOSEFROM_H
#define CLOSEFROM_H

void closefrom(int);

#endif


================================================
FILE: compat/consttime_memequal.h
================================================
/*
 * SPDX-License-Identifier: CC0-1.0
 * Written by Matthias Drochner <drochner@NetBSD.org>.
 * Public domain.
 */

#ifndef CONSTTIME_MEMEQUAL_H
#define CONSTTIME_MEMEQUAL_H
inline static int
consttime_memequal(const void *b1, const void *b2, size_t len)
{
	const unsigned char *c1 = b1, *c2 = b2;
	unsigned int res = 0;

	while (len--)
		res |= *c1++ ^ *c2++;

	/*
	 * Map 0 to 1 and [1, 256) to 0 using only constant-time
	 * arithmetic.
	 *
	 * This is not simply `!res' because although many CPUs support
	 * branchless conditional moves and many compilers will take
	 * advantage of them, certain compilers generate branches on
	 * certain CPUs for `!res'.
	 */
	return (1 & ((res - 1) >> 8));
}
#endif /* CONSTTIME_MEMEQUAL_H */


================================================
FILE: compat/crypt/hmac.c
================================================
/*	$NetBSD: hmac.c,v 1.5 2017/10/05 09:59:04 roy Exp $	*/

/*-
 * SPDX-License-Identifier: BSD-2-Clause
 * Copyright (c) 2016 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Christos Zoulas.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include <string.h>
#include <stdlib.h>

#include "config.h"

#if defined(HAVE_MD5_H) && !defined(DEPGEN)
#include <md5.h>
#endif

#ifdef SHA2_H
#  include SHA2_H
#endif

#ifndef __arraycount
#define	__arraycount(__x)       (sizeof(__x) / sizeof(__x[0]))
#endif

#if 0
#include <md2.h>
#include <md4.h>
#include <md5.h>
#include <rmd160.h>
#include <sha1.h>
#include <sha2.h>
#endif

#ifndef MD5_BLOCK_LENGTH
#define	MD5_BLOCK_LENGTH	64
#endif
#ifndef SHA256_BLOCK_LENGTH
#define	SHA256_BLOCK_LENGTH	64
#endif

#define HMAC_SIZE	128
#define HMAC_IPAD	0x36
#define HMAC_OPAD	0x5C

static const struct hmac {
	const char *name;
	size_t ctxsize;
	size_t digsize;
	size_t blocksize;
	void (*init)(void *);
	void (*update)(void *, const uint8_t *, unsigned int);
	void (*final)(uint8_t *, void *);
} hmacs[] = {
#if 0
	{
		"md2", sizeof(MD2_CTX), MD2_DIGEST_LENGTH, MD2_BLOCK_LENGTH,
		(void *)MD2Init, (void *)MD2Update, (void *)MD2Final,
	},
	{
		"md4", sizeof(MD4_CTX), MD4_DIGEST_LENGTH, MD4_BLOCK_LENGTH,
		(void *)MD4Init, (void *)MD4Update, (void *)MD4Final,
	},
#endif
	{
		"md5", sizeof(MD5_CTX), MD5_DIGEST_LENGTH, MD5_BLOCK_LENGTH,
		(void *)MD5Init, (void *)MD5Update, (void *)MD5Final,
	},
#if 0
	{
		"rmd160", sizeof(RMD160_CTX), RMD160_DIGEST_LENGTH,
		RMD160_BLOCK_LENGTH,
		(void *)RMD160Init, (void *)RMD160Update, (void *)RMD160Final,
	},
	{
		"sha1", sizeof(SHA1_CTX), SHA1_DIGEST_LENGTH, SHA1_BLOCK_LENGTH,
		(void *)SHA1Init, (void *)SHA1Update, (void *)SHA1Final,
	},
	{
		"sha224", sizeof(SHA224_CTX), SHA224_DIGEST_LENGTH,
		SHA224_BLOCK_LENGTH,
		(void *)SHA224_Init, (void *)SHA224_Update,
		(void *)SHA224_Final,
	},
#endif
	{
		"sha256", sizeof(SHA256_CTX), SHA256_DIGEST_LENGTH,
		SHA256_BLOCK_LENGTH,
		(void *)SHA256_Init, (void *)SHA256_Update,
		(void *)SHA256_Final,
	},
#if 0
	{
		"sha384", sizeof(SHA384_CTX), SHA384_DIGEST_LENGTH,
		SHA384_BLOCK_LENGTH,
		(void *)SHA384_Init, (void *)SHA384_Update,
		(void *)SHA384_Final,
	},
	{
		"sha512", sizeof(SHA512_CTX), SHA512_DIGEST_LENGTH,
		SHA512_BLOCK_LENGTH,
		(void *)SHA512_Init, (void *)SHA512_Update,
		(void *)SHA512_Final,
	},
#endif
};

static const struct hmac *
hmac_find(const char *name)
{
	for (size_t i = 0; i < __arraycount(hmacs); i++) {
		if (strcmp(hmacs[i].name, name) != 0)
			continue;
		return &hmacs[i];
	}
	return NULL;
}

ssize_t
hmac(const char *name,
    const void *key, size_t klen,
    const void *text, size_t tlen,
    void *digest, size_t dlen)
{
	uint8_t ipad[HMAC_SIZE], opad[HMAC_SIZE], d[HMAC_SIZE];
	const uint8_t *k = key;
	const struct hmac *h;
	uint64_t c[32];
	void *p;

	if ((h = hmac_find(name)) == NULL)
		return -1;


	if (klen > h->blocksize) {
		(*h->init)(c);
		(*h->update)(c, k, (unsigned int)klen);
		(*h->final)(d, c);
		k = (void *)d;
		klen = h->digsize;
	}

	/* Form input and output pads for the digests */
	for (size_t i = 0; i < sizeof(ipad); i++) {
		ipad[i] = (i < klen ? k[i] : 0) ^ HMAC_IPAD;
		opad[i] = (i < klen ? k[i] : 0) ^ HMAC_OPAD;
	}

	p = dlen >= h->digsize ? digest : d;
	if (p != digest) {
		memcpy(p, digest, dlen);
		memset((char *)p + dlen, 0, h->digsize - dlen);
	}
	(*h->init)(c);
	(*h->update)(c, ipad, (unsigned int)h->blocksize);
	(*h->update)(c, text, (unsigned int)tlen);
	(*h->final)(p, c);

	(*h->init)(c);
	(*h->update)(c, opad, (unsigned int)h->blocksize);
	(*h->update)(c, digest, (unsigned int)h->digsize);
	(*h->final)(p, c);

	if (p != digest)
		memcpy(digest, p, dlen);

	return (ssize_t)h->digsize;
}


================================================
FILE: compat/crypt/hmac.h
================================================
/*	$NetBSD: hmac.c,v 1.5 2017/10/05 09:59:04 roy Exp $	*/

/*-
 * SPDX-License-Identifier: BSD-2-Clause
 * Copyright (c) 2016 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Christos Zoulas.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef HMAC_H
#define HMAC_H

#include <sys/types.h>

ssize_t	 hmac(const char *, const void *, size_t, const void *, size_t, void *,
   size_t);

#endif


================================================
FILE: compat/crypt/md5.c
================================================
/* SPDX-License-Identifier: CC0-1.0
 * This code implements the MD5 message-digest algorithm.
 * The algorithm is due to Ron Rivest.	This code was
 * written by Colin Plumb in 1993, no copyright is claimed.
 * This code is in the public domain; do with it what you wish.
 *
 * Equivalent code is available from RSA Data Security, Inc.
 * This code has been tested against that, and is equivalent,
 * except that you don't need to include two pages of legalese
 * with every copy.
 *
 * To compute the message digest of a chunk of bytes, declare an
 * MD5Context structure, pass it to MD5Init, call MD5Update as
 * needed on buffers full of bytes, and then call MD5Final, which
 * will fill a supplied 16-byte array with the digest.
 */

#include <sys/param.h>
#include <inttypes.h>

#include <string.h>

#include "md5.h"

#define PUT_64BIT_LE(cp, value) do {					\
	(cp)[7] = (uint8_t)((value) >> 56);				\
	(cp)[6] = (uint8_t)((value) >> 48);				\
	(cp)[5] = (uint8_t)((value) >> 40);				\
	(cp)[4] = (uint8_t)((value) >> 32);				\
	(cp)[3] = (uint8_t)((value) >> 24);				\
	(cp)[2] = (uint8_t)((value) >> 16);				\
	(cp)[1] = (uint8_t)((value) >> 8);				\
	(cp)[0] = (uint8_t)(value); } while (0)

#define PUT_32BIT_LE(cp, value) do {					\
	(cp)[3] = (uint8_t)((value) >> 24);				\
	(cp)[2] = (uint8_t)((value) >> 16);				\
	(cp)[1] = (uint8_t)((value) >> 8);				\
	(cp)[0] = (uint8_t)(value); } while (0)

static uint8_t PADDING[MD5_BLOCK_LENGTH] = {
	0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};

/*
 * Start MD5 accumulation.  Set bit count to 0 and buffer to mysterious
 * initialization constants.
 */
void
MD5Init(MD5_CTX *ctx)
{
	ctx->count = 0;
	ctx->state[0] = 0x67452301;
	ctx->state[1] = 0xefcdab89;
	ctx->state[2] = 0x98badcfe;
	ctx->state[3] = 0x10325476;
}


/* The four core functions - F1 is optimized somewhat */

/* #define F1(x, y, z) (x & y | ~x & z) */
#define F1(x, y, z) (z ^ (x & (y ^ z)))
#define F2(x, y, z) F1(z, x, y)
#define F3(x, y, z) (x ^ y ^ z)
#define F4(x, y, z) (y ^ (x | ~z))

/* This is the central step in the MD5 algorithm. */
#define MD5STEP(f, w, x, y, z, data, s) \
	( w += f(x, y, z) + data,  w = w<<s | w>>(32-s),  w += x )

/*
 * The core of the MD5 algorithm, this alters an existing MD5 hash to
 * reflect the addition of 16 longwords of new data.  MD5Update blocks
 * the data and converts bytes into longwords for this routine.
 */
static void
MD5Transform(uint32_t state[4], const uint8_t block[MD5_BLOCK_LENGTH])
{
	uint32_t a, b, c, d, in[MD5_BLOCK_LENGTH / 4];

#if BYTE_ORDER == LITTLE_ENDIAN
	memcpy(in, block, sizeof(in));
#else
	for (a = 0; a < MD5_BLOCK_LENGTH / 4; a++) {
		in[a] = (uint32_t)(
		    (uint32_t)(block[a * 4 + 0]) |
		    (uint32_t)(block[a * 4 + 1]) <<  8 |
		    (uint32_t)(block[a * 4 + 2]) << 16 |
		    (uint32_t)(block[a * 4 + 3]) << 24);
	}
#endif

	a = state[0];
	b = state[1];
	c = state[2];
	d = state[3];

	MD5STEP(F1, a, b, c, d, in[ 0] + 0xd76aa478,  7);
	MD5STEP(F1, d, a, b, c, in[ 1] + 0xe8c7b756, 12);
	MD5STEP(F1, c, d, a, b, in[ 2] + 0x242070db, 17);
	MD5STEP(F1, b, c, d, a, in[ 3] + 0xc1bdceee, 22);
	MD5STEP(F1, a, b, c, d, in[ 4] + 0xf57c0faf,  7);
	MD5STEP(F1, d, a, b, c, in[ 5] + 0x4787c62a, 12);
	MD5STEP(F1, c, d, a, b, in[ 6] + 0xa8304613, 17);
	MD5STEP(F1, b, c, d, a, in[ 7] + 0xfd469501, 22);
	MD5STEP(F1, a, b, c, d, in[ 8] + 0x698098d8,  7);
	MD5STEP(F1, d, a, b, c, in[ 9] + 0x8b44f7af, 12);
	MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
	MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
	MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122,  7);
	MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
	MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
	MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);

	MD5STEP(F2, a, b, c, d, in[ 1] + 0xf61e2562,  5);
	MD5STEP(F2, d, a, b, c, in[ 6] + 0xc040b340,  9);
	MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
	MD5STEP(F2, b, c, d, a, in[ 0] + 0xe9b6c7aa, 20);
	MD5STEP(F2, a, b, c, d, in[ 5] + 0xd62f105d,  5);
	MD5STEP(F2, d, a, b, c, in[10] + 0x02441453,  9);
	MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
	MD5STEP(F2, b, c, d, a, in[ 4] + 0xe7d3fbc8, 20);
	MD5STEP(F2, a, b, c, d, in[ 9] + 0x21e1cde6,  5);
	MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6,  9);
	MD5STEP(F2, c, d, a, b, in[ 3] + 0xf4d50d87, 14);
	MD5STEP(F2, b, c, d, a, in[ 8] + 0x455a14ed, 20);
	MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905,  5);
	MD5STEP(F2, d, a, b, c, in[ 2] + 0xfcefa3f8,  9);
	MD5STEP(F2, c, d, a, b, in[ 7] + 0x676f02d9, 14);
	MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);

	MD5STEP(F3, a, b, c, d, in[ 5] + 0xfffa3942,  4);
	MD5STEP(F3, d, a, b, c, in[ 8] + 0x8771f681, 11);
	MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
	MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
	MD5STEP(F3, a, b, c, d, in[ 1] + 0xa4beea44,  4);
	MD5STEP(F3, d, a, b, c, in[ 4] + 0x4bdecfa9, 11);
	MD5STEP(F3, c, d, a, b, in[ 7] + 0xf6bb4b60, 16);
	MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
	MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6,  4);
	MD5STEP(F3, d, a, b, c, in[ 0] + 0xeaa127fa, 11);
	MD5STEP(F3, c, d, a, b, in[ 3] + 0xd4ef3085, 16);
	MD5STEP(F3, b, c, d, a, in[ 6] + 0x04881d05, 23);
	MD5STEP(F3, a, b, c, d, in[ 9] + 0xd9d4d039,  4);
	MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
	MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
	MD5STEP(F3, b, c, d, a, in[2 ] + 0xc4ac5665, 23);

	MD5STEP(F4, a, b, c, d, in[ 0] + 0xf4292244,  6);
	MD5STEP(F4, d, a, b, c, in[7 ] + 0x432aff97, 10);
	MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
	MD5STEP(F4, b, c, d, a, in[5 ] + 0xfc93a039, 21);
	MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3,  6);
	MD5STEP(F4, d, a, b, c, in[3 ] + 0x8f0ccc92, 10);
	MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
	MD5STEP(F4, b, c, d, a, in[1 ] + 0x85845dd1, 21);
	MD5STEP(F4, a, b, c, d, in[8 ] + 0x6fa87e4f,  6);
	MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
	MD5STEP(F4, c, d, a, b, in[6 ] + 0xa3014314, 15);
	MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
	MD5STEP(F4, a, b, c, d, in[4 ] + 0xf7537e82,  6);
	MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
	MD5STEP(F4, c, d, a, b, in[2 ] + 0x2ad7d2bb, 15);
	MD5STEP(F4, b, c, d, a, in[9 ] + 0xeb86d391, 21);

	state[0] += a;
	state[1] += b;
	state[2] += c;
	state[3] += d;
}

/*
 * Update context to reflect the concatenation of another buffer full
 * of bytes.
 */
void
MD5Update(MD5_CTX *ctx, const unsigned char *input, size_t len)
{
	size_t have, need;

	/* Check how many bytes we already have and how many more we need. */
	have = (size_t)((ctx->count >> 3) & (MD5_BLOCK_LENGTH - 1));
	need = MD5_BLOCK_LENGTH - have;

	/* Update bitcount */
	ctx->count += (uint64_t)len << 3;

	if (len >= need) {
		if (have != 0) {
			memcpy(ctx->buffer + have, input, need);
			MD5Transform(ctx->state, ctx->buffer);
			input += need;
			len -= need;
			have = 0;
		}

		/* Process data in MD5_BLOCK_LENGTH-byte chunks. */
		while (len >= MD5_BLOCK_LENGTH) {
			MD5Transform(ctx->state, input);
			input += MD5_BLOCK_LENGTH;
			len -= MD5_BLOCK_LENGTH;
		}
	}

	/* Handle any remaining bytes of data. */
	if (len != 0)
		memcpy(ctx->buffer + have, input, len);
}

/*
 * Final wrapup - pad to 64-byte boundary with the bit pattern
 * 1 0* (64-bit count of bits processed, MSB-first)
 */
void
MD5Final(unsigned char digest[MD5_DIGEST_LENGTH], MD5_CTX *ctx)
{
	uint8_t count[8];
	size_t padlen;
	int i;

	/* Convert count to 8 bytes in little endian order. */
	PUT_64BIT_LE(count, ctx->count);

	/* Pad out to 56 mod 64. */
	padlen = MD5_BLOCK_LENGTH -
	    ((ctx->count >> 3) & (MD5_BLOCK_LENGTH - 1));
	if (padlen < 1 + 8)
		padlen += MD5_BLOCK_LENGTH;
	MD5Update(ctx, PADDING, padlen - 8);		/* padlen - 8 <= 64 */
	MD5Update(ctx, count, 8);

	if (digest != NULL) {
		for (i = 0; i < 4; i++)
			PUT_32BIT_LE(digest + i * 4, ctx->state[i]);
	}
	memset(ctx, 0, sizeof(*ctx));	/* in case it's sensitive */
}




================================================
FILE: compat/crypt/md5.h
================================================
/*
 * This code implements the MD5 message-digest algorithm.
 * SPDX-License-Identifier: CC0-1.0
 * The algorithm is due to Ron Rivest.	This code was
 * written by Colin Plumb in 1993, no copyright is claimed.
 * This code is in the public domain; do with it what you wish.
 *
 * Equivalent code is available from RSA Data Security, Inc.
 * This code has been tested against that, and is equivalent,
 * except that you don't need to include two pages of legalese
 * with every copy.
 *
 * To compute the message digest of a chunk of bytes, declare an
 * MD5Context structure, pass it to MD5Init, call MD5Update as
 * needed on buffers full of bytes, and then call MD5Final, which
 * will fill a supplied 16-byte array with the digest.
 */

#ifndef MD5_H_
#define MD5_H_

#define MD5_DIGEST_LENGTH	16
#define MD5_BLOCK_LENGTH	64

typedef struct MD5Context {
	uint32_t state[4];	/* state (ABCD) */
	uint64_t count;		/* number of bits, modulo 2^64 (lsb first) */
	unsigned char buffer[MD5_BLOCK_LENGTH]; /* input buffer */
} MD5_CTX;

void	MD5Init(MD5_CTX *);
void	MD5Update(MD5_CTX *, const unsigned char *, size_t);
void	MD5Final(unsigned char[MD5_DIGEST_LENGTH], MD5_CTX *);
#endif


================================================
FILE: compat/crypt/sha256.c
================================================
/*-
 * SPDX-License-Identifier: BSD-2-Clause
 * Copyright 2005 Colin Percival
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

/* For BSD */
#if (defined(__unix__) || defined(unix)) && !defined(USG)
#include <sys/param.h>
#endif

#include <inttypes.h>
#include <string.h>

#ifdef __GLIBC__
#  include <endian.h>
#endif
#ifdef BSD
#  ifndef __QNX__
#    include <sys/endian.h>
#  endif
#endif

#include "config.h"
#include "sha256.h"

#if BYTE_ORDER == BIG_ENDIAN

/* Copy a vector of big-endian uint32_t into a vector of bytes */
#define be32enc_vect(dst, src, len)	\
	memcpy((void *)dst, (const void *)src, (size_t)len)

/* Copy a vector of bytes into a vector of big-endian uint32_t */
#define be32dec_vect(dst, src, len)	\
	memcpy((void *)dst, (const void *)src, (size_t)len)

#else /* BYTE_ORDER != BIG_ENDIAN */

/*
 * Encode a length len/4 vector of (uint32_t) into a length len vector of
 * (unsigned char) in big-endian form.  Assumes len is a multiple of 4.
 */
static void
be32enc_vect(unsigned char *dst, const uint32_t *src, size_t len)
{
	size_t i;

	for (i = 0; i < len / 4; i++)
		be32enc(dst + i * 4, src[i]);
}

/*
 * Decode a big-endian length len vector of (unsigned char) into a length
 * len/4 vector of (uint32_t).  Assumes len is a multiple of 4.
 */
static void
be32dec_vect(uint32_t *dst, const unsigned char *src, size_t len)
{
	size_t i;

	for (i = 0; i < len / 4; i++)
		dst[i] = be32dec(src + i * 4);
}

#endif /* BYTE_ORDER != BIG_ENDIAN */

/* Elementary functions used by SHA256 */
#define Ch(x, y, z)	((x & (y ^ z)) ^ z)
#define Maj(x, y, z)	((x & (y | z)) | (y & z))
#define SHR(x, n)	(x >> n)
#define ROTR(x, n)	((x >> n) | (x << (32 - n)))
#define S0(x)		(ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
#define S1(x)		(ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
#define s0(x)		(ROTR(x, 7) ^ ROTR(x, 18) ^ SHR(x, 3))
#define s1(x)		(ROTR(x, 17) ^ ROTR(x, 19) ^ SHR(x, 10))

/* SHA256 round function */
#define RND(a, b, c, d, e, f, g, h, k)			\
	t0 = h + S1(e) + Ch(e, f, g) + k;		\
	t1 = S0(a) + Maj(a, b, c);			\
	d += t0;					\
	h  = t0 + t1;

/* Adjusted round function for rotating state */
#define RNDr(S, W, i, k)			\
	RND(S[(64 - i) % 8], S[(65 - i) % 8],	\
	    S[(66 - i) % 8], S[(67 - i) % 8],	\
	    S[(68 - i) % 8], S[(69 - i) % 8],	\
	    S[(70 - i) % 8], S[(71 - i) % 8],	\
	    W[i] + k)

/*
 * SHA256 block compression function.  The 256-bit state is transformed via
 * the 512-bit input block to produce a new state.
 */
static void
SHA256_Transform(uint32_t * state, const unsigned char block[64])
{
	uint32_t W[64];
	uint32_t S[8];
	uint32_t t0, t1;
	int i;

	/* 1. Prepare message schedule W. */
	be32dec_vect(W, block, 64);
	for (i = 16; i < 64; i++)
		W[i] = s1(W[i - 2]) + W[i - 7] + s0(W[i - 15]) + W[i - 16];

	/* 2. Initialize working variables. */
	memcpy(S, state, 32);

	/* 3. Mix. */
	RNDr(S, W, 0, 0x428a2f98);
	RNDr(S, W, 1, 0x71374491);
	RNDr(S, W, 2, 0xb5c0fbcf);
	RNDr(S, W, 3, 0xe9b5dba5);
	RNDr(S, W, 4, 0x3956c25b);
	RNDr(S, W, 5, 0x59f111f1);
	RNDr(S, W, 6, 0x923f82a4);
	RNDr(S, W, 7, 0xab1c5ed5);
	RNDr(S, W, 8, 0xd807aa98);
	RNDr(S, W, 9, 0x12835b01);
	RNDr(S, W, 10, 0x243185be);
	RNDr(S, W, 11, 0x550c7dc3);
	RNDr(S, W, 12, 0x72be5d74);
	RNDr(S, W, 13, 0x80deb1fe);
	RNDr(S, W, 14, 0x9bdc06a7);
	RNDr(S, W, 15, 0xc19bf174);
	RNDr(S, W, 16, 0xe49b69c1);
	RNDr(S, W, 17, 0xefbe4786);
	RNDr(S, W, 18, 0x0fc19dc6);
	RNDr(S, W, 19, 0x240ca1cc);
	RNDr(S, W, 20, 0x2de92c6f);
	RNDr(S, W, 21, 0x4a7484aa);
	RNDr(S, W, 22, 0x5cb0a9dc);
	RNDr(S, W, 23, 0x76f988da);
	RNDr(S, W, 24, 0x983e5152);
	RNDr(S, W, 25, 0xa831c66d);
	RNDr(S, W, 26, 0xb00327c8);
	RNDr(S, W, 27, 0xbf597fc7);
	RNDr(S, W, 28, 0xc6e00bf3);
	RNDr(S, W, 29, 0xd5a79147);
	RNDr(S, W, 30, 0x06ca6351);
	RNDr(S, W, 31, 0x14292967);
	RNDr(S, W, 32, 0x27b70a85);
	RNDr(S, W, 33, 0x2e1b2138);
	RNDr(S, W, 34, 0x4d2c6dfc);
	RNDr(S, W, 35, 0x53380d13);
	RNDr(S, W, 36, 0x650a7354);
	RNDr(S, W, 37, 0x766a0abb);
	RNDr(S, W, 38, 0x81c2c92e);
	RNDr(S, W, 39, 0x92722c85);
	RNDr(S, W, 40, 0xa2bfe8a1);
	RNDr(S, W, 41, 0xa81a664b);
	RNDr(S, W, 42, 0xc24b8b70);
	RNDr(S, W, 43, 0xc76c51a3);
	RNDr(S, W, 44, 0xd192e819);
	RNDr(S, W, 45, 0xd6990624);
	RNDr(S, W, 46, 0xf40e3585);
	RNDr(S, W, 47, 0x106aa070);
	RNDr(S, W, 48, 0x19a4c116);
	RNDr(S, W, 49, 0x1e376c08);
	RNDr(S, W, 50, 0x2748774c);
	RNDr(S, W, 51, 0x34b0bcb5);
	RNDr(S, W, 52, 0x391c0cb3);
	RNDr(S, W, 53, 0x4ed8aa4a);
	RNDr(S, W, 54, 0x5b9cca4f);
	RNDr(S, W, 55, 0x682e6ff3);
	RNDr(S, W, 56, 0x748f82ee);
	RNDr(S, W, 57, 0x78a5636f);
	RNDr(S, W, 58, 0x84c87814);
	RNDr(S, W, 59, 0x8cc70208);
	RNDr(S, W, 60, 0x90befffa);
	RNDr(S, W, 61, 0xa4506ceb);
	RNDr(S, W, 62, 0xbef9a3f7);
	RNDr(S, W, 63, 0xc67178f2);

	/* 4. Mix local working variables into global state */
	for (i = 0; i < 8; i++)
		state[i] += S[i];
}

static unsigned char PAD[64] = {
	0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};

/* Add padding and terminating bit-count. */
static void
SHA256_Pad(SHA256_CTX * ctx)
{
	unsigned char len[8];
	uint32_t r, plen;

	/*
	 * Convert length to a vector of bytes -- we do this now rather
	 * than later because the length will change after we pad.
	 */
	be64enc(len, ctx->count);

	/* Add 1--64 bytes so that the resulting length is 56 mod 64 */
	r = (ctx->count >> 3) & 0x3f;
	plen = (r < 56) ? (56 - r) : (120 - r);
	SHA256_Update(ctx, PAD, (size_t)plen);

	/* Add the terminating bit-count */
	SHA256_Update(ctx, len, 8);
}

/* SHA-256 initialization.  Begins a SHA-256 operation. */
void
SHA256_Init(SHA256_CTX * ctx)
{

	/* Zero bits processed so far */
	ctx->count = 0;

	/* Magic initialization constants */
	ctx->state[0] = 0x6A09E667;
	ctx->state[1] = 0xBB67AE85;
	ctx->state[2] = 0x3C6EF372;
	ctx->state[3] = 0xA54FF53A;
	ctx->state[4] = 0x510E527F;
	ctx->state[5] = 0x9B05688C;
	ctx->state[6] = 0x1F83D9AB;
	ctx->state[7] = 0x5BE0CD19;
}

/* Add bytes into the hash */
void
SHA256_Update(SHA256_CTX * ctx, const void *in, size_t len)
{
	uint64_t bitlen;
	uint32_t r;
	const unsigned char *src = in;

	/* Number of bytes left in the buffer from previous updates */
	r = (ctx->count >> 3) & 0x3f;

	/* Convert the length into a number of bits */
	bitlen = len << 3;

	/* Update number of bits */
	ctx->count += bitlen;

	/* Handle the case where we don't need to perform any transforms */
	if (len < 64 - r) {
		memcpy(&ctx->buf[r], src, len);
		return;
	}

	/* Finish the current block */
	memcpy(&ctx->buf[r], src, 64 - r);
	SHA256_Transform(ctx->state, ctx->buf);
	src += 64 - r;
	len -= 64 - r;

	/* Perform complete blocks */
	while (len >= 64) {
		SHA256_Transform(ctx->state, src);
		src += 64;
		len -= 64;
	}

	/* Copy left over data into buffer */
	memcpy(ctx->buf, src, len);
}

/*
 * SHA-256 finalization.  Pads the input data, exports the hash value,
 * and clears the context state.
 */
void
SHA256_Final(unsigned char digest[32], SHA256_CTX * ctx)
{

	/* Add padding */
	SHA256_Pad(ctx);

	/* Write the hash */
	be32enc_vect(digest, ctx->state, 32);

	/* Clear the context state */
	memset((void *)ctx, 0, sizeof(*ctx));
}


================================================
FILE: compat/crypt/sha256.h
================================================
/*-
 * SPDX-License-Identifier: BSD-2-Clause
 * Copyright 2005 Colin Percival
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $FreeBSD$
 */

#ifndef SHA256_H_
#define SHA256_H_

#include <sys/types.h>

#define SHA256_DIGEST_LENGTH		32

typedef struct SHA256Context {
	uint32_t state[8];
	uint64_t count;
	unsigned char buf[64];
} SHA256_CTX;

void	SHA256_Init(SHA256_CTX *);
void	SHA256_Update(SHA256_CTX *, const void *, size_t);
void	SHA256_Final(unsigned char [32], SHA256_CTX *);

#endif


================================================
FILE: compat/crypt_openssl/hmac.c
================================================
/*
 * SPDX-License-Identifier: BSD-2-Clause
 * Copyright (c) 2023 Canonical Ltd.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#include <string.h>
#include <stdlib.h>

#include "config.h"

#include "openssl/hmac.h"

ssize_t
hmac(const char *name,
    const void *key, size_t klen,
    const void *text, size_t tlen,
    void *digest, size_t dlen)
{
	const EVP_MD	*md;
	unsigned int	 outlen;

	if (strcmp(name, "md5") == 0)
		md = EVP_md5();
	else if (strcmp(name, "sha256") == 0)
		md = EVP_sha1();
	else
		return -1;

	HMAC(md, key, (int)klen, text, tlen, digest, &outlen);
	if (dlen != outlen)
		return -1;

	return (ssize_t)outlen;
}


================================================
FILE: compat/crypt_openssl/hmac.h
================================================
/*
 * SPDX-License-Identifier: BSD-2-Clause
 * Copyright (c) 2023 Canonical Ltd.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#ifndef HMAC_H
#define HMAC_H

#include <sys/types.h>

ssize_t	 hmac(const char *, const void *, size_t, const void *, size_t, void *,
   size_t);

#endif


================================================
FILE: compat/crypt_openssl/sha256.c
================================================
/*
 * SPDX-License-Identifier: BSD-2-Clause
 * Copyright (c) 2023 Canonical Ltd.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#include "config.h"
#include "sha256.h"

#include "openssl/evp.h"

/* SHA-256 initialization.  Begins a SHA-256 operation. */
void
dhcpcd_SHA256_Init(SHA256_CTX *ctx)
{
	ctx->c = EVP_MD_CTX_new();
	EVP_DigestInit_ex2(ctx->c, EVP_sha256(), NULL);
}

/* Add bytes into the hash */
void
dhcpcd_SHA256_Update(SHA256_CTX *ctx, const void *in, size_t len)
{
	EVP_DigestUpdate(ctx->c, in, len);
}

/*
 * SHA-256 finalization.  Pads the input data, exports the hash value,
 * and clears the context state.
 */
void
dhcpcd_SHA256_Final(unsigned char digest[32], SHA256_CTX *ctx)
{
	EVP_DigestFinal_ex(ctx->c, digest, NULL);
	EVP_MD_CTX_free(ctx->c);
}


================================================
FILE: compat/crypt_openssl/sha256.h
================================================
/*
 * SPDX-License-Identifier: BSD-2-Clause
 * Copyright (c) 2023 Canonical Ltd.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#ifndef SHA256_H_
#define SHA256_H_

#define SHA256_DIGEST_LENGTH		32

#include "openssl/evp.h"
typedef struct dhcpcd_SHA256Context {
	EVP_MD_CTX *c;
} dhcpcd_SHA256_CTX;

void	dhcpcd_SHA256_Init(dhcpcd_SHA256_CTX *);
void	dhcpcd_SHA256_Update(dhcpcd_SHA256_CTX *, const void *, size_t);
void	dhcpcd_SHA256_Final(unsigned char [32], dhcpcd_SHA256_CTX *);

#define SHA256_Init	dhcpcd_SHA256_Init
#define SHA256_Update	dhcpcd_SHA256_Update
#define SHA256_Final	dhcpcd_SHA256_Final
#define SHA256_CTX	dhcpcd_SHA256_CTX

#endif


================================================
FILE: compat/dprintf.c
================================================
/*
 * dhcpcd - DHCP client daemon
 * SPDX-License-Identifier: BSD-2-Clause
 * Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
 * All rights reserved

 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <unistd.h>

#include "dprintf.h"

int
vdprintf(int fd, const char * __restrict fmt, va_list va)
{
	int e;
	FILE *fp;

	if ((e = dup(fd)) == -1)
		return -1;

	if ((fp = fdopen(e, "a")) == NULL) {
		close(e);
		return -1;
	}

	e = vfprintf(fp, fmt, va);
	fclose(fp);
	return e;
}

int
dprintf(int fd, const char * __restrict fmt, ...)
{
	int e;
	va_list va;

	va_start(va, fmt);
	e = vdprintf(fd, fmt, va);
	va_end(va);
	return e;
}


================================================
FILE: compat/dprintf.h
================================================
/*
 * dhcpcd - DHCP client daemon
 * SPDX-License-Identifier: BSD-2-Clause
 * Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
 * All rights reserved

 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#ifndef DPRINTF_H
#define DPRINTF_H

#include <stdarg.h>

#ifndef __printflike
# if __GNUC__ > 2 || defined(__INTEL_COMPILER)
#  define __printflike(a, b) __attribute__((format(printf, a, b)))
# else
#  define __printflike(a, b)
# endif
#endif

__printflike(2, 0) int vdprintf(int, const char * __restrict, va_list);
__printflike(2, 3) int dprintf(int, const char * __restrict, ...);
#endif


================================================
FILE: compat/endian.h
================================================
/*
 * dhcpcd - DHCP client daemon
 * SPDX-License-Identifier: BSD-2-Clause
 * Copyright (c) 2006-2014 Roy Marples <roy@marples.name>
 * All rights reserved

 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#ifndef ENDIAN_H
#define ENDIAN_H

#include <stdint.h>

inline static void
be32enc(uint8_t *buf, uint32_t u)
{

	buf[0] = (uint8_t)((u >> 24) & 0xff);
	buf[1] = (uint8_t)((u >> 16) & 0xff);
	buf[2] = (uint8_t)((u >> 8) & 0xff);
	buf[3] = (uint8_t)(u & 0xff);
}

inline static void
be64enc(uint8_t *buf, uint64_t u)
{

	be32enc(buf, (uint32_t)(u >> 32));
	be32enc(buf + sizeof(uint32_t), (uint32_t)(u & 0xffffffffULL));
}

inline static uint16_t
be16dec(const uint8_t *buf)
{

	return (uint16_t)(buf[0] << 8 | buf[1]);
}

inline static uint32_t
be32dec(const uint8_t *buf)
{

	return (uint32_t)((uint32_t)be16dec(buf) << 16 | be16dec(buf + 2));
}

inline static uint64_t
be64dec(const uint8_t *buf)
{

	return (uint64_t)((uint64_t)be32dec(buf) << 32 | be32dec(buf + 4));
}
#endif


================================================
FILE: compat/pidfile.c
================================================
/*	$NetBSD: pidfile.c,v 1.16 2021/08/01 15:29:29 andvar Exp $	*/

/*-
 * SPDX-License-Identifier: BSD-2-Clause
 * Copyright (c) 1999, 2016 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Jason R. Thorpe, Matthias Scheler, Julio Merino and Roy Marples.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include <sys/param.h>

#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <limits.h>
#include <paths.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

#include <sys/file.h>	/* for flock(2) */
#include "config.h"
#include "defs.h"

static pid_t pidfile_pid;
static char pidfile_path[PATH_MAX];
static int pidfile_fd = -1;

/* Closes pidfile resources.
 *
 * Returns 0 on success, otherwise -1. */
static int
pidfile_close(void)
{
	int error;

	pidfile_pid = 0;
	error = close(pidfile_fd);
	pidfile_fd = -1;
	pidfile_path[0] = '\0';
	return error;
}

/* Truncate, close and unlink an existent pidfile,
 * if and only if it was created by this process.
 * The pidfile is truncated because we may have dropped permissions
 * or entered a chroot and thus unable to unlink it.
 *
 * Returns 0 on truncation success, otherwise -1. */
int
pidfile_clean(void)
{
	int error;

	if (pidfile_fd == -1) {
		errno = EBADF;
		return -1;
	}

	if (pidfile_pid != getpid())
		error = EPERM;
	else if (ftruncate(pidfile_fd, 0) == -1)
		error = errno;
	else {
#ifndef HAVE_PLEDGE /* Avoid a pledge violating segfault. */
		(void)unlink(pidfile_path);
#endif
		error = 0;
	}

	(void) pidfile_close();

	if (error != 0) {
		errno = error;
		return -1;
	}
	return 0;
}

/* atexit shim for pidfile_clean */
static void
pidfile_cleanup(void)
{

	pidfile_clean();
}

/* Constructs a name for a pidfile in the default location (/var/run).
 * If 'bname' is NULL, uses the name of the current program for the name of
 * the pidfile.
 *
 * Returns 0 on success, otherwise -1. */
static int
pidfile_varrun_path(char *path, size_t len, const char *bname)
{

	if (bname == NULL)
		bname = PACKAGE;

	/* _PATH_VARRUN includes trailing / */
	if ((size_t)snprintf(path, len, "%s%s.pid", _PATH_VARRUN, bname) >= len)
	{
		errno = ENAMETOOLONG;
		return -1;
	}
	return 0;
}

/* Returns the process ID inside path on success, otherwise -1.
 * If no path is given, use the last pidfile path, otherwise the default one. */
pid_t
pidfile_read(const char *path)
{
	char dpath[PATH_MAX], buf[16], *eptr;
	int fd, error;
	ssize_t n;
	pid_t pid;

	if (path == NULL && pidfile_path[0] != '\0')
		path = pidfile_path;
	if (path == NULL || strchr(path, '/') == NULL) {
		if (pidfile_varrun_path(dpath, sizeof(dpath), path) == -1)
			return -1;
		path = dpath;
	}

	if ((fd = open(path, O_RDONLY | O_NONBLOCK)) == -1)
		return  -1;
	n = read(fd, buf, sizeof(buf) - 1);
	error = errno;
	(void) close(fd);
	if (n == -1) {
		errno = error;
		return -1;
	}
	buf[n] = '\0';
	pid = (pid_t)strtoi(buf, &eptr, 10, 1, INT_MAX, &error);
	if (error && !(error == ENOTSUP && *eptr == '\n')) {
		errno = error;
		return -1;
	}
	return pid;
}

/* Locks the pidfile specified by path and writes the process pid to it.
 * The new pidfile is "registered" in the global variables pidfile_fd,
 * pidfile_path and pidfile_pid so that any further call to pidfile_lock(3)
 * can check if we are recreating the same file or a new one.
 *
 * Returns 0 on success, otherwise the pid of the process who owns the
 * lock if it can be read, otherwise -1. */
pid_t
pidfile_lock(const char *path)
{
	char dpath[PATH_MAX];
	static bool registered_atexit = false;

	/* Register for cleanup with atexit. */
	if (!registered_atexit) {
		if (atexit(pidfile_cleanup) == -1)
			return -1;
		registered_atexit = true;
	}

	if (path == NULL || strchr(path, '/') == NULL) {
		if (pidfile_varrun_path(dpath, sizeof(dpath), path) == -1)
			return -1;
		path = dpath;
	}

	/* If path has changed (no good reason), clean up the old pidfile. */
	if (pidfile_fd != -1 && strcmp(pidfile_path, path) != 0)
		pidfile_clean();

	if (pidfile_fd == -1) {
		int fd, opts;

		opts = O_WRONLY | O_CREAT | O_NONBLOCK;
#ifdef O_CLOEXEC
		opts |= O_CLOEXEC;
#endif
#ifdef O_EXLOCK
		opts |=	O_EXLOCK;
#endif
		if ((fd = open(path, opts, 0644)) == -1)
			goto return_pid;
#ifndef O_CLOEXEC
		if ((opts = fcntl(fd, F_GETFD)) == -1 ||
		    fcntl(fd, F_SETFL, opts | FD_CLOEXEC) == -1)
		{
			int error = errno;

			(void) close(fd);
			errno = error;
			return -1;
		}
#endif
#ifndef O_EXLOCK
		if (flock(fd, LOCK_EX | LOCK_NB) == -1) {
			int error = errno;

			(void) close(fd);
			if (error != EAGAIN) {
				errno = error;
				return -1;
			}
			fd = -1;
		}
#endif

return_pid:
		if (fd == -1) {
			pid_t pid;

			if (errno == EAGAIN) {
				/* The pidfile is locked, return the process ID
				 * it contains.
				 * If successful, set errno to EEXIST. */
				if ((pid = pidfile_read(path)) != -1)
					errno = EEXIST;
			} else
				pid = -1;

			return pid;
		}
		pidfile_fd = fd;
		strlcpy(pidfile_path, path, sizeof(pidfile_path));
	}

	pidfile_pid = getpid();

	/* Truncate the file, as we could be re-writing it.
	 * Then write the process ID. */
	if (ftruncate(pidfile_fd, 0) == -1 ||
	    lseek(pidfile_fd, 0, SEEK_SET) == -1 ||
	    dprintf(pidfile_fd, "%d\n", (int)pidfile_pid) == -1)
	{
		int error = errno;

		pidfile_cleanup();
		errno = error;
		return -1;
	}

	/* Hold the fd open to persist the lock. */
	return 0;
}


================================================
FILE: compat/pidfile.h
================================================
/*-
 * SPDX-License-Identifier: BSD-2-Clause
 * Copyright (c) 1999, 2016 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Jason R. Thorpe, Matthias Scheler, Julio Merino and Roy Marples.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef PIDFILE_H
#define PIDFILE_H

#include <unistd.h>

int		pidfile_clean(void);
pid_t		pidfile_lock(const char *);
pid_t		pidfile_read(const char *);

#endif


================================================
FILE: compat/queue.h
================================================
/*
 * SPDX-License-Identifier: BSD-2-Clause
 * Copyright (c) 2014-2025 Roy Marples <roy@marples.name>
 */

/* This stub exists to avoid including queue.h in the vendor folder
 * for source imports */
#ifdef BSD
#include <sys/queue.h>
#else
#include "../vendor/queue.h"
#endif


================================================
FILE: compat/reallocarray.c
================================================
/* $NetBSD: reallocarr.c,v 1.4 2015/08/20 20:08:04 joerg Exp $ */

/*-
 * SPDX-License-Identifier: BSD-2-Clause
 * Copyright (c) 2015 Joerg Sonnenberger <joerg@NetBSD.org>.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#include <errno.h>
#include <limits.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>

/*
 * To be clear, this is NetBSD's more refined reallocarr(3) function
 * made to look like OpenBSD's more useable reallocarray(3) interface.
 */
#include "reallocarray.h"

#define SQRT_SIZE_MAX (((size_t)1) << (sizeof(size_t) * CHAR_BIT / 2))
void *
reallocarray(void *ptr, size_t n, size_t size)
{

	/*
	 * Try to avoid division here.
	 *
	 * It isn't possible to overflow during multiplication if neither
	 * operand uses any of the most significant half of the bits.
	 */
	if ((n | size) >= SQRT_SIZE_MAX && n > SIZE_MAX / size) {
		errno = EOVERFLOW;
		return NULL;
	}
	return realloc(ptr, n * size);
}


================================================
FILE: compat/reallocarray.h
================================================
/* $NetBSD: reallocarr.c,v 1.4 2015/08/20 20:08:04 joerg Exp $ */

/*-
 * SPDX-License-Identifier: BSD-2-Clause
 * Copyright (c) 2015 Joerg Sonnenberger <joerg@NetBSD.org>.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#ifndef REALLOCARRAY_H
#define REALLOCARRAY_H

void *reallocarray(void *, size_t, size_t);

#endif


================================================
FILE: compat/setproctitle.c
================================================
/*
 * SPDX-License-Identifier: MIT
 * Copyright © 2010 William Ahern
 * Copyright © 2012-2013 Guillem Jover <guillem@hadrons.org>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to permit
 * persons to whom the Software is furnished to do so, subject to the
 * following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
 * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
 * USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#include <errno.h>
#include <stddef.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <err.h>
#include <unistd.h>
#include <string.h>
//#include "local-link.h"

#include "config.h"

static struct {
	/* Original value. */
	char *arg0;

	/* Title space available. */
	char *base, *end;

	 /* Pointer to original nul character within base. */
	char *nul;

	bool warned;
	bool reset;
	int error;

	/* Our copy of args and environment to free. */
	int argc;
	char **argv;
	char **tmp_environ;
} SPT;


static inline size_t
spt_min(size_t a, size_t b)
{
	return a < b ? a : b;
}

/*
 * For discussion on the portability of the various methods, see
 * https://lists.freebsd.org/pipermail/freebsd-stable/2008-June/043136.html
 */
static int
spt_clearenv(void)
{
#ifdef HAVE_CLEARENV
	return clearenv();
#else
	SPT.tmp_environ = malloc(sizeof(*SPT.tmp_environ));
	if (SPT.tmp_environ == NULL)
		return errno;

	SPT.tmp_environ[0] = NULL;
	environ = SPT.tmp_environ;

	return 0;
#endif
}

static int
spt_copyenv(int envc, char *envp[])
{
	char **envcopy;
	char *eq;
	size_t envsize;
	int i, error;

	if (environ != envp)
		return 0;

	/* Make a copy of the old environ array of pointers, in case
	 * clearenv() or setenv() is implemented to free the internal
	 * environ array, because we will need to access the old environ
	 * contents to make the new copy. */
	envsize = (size_t)(envc + 1) * sizeof(char *);
	envcopy = malloc(envsize);
	if (envcopy == NULL)
		return errno;
	memcpy(envcopy, envp, envsize);

	error = spt_clearenv();
	if (error) {
		environ = envp;
		free(envcopy);
		return error;
	}

	for (i = 0; envcopy[i]; i++) {
		eq = strchr(envcopy[i], '=');
		if (eq == NULL)
			continue;

		*eq = '\0';
		if (setenv(envcopy[i], eq + 1, 1) < 0)
			error = errno;
		*eq = '=';

		if (error) {
#ifdef HAVE_CLEARENV
			/* Because the old environ might not be available
			 * anymore we will make do with the shallow copy. */
			environ = envcopy;
#else
			environ = envp;
			free(envcopy);
#endif
			return error;
		}
	}

	/* Dispose of the shallow copy, now that we've finished transfering
	 * the old environment. */
	free(envcopy);

	return 0;
}

static int
spt_copyargs(int argc, char *argv[])
{
	char *tmp;
	int i;

	for (i = 1; i < argc || (i >= argc && argv[i]); i++) {
		if (argv[i] == NULL)
			continue;

		tmp = strdup(argv[i]);
		if (tmp == NULL)
			return errno;

		argv[i] = tmp;
	}

	return 0;
}

void
setproctitle_init(int argc, char *argv[], char *envp[])
{
	char *base, *end, *nul, *tmp;
	int i, envc, error;

	/* Try to make sure we got called with main() arguments. */
	if (argc < 0)
		return;

	base = argv[0];
	if (base == NULL)
		return;

	nul = &base[strlen(base)];
	end = nul + 1;

	for (i = 0; i < argc || (i >= argc && argv[i]); i++) {
		if (argv[i] == NULL || argv[i] != end)
			continue;

		end = argv[i] + strlen(argv[i]) + 1;
	}

	for (i = 0; envp[i]; i++) {
		if (envp[i] != end)
			continue;

		end = envp[i] + strlen(envp[i]) + 1;
	}
	envc = i;

	SPT.arg0 = strdup(argv[0]);
	if (SPT.arg0 == NULL) {
		SPT.error = errno;
		return;
	}

	tmp = strdup(getprogname());
	if (tmp == NULL) {
		SPT.error = errno;
		return;
	}
	setprogname(tmp);

	error = spt_copyenv(envc, envp);
	if (error) {
		SPT.error = error;
		return;
	}

	error = spt_copyargs(argc, argv);
	if (error) {
		SPT.error = error;
		return;
	}

	SPT.argc = argc;
	SPT.argv = argv;

	SPT.nul  = nul;
	SPT.base = base;
	SPT.end  = end;
}

void
setproctitle_fini(void)
{
	int i;

	free(SPT.arg0);
	SPT.arg0 = NULL;

	for (i = 1; i < SPT.argc; i++) {
		if (SPT.argv[i] != NULL)
			free(SPT.argv[i]);
	}
	SPT.argc = 0;

	free(SPT.tmp_environ);
	SPT.tmp_environ = NULL;
}

#ifndef SPT_MAXTITLE
#define SPT_MAXTITLE 255
#endif

__printflike(1, 2) static void
setproctitle_impl(const char *fmt, ...)
{
	/* Use buffer in case argv[0] is passed. */
	char buf[SPT_MAXTITLE + 1];
	va_list ap;
	char *nul;
	int l;
	size_t len, base_len;

	if (SPT.base == NULL) {
		if (!SPT.warned) {
			warnx("setproctitle not initialized, please either call "
			      "setproctitle_init() or link against libbsd-ctor.");
			SPT.warned = true;
		}
		return;
	}

	if (fmt) {
		if (fmt[0] == '-') {
			/* Skip program name prefix. */
			fmt++;
			len = 0;
		} else {
			/* Print program name heading for grep. */
			l = snprintf(buf, sizeof(buf), "%s: ", getprogname());
			if (l <= 0)
				return;
			len = (size_t)l;
		}

		va_start(ap, fmt);
		l = vsnprintf(buf + len, sizeof(buf) - len, fmt, ap);
		va_end(ap);
	} else {
		len = 0;
		l = snprintf(buf, sizeof(buf), "%s", SPT.arg0);
	}

	if (l <= 0) {
		SPT.error = errno;
		return;
	}
	len += (size_t)l;

	base_len = (size_t)(SPT.end - SPT.base);
	if (!SPT.reset) {
		memset(SPT.base, 0, base_len);
		SPT.reset = true;
	} else {
		memset(SPT.base, 0, spt_min(sizeof(buf), base_len));
	}

	len = spt_min(len, spt_min(sizeof(buf), base_len) - 1);
	memcpy(SPT.base, buf, len);
	nul = &SPT.base[len];

	if (nul < SPT.nul) {
		*SPT.nul = '.';
	} else if (nul == SPT.nul && &nul[1] < SPT.end) {
		*SPT.nul = ' ';
		*++nul = '\0';
	}
}
libbsd_symver_default(setproctitle, setproctitle_impl, LIBBSD_0.5);

/* The original function introduced in 0.2 was a stub, it only got implemented
 * in 0.5, make the implementation available in the old version as an alias
 * for code linking against that version, and change the default to use the
 * new version, so that new code depends on the implemented version. */
#ifdef HAVE_TYPEOF
extern __typeof__(setproctitle_impl)
setproctitle_stub
	__attribute__((__alias__("setproctitle_impl")));
#else
void
setproctitle_stub(const char *fmt, ...)
	__attribute__((__alias__("setproctitle_impl")));
#endif
libbsd_symver_variant(setproctitle, setproctitle_stub, LIBBSD_0.2);


================================================
FILE: compat/setproctitle.h
================================================
/*
 * SPDX-License-Identifier: MIT
 * Copyright © 2010 William Ahern
 * Copyright © 2012-2013 Guillem Jover <guillem@hadrons.org>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to permit
 * persons to whom the Software is furnished to do so, subject to the
 * following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
 * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
 * USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#ifndef SETPROCTITLE_H
#define SETPROCTITLE_H

#ifndef __printflike
#if __GNUC__ > 2 || defined(__INTEL_COMPILER)
#define	__printflike(a, b) __attribute__((format(printf, a, b)))
#else
#define	__printflike(a, b)
#endif
#endif /* !__printflike */

/* WEXITSTATUS is defined in stdlib.h which defines free() */
#ifdef WEXITSTATUS
static inline const char *
getprogname(void)
{
	return "dhcpcd";
}
static inline void
setprogname(char *name)
{
	free(name);
}
#endif

void setproctitle_init(int, char *[], char *[]);
__printflike(1, 2) void setproctitle(const char *, ...);
void setproctitle_fini(void);

#define libbsd_symver_default(alias, symbol, version) \
    extern __typeof(symbol) alias __attribute__((__alias__(#symbol)))

#define libbsd_symver_variant(alias, symbol, version)
#endif


================================================
FILE: compat/strlcpy.c
================================================
/*	$OpenBSD: strlcpy.c,v 1.16 2019/01/25 00:19:25 millert Exp $	*/

/*
 * SPDX-License-Identifier: ISC
 * Copyright (c) 1998, 2015 Todd C. Miller <millert@openbsd.org>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <sys/types.h>

#include "strlcpy.h"

/*
 * Copy string src to buffer dst of size dsize.  At most dsize-1
 * chars will be copied.  Always NUL terminates (unless dsize == 0).
 * Returns strlen(src); if retval >= dsize, truncation occurred.
 */
size_t
strlcpy(char *dst, const char *src, size_t dsize)
{
	const char *osrc = src;
	size_t nleft = dsize;

	/* Copy as many bytes as will fit. */
	if (nleft != 0) {
		while (--nleft != 0) {
			if ((*dst++ = *src++) == '\0')
				break;
		}
	}

	/* Not enough room in dst, add NUL and traverse rest of src. */
	if (nleft == 0) {
		if (dsize != 0)
			*dst = '\0';		/* NUL-terminate dst */
		while (*src++)
			;
	}

	return (size_t)(src - osrc - 1);	/* count does not include NUL */
}


================================================
FILE: compat/strlcpy.h
================================================
/*	$OpenBSD: strlcpy.c,v 1.15 2016/10/16 17:37:39 dtucker Exp $	*/

/*
 * SPDX-License-Identifier: ISC
 * Copyright (c) 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#ifndef STRLCPY_H
#define STRLCPY_H

size_t strlcpy(char *, const char *, size_t);

#endif


================================================
FILE: compat/strtoi.c
================================================
/*	$NetBSD: strtoi.c,v 1.3 2019/11/28 12:33:23 roy Exp $	*/

/*-
 * SPDX-License-Identifier: BSD-2-Clause
 * Copyright (c) 2005 The DragonFly Project.  All rights reserved.
 * Copyright (c) 2003 Citrus Project,
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * Created by Kamil Rytarowski, based on ID:
 * NetBSD: src/common/lib/libc/stdlib/strtoul.c,v 1.3 2008/08/20 19:58:34 oster Exp
 */

#if defined(HAVE_NBTOOL_CONFIG_H) && HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif

#ifdef _LIBC
#include "namespace.h"
#endif

#if defined(_KERNEL)
#include <sys/param.h>
#include <sys/types.h>
#include <lib/libkern/libkern.h>
#elif defined(_STANDALONE)
#include <sys/param.h>
#include <sys/types.h>
#include <lib/libkern/libkern.h>
#include <lib/libsa/stand.h>
#else
#include <stddef.h>
#include <assert.h>
#include <errno.h>
#include <inttypes.h>
#endif

#include "strtoi.h"

#define	_FUNCNAME	strtoi
#define	__TYPE		intmax_t
#define	__WRAPPED	strtoimax

#include "_strtoi.h"

#ifdef _LIBC
__weak_alias(strtoi, _strtoi)
__weak_alias(strtoi_l, _strtoi_l)
#endif


================================================
FILE: compat/strtoi.h
================================================
/*-
 * SPDX-License-Identifier: BSD-3-Clause
 * Copyright (c) 1990, 1993
 *	The Regents of the University of California.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * Original version ID:
 * NetBSD: src/lib/libc/locale/_wcstoul.h,v 1.2 2003/08/07 16:43:03 agc Exp
 *
 * Created by Kamil Rytarowski, based on ID:
 * NetBSD: src/common/lib/libc/stdlib/_strtoul.h,v 1.7 2013/05/17 12:55:56 joerg Exp
 */

#ifndef STRTOI_H
#define STRTOI_H

#include <inttypes.h>

intmax_t strtoi(const char * __restrict nptr, char ** __restrict endptr,
    int base, intmax_t lo, intmax_t hi, int *rstatus);
uintmax_t strtou(const char * __restrict nptr, char ** __restrict endptr,
    int base, uintmax_t lo, uintmax_t hi, int *rstatus);
#endif


================================================
FILE: compat/strtou.c
================================================
/*	$NetBSD: strtou.c,v 1.3 2019/11/28 12:33:23 roy Exp $	*/

/*-
 * SPDX-License-Identifier: BSD-2-Clause
 * Copyright (c) 2005 The DragonFly Project.  All rights reserved.
 * Copyright (c) 2003 Citrus Project,
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * Created by Kamil Rytarowski, based on ID:
 * NetBSD: src/common/lib/libc/stdlib/strtoul.c,v 1.3 2008/08/20 19:58:34 oster Exp
 */

#if defined(HAVE_NBTOOL_CONFIG_H) && HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif

#ifdef _LIBC
#include "namespace.h"
#endif

#if defined(_KERNEL)
#include <sys/param.h>
#include <sys/types.h>
#include <lib/libkern/libkern.h>
#elif defined(_STANDALONE)
#include <sys/param.h>
#include <sys/types.h>
#include <lib/libkern/libkern.h>
#include <lib/libsa/stand.h>
#else
#include <stddef.h>
#include <assert.h>
#include <errno.h>
#include <inttypes.h>
#endif

#include "strtoi.h"

#define	_FUNCNAME	strtou
#define	__TYPE		uintmax_t
#define	__WRAPPED	strtoumax

#include "_strtoi.h"

#ifdef _LIBC
__weak_alias(strtou, _strtou)
__weak_alias(strtou_l, _strtou_l)
#endif


================================================
FILE: config-null.mk
================================================
# SPDX-License-Identifier: BSD-2-Clause
# Copyright (c) 2014 Roy Marples <roy@marples.name>

# This space left intentionally blank

DHCPCD_SRCS+=	dhcpcd-embedded.c


================================================
FILE: configure
================================================
#!/bin/sh
# SPDX-License-Identifier: BSD-2-Clause
# Copyright (c) 2009-2025 Roy Marples <roy@marples.name>

# Try and be like autotools configure, but without autotools

echo "configure args: $*"
exec 3>config.log

# Ensure that we do not inherit these from env
HOOKSET=false
INET=
ARP=
ARPING=
IPV4LL=
INET6=
PRIVSEP=
PRIVSEP_USER=
SECCOMP=
ARC4RANDOM=
CLOSEFROM=
RBTREE=
CONSTTIME_MEMEQUAL=
OPEN_MEMSTREAM=
STRLCPY=
UDEV=
OS=
BUILD=
HOST=
HOSTCC=
TARGET=
INCLUDEDIR=
DEBUG=
FORK=
STATIC=
DEVS=
EMBEDDED=
AUTH=
NTP=
POLL=
SMALL=
SANITIZE=no
STATUSARG=
OPENSSL=
LIBPCAP=

DHCPCD_DEFS=dhcpcd-definitions.conf

for x do
	opt=${x%%=*}
	var=${x#*=}
	case "$opt" in
	--os|OS) OS=$var;;
	--debug) DEBUG=$var;;
	--disable-debug) DEBUG=no;;
	--enable-debug) DEBUG=yes;;
	--fork) FORK=$var;;
	--disable-fork) FORK=no;;
	--enable-fork) FORK=yes;;
	--disable-static) STATIC=no;;
	--enable-static) STATIC=yes;;
	--disable-ipv4|--disable-inet) INET=no; ARP=no; ARPING=no; IPV4LL=no;;
	--enable-ipv4|--enable-inet) INET=yes;;
	--disable-arp) ARP=no; ARPING=no; IPV4LL=no;;
	--enable-arp) ARP=yes; INET=yes;;
	--disable-arping) ARPING=no;;
	--enable-arping) ARPING=yes; ARP=yes; INET=yes;;
	--disable-ipv4ll) IPV4LL=no;;
	--enable-ipv4ll) IPV4LL=yes; ARP=yes; INET=yes;;
	--disable-ipv6|--disable-inet6) INET6=no; DHCP6=no;;
	--enable-ipv6|--enable-inet6) INET6=yes;;
	--disable-dhcp6) DHCP6=no;;
	--enable-dhcp6) DHCP6=yes;;
	--disable-embedded) EMBEDDED=no;;
	--enable-embedded) EMBEDDED=yes;;
	--disable-auth) AUTH=no;;
	--enable-auth) AUTH=yes;;
	--disable-privsep) PRIVSEP=no;;
	--enable-privsep) PRIVSEP=yes;;
	--disable-seccomp) SECCOMP=no;;
	--enable-seccomp) SECCOMP=yes;;
	--disable-ntp) NTP=no;;
	--enable-ntp) NTP=yes;;
	--privsepuser) PRIVSEP_USER=$var;;
	--prefix) PREFIX=$var;prefix=$var;; # prefix is set for autotools compat
	--sysconfdir) SYSCONFDIR=$var;;
	--bindir|--sbindir) SBINDIR=$var;;
	--libexecdir) LIBEXECDIR=$var;;
	--statedir|--localstatedir) STATEDIR=$var;;
	--dbdir) DBDIR=$var;;
	--rundir) RUNDIR=$var;;
	--runstatedir) RUNSTATEDIR=$var;;
	--mandir) MANDIR=$var;;
	--datadir) DATADIR=$var;;
	--with-ccopts|CFLAGS) CFLAGS=$var;;
	-I|--includedir) INCLUDEDIR="$INCLUDEDIR${INCLUDEDIR:+ }-I$var";;
	CC) CC=$var;;
	CPPFLAGS) CPPFLAGS=$var;;
	PKG_CONFIG) PKG_CONFIG=$var;;
	--with-hook) HOOKSCRIPTS="$HOOKSCRIPTS${HOOKSCRIPTS:+ }$var";;
	--with-hooks|HOOKSCRIPTS) HOOKSCRIPTS=$var; HOOKSET=true;;
	--with-eghook) EGHOOKSCRIPTS="$EGHOOKSCRIPTS${EGHOOKSCRIPTS+ }$var";;
	--with-eghooks|EGHOOKSCRIPTS) EGHOOKSCRIPTS=$var; EGHOOKSET=true;;
	--with-default-hostname) _DEFAULT_HOSTNAME=$var;;
	--build) BUILD=$var;;
	--host) HOST=$var; HOSTCC=$var-;;
	--target) TARGET=$var;;
	--libdir) LIBDIR=$var;;
	--without-arc4random) ARC4RANDOM=no;;
	--without-strlcpy) STRLCPY=no;;
	--without-pidfile_lock) PIDFILE_LOCK=no;;
	--without-reallocarrray) REALLOCARRAY=no;;
	--without-md5) MD5=no;;
	--without-sha2) SHA2=no;;
	--without-sha256) SHA2=no;;
	--without-hmac) HMAC=no;;
	--without-dev) DEV=no;;
	--with-udev) DEV=yes; UDEV=yes;;
	--without-udev) UDEV=no;;
	--with-poll) POLL="$var";;
	--with-openssl) OPENSSL=yes;;
	--without-openssl) OPENSSL=no;;
	--with-libpcap) LIBPCAP=yes;;
	--without-libpcap) LIBPCAP=no;;
	--sanitise|--sanitize) SANITIZEADDRESS="yes";;
	--serviceexists) SERVICEEXISTS=$var;;
	--servicecmd) SERVICECMD=$var;;
	--servicestatus) SERVICESTATUS=$var;;
	--small) SMALL=yes;;
	--statusarg) STATUSARG=$var;;
	--infodir) ;; # ignore autotools
	--disable-maintainer-mode|--disable-dependency-tracking) ;;
	--disable-option-checking|--disable-silent-rules) ;;
	-V|--version)
		v=$(sed -ne 's/.*VERSION[[:space:]]*"\([^"]*\).*/\1/p' defs.h);
		c=$(sed -ne 's/^.*copyright\[\] = "\([^"]*\).*/\1/p' dhcpcd.c);
		echo "dhcpcd-$v $c";
		exit 0;;
	-h|--help) cat <<EOF
\`configure' configures this package to adapt to many kinds of systems.

Usage: configure [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.

Configuration:
  -h, --help              display this help and exit
      --help=short        display options specific to this package
  -V, --version           display version information and exit

Installation directories:
  --prefix=PREFIX         install architecture-independent files in PREFIX [/]

By default, \`make install' will install all the files in \'/sbin',
\`/libexec', etc. You can specify
an installation prefix other than \`/' using \`--prefix',
for instance \`--prefix=$HOME'.

For better control, use the options below.

Fine tuning of the installation directories:
  --bindir=DIR            user executables [PREFIX/bin]
  --sbindir=DIR           system admin executables [PREFIX/sbin]
  --libexecdir=DIR        program executables [PREFIX/libexec]
  --dbdir=DIR             database [STATEDIR/db/dhcpcd]
  --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
  --localstatedir=DIR     modifiable single-machine data [/var]
  --libdir=DIR            object code libraries [PREFIX/lib]
  --includedir=DIR        C header files [PREFIX/include]
  --mandir=DIR            man documentation [PREFIX/man]

System types:
  --build=BUILD           configure for building on BUILD [guessed]
  --host=HOST             build programs to run on HOST [BUILD]
  --target=TARGET         configure for building compilers for TARGET [HOST]

Optional Features:
  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]

Some influential environment variables:
  CC          C compiler command
  CFLAGS      C compiler flags
  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
	      nonstandard directory <lib dir>
  CPPFLAGS    C/C++ preprocessor flags, e.g. -I<include dir> if you have
	      headers in a nonstandard directory <include dir>
  CPP         C preprocessor
  PKG_CONFIG  pkg-config executable

Use these variables to override the choices made by \`configure' or to help
it to find libraries and programs with nonstandard names/locations.
EOF
exit 0
;;
	*) echo "$0: WARNING: unknown option $opt" >&2;;
	esac
done

: ${SED:=sed}
: ${GREP:=grep}
: ${PKG_CONFIG:=pkg-config}
: ${WC:=wc}

: ${FORK:=yes}
_which()
{
	x="$(which "$1" 2>/dev/null)"
	if [ $? = 0 ] && [ -n "$x" ]; then
		echo "$x"
		return 0
	fi
	for x in /sbin/"$1" /usr/sbin/"$1" \
		/usr/pkg/sbin/"$1" /usr/local/sbin/"$1"
	do
		if [ -e "$x" ]; then
			echo "$x"
			return 0
		fi
	done
	return 1
}

CONFIG_H=config.h
CONFIG_MK=config.mk

if [ -z "$BUILD" ]; then
	# autoconf target triplet: cpu-vendor-os
	BUILD=$(uname -m)-unknown-$(uname -s | tr '[:upper:]' '[:lower:]')
fi
: ${HOST:=$BUILD}

if [ -z "$OS" ]; then
	echo "Deriving operating system from ... $HOST"
	# Derive OS from cpu-vendor-[kernel-]os
	CPU=${HOST%%-*}
	REST=${HOST#*-}
	if [ "$CPU" != "$REST" ]; then
		VENDOR=${REST%%-*}
		REST=${REST#*-}
		if [ "$VENDOR" != "$REST" ]; then
			# Use kernel if given, otherwise os
			OS=${REST%%-*}
		else
			# 2 tupple
			OS=$VENDOR
			VENDOR=
		fi
	fi

	# Work with cpu-kernel-os, ie Debian
	case "$VENDOR" in
	linux*|kfreebsd*) OS=$VENDOR; VENDOR= ;;
	esac
	case "$REST" in
	gnu/kfreebsd*)		OS="kfreebsd"; VENDOR= ;;
	esac
	# Special case
	case "$OS" in
	dragonfly*)
		# This means /usr HAS to be mounted not via dhcpcd
		: ${LIBEXECDIR:=${PREFIX:-/usr}/libexec}
		;;
	gnu*) OS=hurd;; # No HURD support as yet
	esac
fi

echo "Configuring dhcpcd for ... $OS"
rm -f $CONFIG_H $CONFIG_MK
echo "# $OS" >$CONFIG_MK
echo "/* $OS */" >$CONFIG_H
echo >>$CONFIG_H
echo "#ifndef CONFIG_H">>$CONFIG_H
echo "#define CONFIG_H">>$CONFIG_H
echo >>$CONFIG_H

: ${SYSCONFDIR:=$PREFIX/etc}
: ${SBINDIR:=$PREFIX/sbin}
: ${LIBDIR:=$PREFIX/lib}
: ${LIBEXECDIR:=$PREFIX/libexec}
: ${STATEDIR:=/var}
: ${DBDIR:=$STATEDIR/db/dhcpcd}
: ${RUNSTATEDIR:=$STATEDIR/run}
: ${RUNDIR:=$RUNSTATEDIR/dhcpcd}
: ${MANDIR:=${PREFIX:-/usr}/share/man}
: ${DATADIR:=${PREFIX:-/usr}/share}

eval SYSCONFDIR="$SYSCONFDIR"
eval LIBDIR="$LIBDIR"
eval LIBEXECDIR="$LIBEXECDIR"
eval STATEDIR="$STATEDIR"
eval DBDIR="$DBDIR"
eval RUNDIR="$RUNDIR"
eval MANDIR="$MANDIR"
eval DATADIR="$DATADIR"

echo "#ifndef	SYSCONFDIR" >>$CONFIG_H
for x in SYSCONFDIR SBINDIR LIBDIR LIBEXECDIR DBDIR RUNDIR; do
	eval v=\$$x
	# Make files look nice for import
	l=$((10 - ${#x}))
	unset t
	[ $l -gt 3 ] && t="	"
	echo "$x=$t	$v" >>$CONFIG_MK
	unset t
	[ $l -gt 2 ] && t="	"
	echo "#define	$x$t		\"$v\"" >>$CONFIG_H
done
echo "#endif" >>$CONFIG_H

echo "LIBDIR=		$LIBDIR" >>$CONFIG_MK
echo "MANDIR=		$MANDIR" >>$CONFIG_MK
echo "DATADIR=	$DATADIR" >>$CONFIG_MK

# Always obey CC.
if [ -n "$CC" ]; then
	HOSTCC=
else
	CC=cc
	_COMPILERS="cc clang gcc pcc icc"
fi
# Only look for a cross compiler if --host and --build are not the same
if [ -n "$HOSTCC" ] && [ "$BUILD" != "$HOST" ]; then
	for _CC in $_COMPILERS; do
		_CC=$(_which "$HOSTCC$_CC")
		if [ -x "$_CC" ]; then
			CC=$_CC
			break
		fi
	done
fi
if ! type "$CC" >/dev/null 2>&1; then
	for _CC in $_COMPILERS; do
		_CC=$(_which "$_CC")
		if [ -x "$_CC" ]; then
			CC=$_CC
			break
		fi
	done
fi

# Set to blank, then append user config
# We do this so our SED call to append to XCC remains portable
if [ -n "$CFLAGS" ]; then
	echo "CFLAGS=" >>$CONFIG_MK
	echo "CFLAGS+=	$CFLAGS" >>$CONFIG_MK
fi
if [ -n "$CPPFLAGS" ]; then
	echo "CPPFLAGS=" >>$CONFIG_MK
	echo "CPPFLAGS+=	$CPPFLAGS" >>$CONFIG_MK
fi
if [ -n "$INCLUDEDIR" ]; then
	echo "CPPFLAGS+=	$INCLUDEDIR" >>$CONFIG_MK
fi
if [ -n "$LDFLAGS" ]; then
	echo "LDFLAGS=" >>$CONFIG_MK
	echo "LDFLAGS+=	$LDFLAGS" >>$CONFIG_MK
fi

echo "CPPFLAGS+=	-DHAVE_CONFIG_H" >>$CONFIG_MK

# NetBSD: Even if we build for $PREFIX, the clueless user might move us to /
LDELF=/libexec/ld.elf_so
if [ -e "$LDELF" ]; then
	echo "Linking against $LDELF"
	echo "LDFLAGS+=	-Wl,-dynamic-linker=$LDELF" >>$CONFIG_MK
	echo "LDFLAGS+=	-Wl,-rpath=${LIBDIR}" >>$CONFIG_MK
fi

if [ -z "$PREFIX" ] || [ "$PREFIX" = / ]; then
	ALLOW_USR_LIBS=false
else
	ALLOW_USR_LIBS=true
fi
case "$OS" in
linux*|solaris*|sunos*|kfreebsd*|dragonfly*|freebsd*) ;;
*)
	# There might be more than one ...
	for LDELFN in /libexec/ld-elf.so.[0-9]*; do
		[ -x "$LDELFN" ] && break
	done
	if ! [ -x "$LDELF" ] || [ -x "$LDELFN" ]; then
	    if [ -z "$PREFIX" ] || [ "$PREFIX" = "/" ]; then
			echo "Forcing a static build for $OS and \$PREFIX of /"
			STATIC=yes
			ALLOW_USR_LIBS=true
		fi
	fi
	;;
esac
if [ "$STATIC" = yes ]; then
	echo "LDFLAGS+=	-static" >>$CONFIG_MK
fi

if [ -z "$DEBUG" ] && [ -d .git ]; then
	printf "Found git checkout ... "
	DEBUG=yes
fi
if [ -n "$DEBUG" ] && [ "$DEBUG" != no ] && [ "$DEBUG" != false ]; then
	echo "Adding debugging CFLAGS"

	cat <<EOF >>$CONFIG_MK
CFLAGS+=	-g -Wall -Wextra -Wundef
CFLAGS+=	-Wmissing-prototypes -Wmissing-declarations
CFLAGS+=	-Wmissing-format-attribute -Wnested-externs
CFLAGS+=	-Winline -Wcast-align -Wcast-qual -Wpointer-arith
CFLAGS+=	-Wreturn-type -Wswitch -Wshadow
CFLAGS+=	-Wcast-qual -Wwrite-strings
CFLAGS+=	-Wformat=2
CFLAGS+=	-Wpointer-sign -Wmissing-noreturn
EOF

	case "$OS" in
	mirbsd*|openbsd*);; # OpenBSD has many redundant decs in system headers
	bitrig*|solaris*|sunos*)
			echo "CFLAGS+=	-Wredundant-decls" >>$CONFIG_MK
			;; # Bitrig spouts many conversion errors with htons
			   # sunos has many as well
	*)		echo "CFLAGS+=	-Wredundant-decls" >>$CONFIG_MK
			echo "CFLAGS+=	-Wconversion" >>$CONFIG_MK
			;;
	esac

	case "$OS" in
	solaris*|sunos*);;
	*)		echo "CFLAGS+=	-Wstrict-overflow" >>$CONFIG_MK;;
	esac

	# Turn on extra per compiler debugging
	case "$CC" in
	*gcc*)		echo "CFLAGS+=	-Wlogical-op" >>$CONFIG_MK;;
	esac

	if [ "$SANITIZEADDRESS" = yes ]; then
		printf "Testing compiler supports address sanitisation ..."
	cat <<EOF >_test.c
int main(void) {
	return 0;
}
EOF
		if $CC -fsanitize=address _test.c -o _test 2>&3; then
			echo "yes"
			echo "CPPFLAGS+=	-DASAN" >>$CONFIG_MK
			echo "CFLAGS+=	-fsanitize=address" >>$CONFIG_MK
			echo "CFLAGS+=	-fno-omit-frame-pointer" >>$CONFIG_MK
			echo "LDFLAGS+=	-fsanitize=address" >>$CONFIG_MK
		else
			echo "no"
		fi
		rm -rf _test.c _test
	fi
else
	echo "CPPFLAGS+=	-DNDEBUG" >>$CONFIG_MK
fi

if [ -n "$FORK" ] && [ "$FORK" != yes ] && [ "$FORK" != true ]; then
	echo "There is no fork"
	echo "CPPFLAGS+=	-DTHERE_IS_NO_FORK" >>$CONFIG_MK
fi

if [ "$SMALL" = yes ]; then
	echo "Building with -DSMALL"
	echo "CPPFLAGS+=	-DSMALL" >>$CONFIG_MK
	DHCPCD_DEFS=dhcpcd-definitions-small.conf
	echo "DHCPCD_DEFS=	$DHCPCD_DEFS" >>$CONFIG_MK
fi

BPF_OS=
case "$OS" in
freebsd*|kfreebsd*)
	# FreeBSD hide some newer POSIX APIs behind _GNU_SOURCE ...
	echo "CPPFLAGS+=	-D_GNU_SOURCE" >>$CONFIG_MK
	case "$OS" in
	kfreebsd*)	echo "CPPFLAGS+=	-DBSD" >>$CONFIG_MK;;
	esac
	echo "DHCPCD_SRCS+=	if-bsd.c" >>$CONFIG_MK
	# Whacky includes needed to buck the trend
	case "$OS" in
	kfreebsd*)	echo "#include		<inttypes.h>" >>$CONFIG_H;
	esac
	echo "#include			<net/if.h>" >>$CONFIG_H
	echo "#include			<net/if_var.h>" >>$CONFIG_H
	;;
netbsd*)
	# reallocarray(3) is guarded by _OPENBSD_SOURCE
	echo "CPPFLAGS+=	-D_OPENBSD_SOURCE" >>$CONFIG_MK
	echo "DHCPCD_SRCS+=	if-bsd.c" >>$CONFIG_MK
	;;
linux*)
	echo "CPPFLAGS+=	-D_GNU_SOURCE" >>$CONFIG_MK
	# Large File Support, should be fine for 32-bit systems.
	# But if this is the case, why is it not set by default?
	echo "CPPFLAGS+=	-D_FILE_OFFSET_BITS=64" >>$CONFIG_MK
	echo "CPPFLAGS+=	-D_LARGEFILE_SOURCE" >>$CONFIG_MK
	echo "CPPFLAGS+=	-D_LARGEFILE64_SOURCE" >>$CONFIG_MK
	echo "DHCPCD_SRCS+=	if-linux.c" >>$CONFIG_MK
	# for RTM_NEWADDR and friends
	echo "#include		<asm/types.h> /* fix broken headers */" >>$CONFIG_H
	echo "#include		<sys/socket.h> /* fix broken headers */" >>$CONFIG_H
	echo "#include		<linux/rtnetlink.h>" >>$CONFIG_H
	BPF_OS="bpf-linux.c"
	# cksum does't support -a and netpgp is rare
	echo "CKSUM=		sha256sum --tag" >>$CONFIG_MK
	echo "PGP=		gpg2" >>$CONFIG_MK
	;;
qnx*)
	echo "CPPFLAGS+=	-D__EXT" >>$CONFIG_MK
	echo "DHCPCD_SRCS+=	if-bsd.c" >>$CONFIG_MK
	;;
solaris*|sunos*)
	echo "CPPFLAGS+=	-D_XPG4_2 -D__EXTENSIONS__ -DBSD_COMP" \
	    >>$CONFIG_MK
	echo "DHCPCD_SRCS+=	if-sun.c" >>$CONFIG_MK
	echo "LDADD+=		-ldlpi -lkstat" >>$CONFIG_MK
	BPF_OS="bpf-bsd.c bpf-dlpi.c"
	;;
*)
	echo "DHCPCD_SRCS+=	if-bsd.c" >>$CONFIG_MK
	;;
esac

if [ -z "$BPF_OS" ]; then
	BPF_OS="bpf-bsd.c"
fi
if [ "$LIBPCAP" = yes ]; then
	BPF_OS="bpf-pcap.c"
fi

if [ -n "${_DEFAULT_HOSTNAME+x}" ]; then
	DEFAULT_HOSTNAME="${_DEFAULT_HOSTNAME}"
else
	case "$OS" in
	linux*)	DEFAULT_HOSTNAME="(none)";;
	*)	DEFAULT_HOSTNAME="";;
	esac
fi
echo "DEFAULT_HOSTNAME=		$DEFAULT_HOSTNAME" >>$CONFIG_MK

if [ -z "$INET" ] || [ "$INET" = yes ]; then
	echo "Enabling INET support"
	echo "CPPFLAGS+=	-DINET" >>$CONFIG_MK
	echo "DHCPCD_SRCS+=	dhcp.c ipv4.c bpf.c $BPF_OS" >>$CONFIG_MK
	if [ -z "$ARP" ] || [ "$ARP" = yes ]; then
		echo "Enabling ARP support"
		echo "CPPFLAGS+=	-DARP" >>$CONFIG_MK
		echo "DHCPCD_SRCS+=	arp.c" >>$CONFIG_MK
	fi
	if [ -z "$ARPING" ] || [ "$ARPING" = yes ]; then
		echo "Enabling ARPing support"
		echo "CPPFLAGS+=	-DARPING" >>$CONFIG_MK
	fi
	if [ -z "$IPV4LL" ] || [ "$IPV4LL" = yes ]; then
		echo "Enabling IPv4LL support"
		echo "CPPFLAGS+=	-DIPV4LL" >>$CONFIG_MK
		echo "DHCPCD_SRCS+=	ipv4ll.c" >>$CONFIG_MK
	fi
fi
if [ -z "$INET6" ] || [ "$INET6" = yes ]; then
	echo "Enabling INET6 support"
	echo "CPPFLAGS+=	-DINET6" >>$CONFIG_MK
	echo "DHCPCD_SRCS+=	ipv6.c ipv6nd.c" >>$CONFIG_MK
	if [ -z "$DHCP6" ] || [ "$DHCP6" = yes ]; then
		echo "Enabling DHCPv6 support"
		echo "CPPFLAGS+=	-DDHCP6" >>$CONFIG_MK
		echo "DHCPCD_SRCS+=	dhcp6.c" >>$CONFIG_MK
	fi
fi
if [ -z "$AUTH" ] || [ "$AUTH" = yes ]; then
	echo "Enabling Authentication"
	echo "CPPFLAGS+=	-DAUTH" >>$CONFIG_MK
	echo "SRCS+=		auth.c" >>$CONFIG_MK
fi

if [ -z "$PRIVSEP" ]; then
	# privilege separation works fine .... except on Solaris
	case "$OS" in
	solaris*|sunos*)	PRIVSEP=no;;
	*)			PRIVSEP=yes;;
	esac
fi

if [ "$PRIVSEP" = yes ]; then
	echo "Enabling Privilege Separation"

	# Try and work out system user
	if [ -z "$PRIVSEP_USER" ]; then
		printf "Detecting a suitable user for dhcpcd ... "
		for x in _dhcpcd _dhcp dhcpcd; do
			home=$(getent passwd $x 2>/dev/null | cut -d: -f6)
			if [ -d "$home" ]; then
				PRIVSEP_USER="$x"
				break
			fi
		done
	fi
	if [ -n "$PRIVSEP_USER" ]; then
		echo "$PRIVSEP_USER"
	else
		PRIVSEP_USER=dhcpcd
		echo
		echo "No suitable user found for Priviledge Separation!"
	fi

	echo "CPPFLAGS+=	-DPRIVSEP" >>$CONFIG_MK
	echo "PRIVSEP_USER?=	$PRIVSEP_USER" >>$CONFIG_MK
	echo "#ifndef PRIVSEP_USER" >>$CONFIG_H
	echo "#define PRIVSEP_USER		 \"$PRIVSEP_USER\"" >>$CONFIG_H
	echo "#endif" >>$CONFIG_H
	echo "PRIVSEP_SRCS=	privsep.c privsep-root.c" >>$CONFIG_MK
	echo "PRIVSEP_SRCS+=	privsep-control.c privsep-inet.c" >>$CONFIG_MK
	if [ -z "$INET" ] || [ "$INET" = yes ]; then
		echo "PRIVSEP_SRCS+=	privsep-bpf.c" >>$CONFIG_MK
	fi
	case "$OS" in
	linux*)
			 echo "PRIVSEP_SRCS+=	privsep-linux.c" >>$CONFIG_MK
			 if [ -n "$SECCOMP" ] && [ "$SECCOMP" = no ]; then
				 echo "#define	DISABLE_SECCOMP" >>$CONFIG_H
			 fi
			 ;;
	solaris*|sunos*) echo "PRIVSEP_SRCS+=	privsep-sun.c" >>$CONFIG_MK;;
	*)		 echo "PRIVSEP_SRCS+=	privsep-bsd.c" >>$CONFIG_MK;;
	esac
else
	echo "PRIVSEP_SRCS=" >>$CONFIG_MK
fi

echo "Using compiler .. $CC"
# Add CPPFLAGS and CFLAGS to CC for testing features
XCC="$CC `$SED -n -e 's/CPPFLAGS+=*\(.*\)/\1/p' $CONFIG_MK`"
XCC="$XCC `$SED -n -e 's/CFLAGS+=*\(.*\)/\1/p' $CONFIG_MK`"

# When running tests, treat all warnings as errors.
# This avoids the situation where we link to a libc symbol
# without the correct header because it might be hidden behind
# a _*_SOURCE #define guard.
XCC="$XCC -Wall -Werror"

# Now test we can use the compiler with our CFLAGS
cat <<EOF >_test.c
int main(void) {
	return 0;
}
EOF
_CC=false
if $XCC _test.c -o _test >/dev/null 2>&3; then
	[ -x _test ] && _CC=true
fi
rm -f _test.c _test
if ! $_CC; then
	echo $XCC
	echo "$CC does not create executables" >&2
	exit 1
fi
[ "$CC" != cc ] && echo "CC=		$CC" >>$CONFIG_MK
$CC --version | $SED -e '1!d'

if [ "$PRIVSEP" = yes ]; then
	printf "Testing for capsicum ... "
	cat <<EOF >_capsicum.c
#include <sys/capsicum.h>
int main(void) {
	return cap_enter();
}
EOF
	if $XCC _capsicum.c -o _capsicum 2>&3; then
		echo "yes"
		echo "#define	HAVE_CAPSICUM" >>$CONFIG_H
	else
		echo "no"
	fi
	rm -f _capsicum.c _capsicum

	printf "Testing for pledge ... "
	cat <<EOF >_pledge.c
#include <unistd.h>
int main(void) {
	return pledge("stdio", NULL);
}
EOF
	if $XCC _pledge.c -o _pledge 2>&3; then
		echo "yes"
		echo "#define	HAVE_PLEDGE" >>$CONFIG_H
	else
		echo "no"
	fi
	rm -f _pledge.c _pledge
fi

# This block needs to be after the compiler test due to embedded quotes.
if [ -z "$EMBEDDED" ] || [ "$EMBEDDED" = yes ]; then
	echo "$DHCPCD_DEFS will be embedded in dhcpcd itself"
	echo "DHCPCD_SRCS+=	dhcpcd-embedded.c" >>$CONFIG_MK
else
	echo "$DHCPCD_DEFS will be installed to $LIBEXECDIR"
	echo "CPPFLAGS+=	-DEMBEDDED_CONFIG=\\\"$LIBEXECDIR/dhcpcd-definitions.conf\\\"" >>$CONFIG_MK
	echo "EMBEDDEDINSTALL=	_embeddedinstall" >>$CONFIG_MK
fi

if [ "$OS" = linux ]; then
	printf "Testing for nl80211 ... "
	cat <<EOF >_nl80211.c
#include <linux/nl80211.h>
int main(void) {
	return 0;
}
EOF
	if $XCC _nl80211.c -o _nl80211 2>&3; then
		echo "yes"
		echo "#define	HAVE_NL80211_H" >>$CONFIG_H
	else
		echo "no"
		echo "DHCPCD_SRCS+=	if-linux-wext.c" >>$CONFIG_MK
	fi
	rm -f _nl80211.c _nl80211

	printf "Testing for IN6_ADDR_GEN_MODE_NONE ... "
	cat <<EOF >_IN6_ADDR_GEN_MODE_NONE.c
#include <linux/if_link.h>
int main(void) {
	int x = IN6_ADDR_GEN_MODE_NONE;
	return x;
}
EOF
	if $XCC _IN6_ADDR_GEN_MODE_NONE.c -o _IN6_ADDR_GEN_MODE_NONE 2>&3; then
		echo "yes"
		echo "#define	HAVE_IN6_ADDR_GEN_MODE_NONE" >>$CONFIG_H
	else
		echo "no"
	fi
	rm -f _IN6_ADDR_GEN_MODE_NONE.c _IN6_ADDR_GEN_MODE_NONE
else
	printf "Testing for ifam_pid ... "
	cat <<EOF >_ifam_pid.c
#include <net/if.h>
int main(void) {
	struct ifa_msghdr ifam = { };
	return (int)ifam.ifam_pid;
}
EOF
	if $XCC _ifam_pid.c -o _ifam_pid 2>&3; then
		echo "yes"
		echo "#define	HAVE_IFAM_PID" >>$CONFIG_H
	else
		echo "no"
	fi
	rm -f _ifam_pid.c _ifam_pid

	printf "Testing for ifam_addrflags ... "
	cat <<EOF >_ifam_addrflags.c
#include <net/if.h>
int main(void) {
	struct ifa_msghdr ifam = { };
	return (int)ifam.ifam_addrflags;
}
EOF
	if $XCC _ifam_addrflags.c -o _ifam_addrflags 2>&3; then
		echo "yes"
		echo "#define	HAVE_IFAM_ADDRFLAGS" >>$CONFIG_H
	else
		echo "no"
	fi
	rm -f _ifam_addrflags.c _ifam_addrflags
fi

abort=false
# We require the libc to support non standard functions, like getifaddrs
printf "Testing for getifaddrs ... "
cat <<EOF >_getifaddrs.c
#include <sys/types.h>
#include <ifaddrs.h>
int main(void) {
	struct ifaddrs *ifap;
	return getifaddrs(&ifap);
}
EOF
LIBSOCKET=
if $XCC _getifaddrs.c -o _getifaddrs 2>&3; then
	echo "yes"
elif $XCC _getifaddrs.c -o _getifaddrs -lsocket 2>&3; then
	LIBSOCKET=-lsocket
	echo "yes (-lsocket)"
	echo "LDADD+=		-lsocket" >>$CONFIG_MK
else
	echo "no"
	echo "libc support for getifaddrs is required - aborting" >&2
	abort=true
fi
rm -f _getifaddrs.c _getifaddrs
$abort && exit 1

printf "Testing for ifaddrs.ifa_addrflags ... "
cat <<EOF >_getifaddrs_addrflags.c
#include <sys/types.h>
#include <ifaddrs.h>
int main(void) {
	struct ifaddrs *ifap;
	getifaddrs(&ifap);
	return (int)ifap->ifa_addrflags;
}
EOF
if $XCC _getifaddrs_addrflags.c -o _getifaddrs_addrflags $LIBSOCKET 2>&3; then
	echo "yes"
	echo "#define	HAVE_IFADDRS_ADDRFLAGS" >>$CONFIG_H
else
	echo "no"
fi
rm -f _getifaddrs_addrflags.c _getifaddrs_addrflags

printf "Testing for clock_gettime ... "
cat <<EOF >_clock_gettime.c
#include <time.h>
int main(void) {
	struct timespec ts;
	return clock_gettime(CLOCK_MONOTONIC, &ts);
}
EOF
if $XCC _clock_gettime.c -o _clock_gettime 2>&3; then
	echo "yes"
elif $XCC _clock_gettime.c -lrt -o _clock_gettime 2>&3; then
	echo "yes (-lrt)"
	echo "LDADD+=		-lrt" >>$CONFIG_MK
else
	echo "no"
	echo "libc support for clock_getttime is required - aborting" >&2
	abort=true
fi
rm -f _clock_gettime.c _clock_gettime
$abort && exit 1

if [ -z "$CLOSEFROM" ]; then
	printf "Testing for closefrom ... "
	cat <<EOF >_closefrom.c
#include <stdlib.h>
#include <unistd.h>
int main(void) {
	closefrom(3);
	return 0;
}
EOF
	if $XCC _closefrom.c -o _closefrom 2>&3; then
		CLOSEFROM=yes
	else
		CLOSEFROM=no
	fi
	echo "$CLOSEFROM"
fi
rm -f _closefrom.c _closefrom
if [ "$CLOSEFROM" = no ]; then
	echo "COMPAT_SRCS+=	compat/closefrom.c" >>$CONFIG_MK
	echo "#include			\"compat/closefrom.h\"" >>$CONFIG_H
fi

printf "Testing ioctl request type ... "
cat <<EOF >_ioctl.c
#include <sys/ioctl.h>
int main(void) {
	unsigned long req = 0;
	return ioctl(3, req, &req);
}
EOF
if $XCC _ioctl.c -o _ioctl 2>&3; then
	IOCTL_REQ="unsigned long"
else
	IOCTL_REQ="int"
fi
echo "$IOCTL_REQ"
# Our default is unsigned long
# We can still define it, but it makes the code path slightly bigger
if [ "$IOCTL_REQ" != "unsigned long" ]; then
	echo "#define	IOCTL_REQUEST_TYPE	$IOCTL_REQ" >>$CONFIG_H
fi
rm -f _ioctl.c _ioctl

printf "Testing for inet_ntoa ... "
cat <<EOF >_inet_ntoa.c
#include <netinet/in.h>
#include <arpa/inet.h>
int main(void) {
	struct in_addr in = { .s_addr = 0 };
	inet_ntoa(in);
	return 0;
}
EOF
if $XCC _inet_ntoa.c -o _inet_ntoa 2>&3; then
	echo "yes"
elif $XCC _inet_ntoa.c -lnsl -o _inet_ntoa 2>&3; then
	echo "yes (-lnsl)"
	echo "LDADD+=		-lnsl" >>$CONFIG_MK
elif $XCC _inet_ntoa.c -lsocket -o _inet_ntoa 2>&3; then
	echo "yes (-lsocket)"
	echo "LDADD+=		-lsocket" >>$CONFIG_MK
else
	echo "no"
	echo "libc support for inet_ntoa is required - aborting" >&2
	abort=true
fi
rm -f _inet_ntoa.c _inet_ntoa
$abort && exit 1

if [ -z "$ARC4RANDOM" ]; then
	printf "Testing for arc4random ... "
	cat <<EOF >_arc4random.c
#include <stdlib.h>
int main(void) {
	return (int)arc4random();
}
EOF
	if $XCC _arc4random.c -o _arc4random 2>&3; then
		ARC4RANDOM=yes
	else
		ARC4RANDOM=no
	fi
	echo "$ARC4RANDOM"
	rm -f _arc4random.c _arc4random
fi
if [ "$ARC4RANDOM" = no ]; then
	echo "COMPAT_SRCS+=	compat/arc4random.c" >>$CONFIG_MK
	echo "#include			\"compat/arc4random.h\"" >>$CONFIG_H
fi

if [ -z "$ARC4RANDOM_UNIFORM" ]; then
	printf "Testing for arc4random_uniform ... "
	cat <<EOF >_arc4random_uniform.c
#include <stdlib.h>
int main(void) {
	return (int)arc4random_uniform(100);
}
EOF
	if $XCC _arc4random_uniform.c -o _arc4random_uniform 2>&3; then
		ARC4RANDOM_UNIFORM=yes
	else
		ARC4RANDOM_UNIFORM=no
	fi
	echo "$ARC4RANDOM_UNIFORM"
	rm -f _arc4random_uniform.c _arc4random_uniform
fi
if [ "$ARC4RANDOM_UNIFORM" = no ]; then
	echo "COMPAT_SRCS+=	compat/arc4random_uniform.c" >>$CONFIG_MK
	echo "#include			\"compat/arc4random_uniform.h\"" >>$CONFIG_H
fi

# Our arc4random compat needs memset_explicit, explicit_bzero or memset_s
if [ -z "$MEMSET_EXPLICIT" ]; then
	printf "Testing for memset_explicit ... "
	cat <<EOF >_memset_explicit.c
#include <string.h>
int main(void) {
	int a;
	(void)memset_explicit(&a, 0, sizeof(a));
	return 0;
}
EOF
	if $XCC _memset_explicit.c -o _memset_explicit 2>&3; then
		MEMSET_EXPLICIT=yes
	else
		MEMSET_EXPLICIT=no
	fi
	echo "$MEMSET_EXPLICIT"
	rm -f _memset_explicit.c _memset_explicit
fi
if [ "$MEMSET_EXPLICIT" = yes ]; then
	echo "#define	HAVE_MEMSET_EXPLICIT" >>$CONFIG_H
fi

if [ -z "$EXPLICIT_BZERO" ]; then
	printf "Testing for explicit_bzero ... "
	cat <<EOF >_explicit_bzero.c
#define _BSD_SOURCE // musl, will be added for Linux in config.h
#include <string.h>
int main(void) {
	int a;
	explicit_bzero(&a, sizeof(a));
	return 0;
}
EOF
	if $XCC _explicit_bzero.c -o _explicit_bzero 2>&3; then
		EXPLICIT_BZERO=yes
	else
		EXPLICIT_BZERO=no
	fi
	echo "$EXPLICIT_BZERO"
	rm -f _explicit_bzero.c _explicit_bzero
fi
if [ "$EXPLICIT_BZERO" = yes ]; then
	echo "#define	HAVE_EXPLICIT_BZERO" >>$CONFIG_H
fi

if [ -z "$MEMSET_S" ]; then
	printf "Testing for memset_s ... "
	cat <<EOF >_memset_s.c
#define	__STDC_WANT_LIB_EXT1__ 1
#include <string.h>
int main(void) {
	int a;
	memset_s(&a, sizeof(a), 0, sizeof(a));
	return 0;
}
EOF
	if $XCC _memset_s.c -o _memset_s 2>&3; then
		MEMSET_S=yes
	else
		MEMSET_S=no
	fi
	echo "$MEMSET_S"
	rm -f _memset_s.c _memset_s
fi
if [ "$MEMSET_S" = yes ]; then
	echo "#define	__STDC_WANT_LIB_EXT1__	1" >>$CONFIG_H
	echo "#define	HAVE_MEMSET_S" >>$CONFIG_H
fi

if [ -z "$OPEN_MEMSTREAM" ]; then
	printf "Testing for open_memstream ... "
	cat <<EOF >_open_memstream.c
#include <stdio.h>
int main(void) {
	return open_memstream(NULL, NULL) != NULL ? 0 : 1;
}
EOF
	if $XCC _open_memstream.c -o _open_memstream 2>&3; then
		OPEN_MEMSTREAM=yes
	else
		OPEN_MEMSTREAM=no
	fi
	echo "$OPEN_MEMSTREAM"
	rm -f _open_memstream.c _open_memstream
fi
if [ "$OPEN_MEMSTREAM" = yes ]; then
	echo "#define	HAVE_OPEN_MEMSTREAM" >>$CONFIG_H
elif [ "$PRIVSEP" = yes ]; then
	echo "WARNING: Ensure that /tmp exists in the privsep users chroot"
fi

if [ -z "$PIDFILE_LOCK" ]; then
	printf "Testing for pidfile_lock ... "
	cat <<EOF >_pidfile.c
#include <stdlib.h>
#include <util.h>
int main(void) {
	return (int)pidfile_lock(NULL);
}
EOF
	# We only want to link to libutil if it exists in /lib
	if $ALLOW_USR_LIBS; then
		set -- /
	else
		set -- $(ls /lib/libutil.so.* 2>/dev/null)
	fi
	if $XCC _pidfile.c -o _pidfile 2>&3; then
		PIDFILE_LOCK=yes
	elif [ -e "$1" ] &&  $XCC _pidfile.c -o _pidfile -lutil 2>&3; then
		PIDFILE_LOCK="yes (-lutil)"
		LIBUTIL="-lutil"
	else
		PIDFILE_LOCK=no
	fi
	echo "$PIDFILE_LOCK"
	rm -f _pidfile.c _pidfile
fi
if [ "$PIDFILE_LOCK" = no ]; then
	echo "COMPAT_SRCS+=	compat/pidfile.c" >>$CONFIG_MK
	echo "#include			\"compat/pidfile.h\"" >>$CONFIG_H
else
	echo "#define	HAVE_UTIL_H" >>$CONFIG_H
	if [ -n "$LIBUTIL" ]; then
		echo "LDADD+=		$LIBUTIL" >>$CONFIG_MK
	fi
fi

if [ -z "$SETPROCTITLE" ]; then
	printf "Testing for setproctitle ... "
	cat << EOF >_setproctitle.c
#include <stdlib.h>
#include <unistd.h>
int main(void) {
	setproctitle("foo");
	return 0;
}
EOF
	if $XCC _setproctitle.c -o _setproctitle 2>&3; then
		SETPROCTITLE=yes
	else
		SETPROCTITLE=no
	fi
	echo "$SETPROCTITLE"
	rm -f _setproctitle.c _setproctitle
fi
if [ "$SETPROCTITLE" = no ]; then
	case "$OS" in
	solaris*|sunos*)
		echo "$OS has no support for setting process title"
		echo "#define	setproctitle(...)" >>$CONFIG_H
		;;
	*)
		echo "COMPAT_SRCS+=	compat/setproctitle.c" >>$CONFIG_MK
		echo "#include			\"compat/setproctitle.h\"" \
			>>$CONFIG_H
		;;
	esac
fi

if [ -z "$STRLCPY" ]; then
	printf "Testing for strlcpy ... "
	cat <<EOF >_strlcpy.c
#include <string.h>
int main(void) {
	const char s1[] = "foo";
	char s2[10];
	return (int)strlcpy(s2, s1, sizeof(s2));
}
EOF
	if $XCC _strlcpy.c -o _strlcpy 2>&3; then
		STRLCPY=yes
	else
		STRLCPY=no
	fi
	echo "$STRLCPY"
	rm -f _strlcpy.c _strlcpy
fi
if [ "$STRLCPY" = no ]; then
	echo "COMPAT_SRCS+=	compat/strlcpy.c" >>$CONFIG_MK
	echo "#include			\"compat/strlcpy.h\"" >>$CONFIG_H
fi

if [ -z "$STRTOI" ]; then
	printf "Testing for strtoi ... "
	cat <<EOF >_strtoi.c
#include <stdlib.h>
#include <limits.h>
#include <inttypes.h>
int main(void) {
	int e;
	return (int)strtoi("1234", NULL, 0, 0, INT32_MAX, &e);
}
EOF
	if $XCC _strtoi.c -o _strtoi 2>&3; then
		STRTOI=yes
	else
		STRTOI=no
	fi
	echo "$STRTOI"
	rm -f _strtoi.c _strtoi
fi
if [ "$STRTOI" = no ]; then
	echo "COMPAT_SRCS+=	compat/strtoi.c compat/strtou.c" >>$CONFIG_MK
	echo "#include			\"compat/strtoi.h\"" >>$CONFIG_H
fi

if [ -z "$CONSTTIME_MEMEQUAL" ]; then
	printf "Testing for consttime_memequal ... "
	cat <<EOF >_consttime_memequal.c
#include <string.h>
int main(void) {
	return consttime_memequal("deadbeef", "deadbeef", 8);
}
EOF
	if $XCC _consttime_memequal.c -o _consttime_memequal 2>&3; then
		CONSTTIME_MEMEQUAL=yes
	else
		CONSTTIME_MEMEQUAL=no
	fi
	echo "$CONSTTIME_MEMEQUAL"
	rm -f _consttime_memequal.c _consttime_memequal
fi
if [ "$CONSTTIME_MEMEQUAL" = no ] && [ -z "$TIMINGSAFE_BCMP" ]; then
	printf "Testing for timingsafe_bcmp ... "
	cat <<EOF >_timingsafe_bcmp.c
#include <string.h>
int main(void) {
	return timingsafe_bcmp("deadbeef", "deadbeef", 8);
}
EOF
	if $XCC _timingsafe_bcmp.c -o _timingsafe_bcmp 2>&3; then
		TIMINGSAFE_BCMP=yes
	else
		TIMINGSAFE_BCMP=no
	fi
	echo "$TIMINGSAFE_BCMP"
	rm -f _timingsafe_bcmp.c _timingsafe_bcmp
fi

if [ "$CONSTTIME_MEMEQUAL" = no ]; then
	if [ "$TIMINGSAFE_BCMP" = yes ]; then
		echo "#define	consttime_memequal	!timingsafe_bcmp" \
		    >>$CONFIG_H
	else
		echo "#include			\"compat/consttime_memequal.h\"" \
		    >>$CONFIG_H
	fi
fi

if [ -z "$DPRINTF" ]; then
	printf "Testing for dprintf ... "
	cat <<EOF >_dprintf.c
#include <stdio.h>
int main(void) {
	return dprintf(0, "%d", 0);
}
EOF
	if $XCC _dprintf.c -o _dprintf 2>&3; then
		DPRINTF=yes
	else
		DPRINTF=no
	fi
	echo "$DPRINTF"
	rm -f _dprintf.c _dprintf
fi
if [ "$DPRINTF" = no ]; then
	echo "COMPAT_SRCS+=	compat/dprintf.c" >>$CONFIG_MK
	echo "#include			\"compat/dprintf.h\"" >>$CONFIG_H
fi

if [ -z "$RBTREE" ]; then
	printf "Testing for rb_tree_init ... "
	cat <<EOF >_rbtree.c
#include <sys/rbtree.h>
static rb_tree_ops_t ops;
int main(void) {
	rb_tree_t tree;
	rb_tree_init(&tree, &ops);
	return 0;
}
EOF
	if $XCC _rbtree.c -o _rbtree 2>&3; then
		RBTREE=yes
	else
		RBTREE=no
	fi
	echo "$RBTREE"
	rm -f _rbtree.c _rbtree
fi
if [ "$RBTREE" = no ]; then
	echo "VENDOR_SRCS+=	vendor/rbtree.c" >>$CONFIG_MK
	# Tell rbtree.c to #include "rbtree.h" rather than sys/rbtree.h
	echo "RBTREE_CPPFLAGS+=	-DRBLOCAL" >>$CONFIG_MK
	# Remove unused warning from compile
	echo "RBTREE_CPPFLAGS+=	\"-D__unused=__attribute__((__unused__))\"" >>$CONFIG_MK
	# Enjoy the same optimisation as NetBSD's libc
	echo "RBTREE_CPPFLAGS+=	\"-D__predict_false(exp)=__builtin_expect((exp) ? 1 : 0, 0)\"" >>$CONFIG_MK
else
	echo "#define	HAVE_SYS_RBTREE_H" >>$CONFIG_H
fi

if [ -z "$REALLOCARRAY" ]; then
	printf "Testing for reallocarray ... "
	cat <<EOF >_reallocarray.c
#include <stdlib.h>

int main(void) {
	void *foo = reallocarray(NULL, 0, 0);
	return foo == NULL ? 1 : 0;
}
EOF
	if $XCC _reallocarray.c -o _reallocarray 2>&3; then
		REALLOCARRAY=yes
	else
		REALLOCARRAY=no
	fi
	echo "$REALLOCARRAY"
	rm -f _reallocarray.c _reallocarray
fi
if [ "$REALLOCARRAY" = no ]; then
	echo "COMPAT_SRCS+=	compat/reallocarray.c" >>$CONFIG_MK
	echo "#include			\"compat/reallocarray.h\"">>$CONFIG_H
fi
# Set this for eloop
echo "#define	HAVE_REALLOCARRAY" >>$CONFIG_H

if [ -z "$BE64ENC" ]; then
	printf "Testing for be64enc ... "
	cat <<EOF >_be64enc.c
#include <sys/endian.h>
#include <stdlib.h>
int main(void) {
	be64enc(NULL, 0);
	return 0;
}
EOF
	if $XCC _be64enc.c -o _be64enc 2>&3; then
		BE64ENC=yes
	else
		BE64ENC=no
	fi
	echo "$BE64ENC"
	rm -f _be64enc.c _be64enc
fi
if [ "$BE64ENC" = no ]; then
	echo "#include			\"compat/endian.h\"" >>$CONFIG_H
fi

if [ -z "$FLS64" ]; then
	printf "Testing for fls64 ... "
	cat <<EOF >_fls64.c
#include <sys/bitops.h>
int main(void) {
	return (int)fls64(1337);
}
EOF
	if $XCC _fls64.c -o _fls64 2>&3; then
		FLS64=yes
	else
		FLS64=no
	fi
	echo "$FLS64"
	rm -f _fls64.c _fls64
fi
if [ "$FLS64" = yes ]; then
	echo "#define	HAVE_SYS_BITOPS_H" >>$CONFIG_H
fi

if [ -z "$MD5" ]; then
	MD5_LIB=
	printf "Testing for MD5Init ... "
	cat <<EOF >_md5.c
#include <sys/types.h>
#include <md5.h>
#include <stdlib.h>
int main(void) {
	MD5_CTX context;
	MD5Init(&context);
	return 0;
}
EOF
	# We only want to link to libmd if it exists in /lib
	if $ALLOW_USR_LIBS; then
		set -- /
	else
		set -- $(ls /lib/libmd.so.* 2>/dev/null)
	fi
	if $XCC _md5.c -o _md5 2>&3; then
		MD5=yes
	elif [ -e "$1" ] && $XCC _md5.c -lmd -o _md5 2>&3; then
		MD5="yes (-lmd)"
		MD5_LIB=-lmd
	else
		MD5=no
	fi
	echo "$MD5"
	rm -f _md5.c _md5
fi

if [ -z "$SHA2_H" ]; then
	if [ -z "$SHA2" ] || [ "$SHA2" != no ]; then
		printf "Testing for sha2.h ... "
		if [ -e /usr/include/sha2.h ]; then
			SHA2_H=sha2.h
		elif [ -e /usr/include/sha256.h ]; then
			SHA2_H=sha256.h
		fi
		if [ -n "$SHA2_H" ]; then
			echo "$SHA2_H"
		else
			echo "no"
		fi
	fi
fi

if [ -z "$SHA2" ]; then
	SHA2_LIB=
	SHA2_RENAMED=
	printf "Testing for SHA256_Init ... "
	cat <<EOF >_sha256.c
#include <sys/types.h>
EOF
	[ -n "$SHA2_H" ] && echo "#include <$SHA2_H>">>_sha256.c
	cat <<EOF >>_sha256.c
#include <stdlib.h>
int main(void) {
	SHA256_CTX context;
	SHA256_Init(&context);
	return 0;
}
EOF
	# We only want to link to libmd if it exists in /lib
	if $ALLOW_USR_LIBS; then
		set -- /
	else
		set -- $(ls /lib/libmd.so.* 2>/dev/null)
	fi
	if $XCC _sha256.c -o _sha256 2>&3; then
		SHA2=yes
	elif [ -e "$1" ] && $XCC _sha256.c -lmd -o _sha256 2>&3; then
		SHA2="yes (-lmd)"
		SHA2_LIB=-lmd
	else
		SHA2=no
	fi
	echo "$SHA2"
	rm -f _sha256.c _sha256
	if [ "$SHA2" = no ]; then
		# Did OpenBSD really change this? grrrr
		printf "Testing for SHA256Init ... "
		cat <<EOF >_sha256.c
#include <sys/types.h>
EOF
		[ -n "$SHA2_H" ] && echo "#include <$SHA2_H>">>_sha256.c
		cat <<EOF >>_sha256.c
#include <stdlib.h>
int main(void) {
	SHA2_CTX context;
	SHA256Init(&context);
	return 0;
}
EOF
		# We only want to link to libmd if it exists in /lib
		if $ALLOW_USR_LIBS; then
			set -- /
		else
			set -- $(ls /lib/libmd.so.* 2>/dev/null)
		fi
		if $XCC	_sha256.c -o _sha256 2>&3; then
			SHA2=yes
			SHA2_RENAMED=yes
		elif [ -e "$1" ] && $XCC _sha256.c -lmd -o _sha256 2>&3
		then
			SHA2="yes (-lmd)"
			SHA2_LIB=-lmd
			SHA2_RENAMED=yes
		else
			SHA2=no
		fi
		echo "$SHA2"
		rm -f _sha256.c _sha256
	fi
fi

if [ -z "$HMAC" ]; then
	HMAC_LIB=
	printf "Testing for hmac ... "
	cat <<EOF >_hmac.c
#include <stdlib.h>
#include <hmac.h>
int main(void) {
	return (int)hmac(NULL, NULL, 0, NULL, 0, NULL, 0);
}
EOF
	if $XCC _hmac.c $MD5_LIB -o _hmac 2>&3; then
		HMAC=yes
		echo "#define	HAVE_HMAC_H" >>$CONFIG_H
	else
		# Remove this test if NetBSD-8 ships with
		# hmac in it's own header and not stdlib.h
		cat <<EOF >_hmac.c
#include <stdlib.h>
int main(void) {
	return (int)hmac(NULL, NULL, 0, NULL, 0, NULL, 0);
}
EOF
		if $XCC _hmac.c $MD5_LIB -o _hmac 2>&3; then
			HMAC=yes
		else
			HMAC=no
		fi
	fi
	echo "$HMAC"
	rm -f _hmac.c _hmac
fi

if [ "$OPENSSL" = yes ] ||
   { [ -z "$OPENSSL" ] && [ "$ALLOW_USR_LIBS" = true ] &&
     [ "$SHA2" = no ] &&  [ "$HMAC" = no ];
   }; then
	printf "Testing for openssl ... "
	if type "$PKG_CONFIG" >/dev/null 2>&1; then
		LIBCRYPTO_CFLAGS=$("$PKG_CONFIG" --cflags libcrypto 2>&3)
		LIBCRYPTO_LIBS=$("$PKG_CONFIG" --libs libcrypto 2>&3)
	fi

	cat <<EOF >_openssl.c
#include <stdio.h>
#include <openssl/crypto.h>
int main(void) {
	return OPENSSL_init_crypto(0, NULL) == 1;
}
EOF
	if $XCC $LIBCRYPTO_CFLAGS _openssl.c -o _openssl $LIBCRYPTO_LIBS 2>&3;
	then
		OPENSSL=yes
		MD5=yes
		MD5_LIB=
		if [ -n "$LIBCRYPTO_CFLAGS" ]; then
			echo "CFLAGS+=		$LIBCRYPTO_CFLAGS" >>$CONFIG_MK
		fi
		echo "LDADD+=		$LIBCRYPTO_LIBS" >>$CONFIG_MK
		echo "#define	HAVE_OPENSSL" >>$CONFIG_H
	else
		OPENSSL=no
	fi
	echo "$OPENSSL"
	rm -f _openssl.c _openssl
fi

if [ "$OPENSSL" = yes ]; then
	printf "Testing for openssl/sha.h ... "
	cat <<EOF >_openssl_sha.c
#include <stdio.h>
#include <openssl/sha.h>

int main(void) {
	SHA256_CTX ctx;
	SHA256_Init(&ctx);
	return 0;
}
EOF
	if $XCC $LIBCRYPTO_CFLAGS _openssl_sha.c -o _openssl_sha \
	   $LIBCRYPTO_LIBS 2>&3; then
		SHA2_H=openssl/sha.h
		SHA2="yes (-lcrypto)"
	else
		SHA2=no
	fi
	SHA2_LIB=
	SHA2_RENAMED=
	echo "$SHA2"
	rm -f _openssl_sha.c _openssl_sha
fi

if [ "$LIBPCAP" = yes ]; then
	printf "Testing for libpcap ... "
	if $PKG_CONFIG --exists libpcap 2>/dev/null; then
		LIBPCAP_CFLAGS=$($PKG_CONFIG --cflags libpcap 2>/dev/null)
		LIBPCAP_LIBS=$($PKG_CONFIG --libs libpcap 2>/dev/null)
		echo "yes"
	else
		cat <<EOF >_libpcap.c
#include <pcap.h>

int main(void) {
	return pcap_activate(NULL);
}
EOF
		if $XCC _libpcap.c -o libpcap -lpcap 2>&3; then
			echo "yes"
			LIBPCAP_CFLAGS=
			LIBPCAP_LIBS="-lpcap"
			abort=false
		else
			echo "no"
			abort=true
		fi
		rm -f _libpcap.c libpcap
		$abort && exit 1
	fi
	echo "CFLAGS+=	$LIBPCAP_CFLAGS" >>$CONFIG_MK
	echo "LDADD+=		$LIBPCAP_LIBS" >>$CONFIG_MK
	echo "#define	USE_LIBPCAP" >>$CONFIG_H

	printf "Testing for pcap_set_immediate_mode() ... "
	cat <<EOF >_libpcap_imm.c
#include <pcap.h>

int main(void) {
	return pcap_set_immediate_mode(NULL, 1);
}
EOF
	if $XCC $LIBPCAP_CFLAGS _libpcap_imm.c -o libpcap_imm $LIBPCAP_LIBS 2>&3; then
		echo "yes"
		echo "#define HAVE_PCAP_SET_IMMEDIATE_MODE" >>$CONFIG_H
	else
		echo "no"
	fi
	rm -f _libpcap_imm.c libpcap_imm

	printf "Testing for pcap_setwritefilter() ... "
	cat <<EOF >_libpcap_write.c
#include <pcap.h>

int main(void) {
	return pcap_setwritefilter(NULL, NULL);
}
EOF
	if $XCC $LIBPCAP_CFLAGS _libpcap_write.c -o libpcap_write $LIBPCAP_LIBS 2>&3; then
		echo "yes"
		echo "#define HAVE_PCAP_SETWRITEFILTER" >>$CONFIG_H
	else
		echo "no"
	fi
	rm -f _libpcap_write.c libpcap_write

	printf "Testing for pcap_lockfilter() ... "
	cat <<EOF >_libpcap_lock.c
#include <pcap.h>

int main(void) {
	return pcap_lockfilter(NULL);
}
EOF
	if $XCC $LIBPCAP_CFLAGS _libpcap_lock.c -o libpcap_lock $LIBPCAP_LIBS 2>&3; then
		echo "yes"
		echo "#define HAVE_PCAP_LOCKFILTER" >>$CONFIG_H
	else
		echo "no"
	fi
	rm -f _libpcap_lock.c libpcap_lock
fi

# Workaround for DragonFlyBSD import
if [ "$OS" = dragonfly ]; then
	echo "#ifdef	USE_PRIVATECRYPTO" >>$CONFIG_H
	echo "#define	HAVE_MD5_H" >>$CONFIG_H
	echo "#define	SHA2_H			<openssl/sha.h>" >>$CONFIG_H
	echo "#else" >>$CONFIG_H
fi

if [ "$MD5" = no ]; then
	echo "#include			\"compat/crypt/md5.h\"" >>$CONFIG_H
	echo "MD5_SRC=	compat/crypt/md5.c" >>$CONFIG_MK
else
	echo "MD5_SRC=" >>$CONFIG_MK
	[ "$OPENSSL" != yes ] && echo "#define	HAVE_MD5_H" >>$CONFIG_H
	[ -n "$MD5_LIB" ] && echo "LDADD+=		$MD5_LIB" >>$CONFIG_MK
fi

if [ "$OPENSSL" = yes ] && [ "$SHA2" = no ]; then
	echo "#include			\"compat/crypt_openssl/sha256.h\"" >>$CONFIG_H
	echo "SHA256_SRC=	compat/crypt_openssl/sha256.c" >>$CONFIG_MK
elif [ "$SHA2" = no ]; then
	echo "#include			\"compat/crypt/sha256.h\"" >>$CONFIG_H
	echo "SHA256_SRC=	compat/crypt/sha256.c" >>$CONFIG_MK
else
	echo "SHA256_SRC=" >>$CONFIG_MK
	echo "#define	SHA2_H			<$SHA2_H>" >>$CONFIG_H
	if [ "$SHA2_RENAMED" = yes ]; then
		echo "#define	SHA256_CTX	SHA2_CTX" >>$CONFIG_H
		echo "#define	SHA256_Init	SHA256Init" >>$CONFIG_H
		echo "#define	SHA256_Update	SHA256Update" >>$CONFIG_H
		echo "#define	SHA256_Final	SHA256Final" >>$CONFIG_H
	fi
	[ -n "$SHA2_LIB" ] && echo "LDADD+=		$SHA2_LIB" >>$CONFIG_MK
fi

# Workarond for DragonFlyBSD import
[ "$OS" = dragonfly ] && echo "#endif" >>$CONFIG_H

if [ "$OPENSSL" = yes ]; then
	echo "#include			\"compat/crypt_openssl/hmac.h\"" >>$CONFIG_H
	echo "HMAC_SRC=	compat/crypt_openssl/hmac.c" >>$CONFIG_MK
elif [ "$HMAC" = no ]; then
	echo "#include			\"compat/crypt/hmac.h\"" >>$CONFIG_H
	echo "HMAC_SRC=	compat/crypt/hmac.c" >>$CONFIG_MK
else
	# echo "#define	HAVE_HMAC_H" >>$CONFIG_H
	echo "HMAC_SRC=" >>$CONFIG_MK
fi

if [ -z "$AUTH" ] || [ "$AUTH" = yes ]; then
	if [ "$HMAC" = no ]; then
		echo "CRYPT_SRCS+=	\${HMAC_SRC}" >>$CONFIG_MK
	fi
fi
if [ -z "$INET6" ] || [ "$INET6" = yes ] || \
    [ -z "$AUTH" ] || [ "$AUTH" = yes ]; then
	if [ "$MD5" = no ]; then
		echo "CRYPT_SRCS+=	\${MD5_SRC}" >>$CONFIG_MK
	fi
	if [ "$SHA2" = no ]; then
		echo "CRYPT_SRCS+=	\${SHA256_SRC}" >>$CONFIG_MK
	fi
fi

if [ "$DEV" != no ] && [ "$UDEV" != no ]; then
	printf "Checking for libudev ... "
	if type "$PKG_CONFIG" >/dev/null 2>&1; then
		LIBUDEV_CFLAGS=$("$PKG_CONFIG" --cflags libudev 2>&3)
		LIBUDEV_LIBS=$("$PKG_CONFIG" --libs libudev 2>&3)
	fi
	if [ -n "$LIBUDEV_LIBS" ] && [ "$UDEV" = yes ]; then
		echo "yes"
	elif [ -n "$LIBUDEV_LIBS" ]; then
		case "$OS" in
		linux*)	echo "yes";;
		*)	echo "yes (disabled)"
			# FreeBSD libudev fails to return a udev device
			# with udev_device_new_from_subsystem_sysname
			# which breaks our test for device initialisation
			LIBUDEV_CFLAGS=
			LIBUDEV_LIBS=
			;;
		esac
	else
		echo "no"
	fi
fi

if [ "$DEV" != no ] && [ "$UDEV" != no ] && [ -n "$LIBUDEV_LIBS" ]; then
	[ -z "$DEV" ] && DEV=yes
	echo "DEV_PLUGINS+=	udev" >>$CONFIG_MK
	if [ -n "$LIBUDEV_CFLAGS" ]; then
		echo "LIBUDEV_CFLAGS=		$LIBUDEV_CFLAGS" >>$CONFIG_MK
	fi
	echo "LIBUDEV_LIBS=	$LIBUDEV_LIBS" >>$CONFIG_MK

	printf "Checking udev_monitor_filter_add_match_subsystem_devtype ... "
	cat <<EOF >_udev.c
#include <libudev.h>
#include <stdlib.h>
int main(void) {
	return udev_monitor_filter_add_match_subsystem_devtype(NULL, NULL, NULL);
}
EOF
	if $XCC $LIBUDEV_CFLAGS _udev.c -o _udev $LIBUDEV_LIBS 2>&3
	then
		echo "yes"
	else
		echo "LIBUDEV_CPPFLAGS+=	-DLIBUDEV_NOFILTER" >>$CONFIG_MK
		echo "no"
	fi
	rm -f _udev.c _udev

	printf "Checking udev_device_get_is_initialized ... "
	cat <<EOF >_udev.c
#include <libudev.h>
#include <stdlib.h>
int main(void) {
	return udev_device_get_is_initialized(NULL);
}
EOF
	if $XCC $LIBUDEV_CFLAGS _udev.c -o _udev $LIBUDEV_LIBS 2>&3
	then
		echo "yes"
	else
		echo "LIBUDEV_CPPFLAGS+=	-DLIBUDEV_NOINIT" >>$CONFIG_MK
		echo "no"
	fi
	rm -f _udev.c _udev
elif [ "$DEV" != no ] && [ "$UDEV" != no ] && [ -n "$UDEV" ]; then
	echo "udev has been explicitly requested ... aborting" >&2
	exit 1
fi

if [ "$DEV" = yes ]; then
	echo "DHCPCD_SRCS+=	dev.c" >>$CONFIG_MK
	echo "CPPFLAGS+=	-DPLUGIN_DEV" >>$CONFIG_MK
	echo "MKDIRS+=	dev" >>$CONFIG_MK

	# So the plugins have access to logerr
	echo "LDFLAGS+=	-Wl,-export-dynamic" >>$CONFIG_MK

	printf "Testing for dlopen ... "
	cat <<EOF >_dlopen.c
#include <dlfcn.h>
#include <stdlib.h>
int main(void) {
	void *h = dlopen("/foo/bar", 0);
	void (*s)(char *) = dlsym(h, "deadbeef");
	s(dlerror());
	dlclose(h);
	return 0;
}
EOF
	if $XCC _dlopen.c -o _dlopen 2>&3; then
		echo "yes"
	elif $XCC _dlopen.c -ldl -o _dlopen 2>&3; then
		echo "yes (-ldl)"
		echo "LDADD+=		-ldl" >>$CONFIG_MK
	else
		echo "no"
		echo "libc for dlopen is required - aborting"
	fi
	rm -f _dlopen.c _dlopen
	$abort && exit 1
fi

# Transform for a make file
SERVICEEXISTS=$(echo "$SERVICEEXISTS" | $SED \
	-e 's:\\:\\\\:g' \
	-e 's:\&:\\\&:g' \
	-e 's:\$:\\\\\$\$:g' \
)
echo "SERVICEEXISTS=	$SERVICEEXISTS" >>config.mk
SERVICECMD=$(echo "$SERVICECMD" | $SED \
	-e 's:\\:\\\\:g' \
	-e 's:\&:\\\&:g' \
	-e 's:\$:\\\\\$\$:g' \
)
echo "SERVICECMD=	$SERVICECMD" >>config.mk
SERVICESTATUS=$(echo "$SERVICESTATUS" | $SED \
	-e 's:\\:\\\\:g' \
	-e 's:\&:\\\&:g' \
	-e 's:\$:\\\\\$\$:g' \
)
echo "SERVICESTATUS=	$SERVICESTATUS" >>config.mk
if [ -z "$STATUSARG" ]; then
	case "$OS" in
	dragonfly*|freebsd*)	STATUSARG="onestatus";;
	esac
fi
echo "STATUSARG=	$STATUSARG" >>config.mk

HOOKS=
if ! $HOOKSET; then
	printf "Checking for ntpd ... "
	NTPD=$(_which ntpd)
	if [ -n "$NTPD" ]; then
		echo "$NTPD (50-ntp.conf)"
	else
		echo "not found"
	fi
	printf "Checking for chronyd ... "
	CHRONYD=$(_which chronyd)
	if [ -n "$CHRONYD" ]; then
		echo "$CHRONYD (50-ntp.conf)"
	else
		echo "not found"
	fi
	if [ -n "$NTPD" ] || [ -n "$CHRONYD" ]; then
		HOOKS="$HOOKS${HOOKS:+ }50-ntp.conf"
	fi
	# Warn if both are detected
	if [ -n "$NTPD" ] && [ -n "$CHRONYD" ]; then
		echo "NTP will default to $NTPD"
	fi

	printf "Checking for timesyncd ... "
	TIMESYNCD=
	for x in /usr/lib/systemd/systemd-timesyncd; do
		if [ -x "$x" ]; then
			TIMESYNCD=$x
			break
		fi
	done
	if [ -n "$TIMESYNCD" ]; then
		echo "$TIMESYNCD"
		HOOKS="$HOOKS${HOOKS:+ }50-timesyncd.conf"
	else
		echo "not found"
	fi

	printf "Checking for ypbind ... "
	YPBIND=$(_which ypbind)
	if [ -n "$YPBIND" ]; then
		YPHOOK="50-ypbind"
		if strings "$YPBIND" | $GREP -q yp\\.conf; then
			YPHOOK="50-yp.conf"
			YPOS="Linux"
		elif strings "$YPBIND" | $GREP -q \\.ypservers; then
			YPOS="NetBSD"
			echo "YPDOMAIN_DIR=	/var/yp" >>$CONFIG_MK
			echo "YPDOMAIN_SUFFIX=.ypservers" >>$CONFIG_MK
		elif strings "$YPBIND" | $GREP -q /etc/yp; then
			YPOS="OpenBSD"
			echo "YPDOMAIN_DIR=	/etc/yp" >>$CONFIG_MK
			echo "YPDOMAIN_SUFFIX=" >>$CONFIG_MK
		else
			YPOS="FreeBSD"
			echo "YPDOMAIN_DIR=" >>$CONFIG_MK
			echo "YPDOMAIN_SUFFIX=" >>$CONFIG_MK
		fi
		echo "$YPBIND ($YPHOOK${YPOS:+ }$YPOS)"
		EGHOOKS="$EGHOOKS${EGHOOKS:+ }$YPHOOK"
	else
		echo "not found"
		YPHOOK="50-ypbind"
		case "$OS" in
		linux*)
			YPHOOK="50-yp.conf"
			YPOS="Linux"
			;;
		freebsd*|dragonfly*)
			YPOS="FreeBSD"
			echo "YPDOMAIN_DIR=" >>$CONFIG_MK
			echo "YPDOMAIN_SUFFIX=" >>$CONFIG_MK
			;;
		netbsd*)
			YPOS="NetBSD"
			echo "YPDOMAIN_DIR=	/var/yp" >>$CONFIG_MK
			echo "YPDOMAIN_SUFFIX=.ypservers" >>$CONFIG_MK
			;;
		openbsd*)
			YPOS="OpenBSD"
			echo "YPDOMAIN_DIR=	/etc/yp" >>$CONFIG_MK
			echo "YPDOMAIN_SUFFIX=" >>$CONFIG_MK
			;;
		*)
			YPHOOK=
			;;
		esac
		if [ -n "$YPHOOK" ]; then
			echo "Assuming ypbind is $YPOS"
			EGHOOKS="$EGHOOKS${EGHOOKS:+ }$YPHOOK"
		fi
	fi
fi
if [ "$NTP" = yes ]; then
	# --enable-ntp
	echo "UNCOMMENT_NTP=	yes" >>$CONFIG_MK
fi

echo >>$CONFIG_H
echo "#endif /*CONFIG_H*/">>$CONFIG_H

find_hook()
{
	for h in [0-9][0-9]"-$x" [0-9][0-9]"-$x.in" \
	    [0-9][0-9]"-$x.sh" [0-9][0-9]"-$x.sh.in" \
	    [0-9][0-9]"-$x.conf" [0-9][0-9]"-$x.conf.in"
	do
		[ -e "$h" ] && break
	done
	[ -e "$h" ] || return 1
	echo "${h%%.in}"
	return 0
}

if cd hooks; then
	for x in $HOOKSCRIPTS; do
		printf "Finding hook $x ... "
		h=$(find_hook "$x")
		if [ -z "$h" ]; then
			echo "no"
		else
			echo "$h"
			case " $HOOKS " in
			*" $h "*)	;;
			*)		HOOKS="$HOOKS${HOOKS:+ }$h";;
			esac
		fi
	done
	for x in $EGHOOKSCRIPTS; do
		printf "Finding example hook $x ... "
		h=$(find_hook "$x")
		if [ -z "$h" ]; then
			echo "no"
		else
			echo "$h"
			case " $EGHOOKS " in
			*" $h "*)	;;
			*)		EGHOOKS="$EGHOOKS${EGHOOKS:+ }$h";;
			esac
		fi
	done
	cd ..
fi
echo "HOOKSCRIPTS=	$HOOKS" >>$CONFIG_MK
echo "EGHOOKSCRIPTS=	$EGHOOKS" >>$CONFIG_MK

echo
echo "   SYSCONFDIR =		$SYSCONFDIR"
echo "   SBINDIR =		$SBINDIR"
echo "   LIBDIR =		$LIBDIR"
echo "   LIBEXECDIR =		$LIBEXECDIR"
echo "   DBDIR =		$DBDIR"
echo "   RUNDIR =		$RUNDIR"
echo "   MANDIR =		$MANDIR"
echo "   DATADIR =		$DATADIR"
echo "   HOOKSCRIPTS =	$HOOKS"
echo "   EGHOOKSCRIPTS =	$EGHOOKS"
echo "   STATUSARG =		$STATUSARG"
if [ "$PRIVSEP" = yes ]; then
	echo "   PRIVSEPUSER =	$PRIVSEP_USER"
fi
echo

rm -f dhcpcd tests/test


================================================
FILE: hooks/01-test
================================================
# SPDX-License-Identifier: BSD-2-Clause
# Copyright (c) 2017-2020 Roy Marples <roy@marples.name>

# Echo the interface flags, reason and message options

if [ "$reason" = "TEST" ]; then
	# General variables at the top
	set | while read line; do
		case "$line" in
		interface=*|pid=*|reason=*|protocol=*|profile=*|skip_hooks=*)
			printf '%s\n' "$line";;
		esac
	done
	# Interface flags
	set | while read line; do
		case "$line" in
		ifcarrier=*|ifflags=*|ifmetric=*|ifmtu=*|ifwireless=*|ifssid=*)
			printf '%s\n' "$line";;
		esac
	done
	# Old lease
	set | while read line; do
		case "$line" in
		old_*) printf '%s\n' "$line";;
		esac
	done
	# New lease
	set | while read line; do
		case "$line" in
		new_*) printf '%s\n' "$line";;
		esac
	done
	# Router Advertisements
	set | while read line; do
		case "$line" in
		nd[0-9]*_*) printf '%s\n' "$line";;
		esac
	done
	exit 0
fi


================================================
FILE: hooks/10-wpa_supplicant
================================================
# SPDX-License-Identifier: BSD-2-Clause
# Copyright (c) 2017-2024 Roy Marples <roy@marples.name>

# Start, reconfigure and stop wpa_supplicant per wireless interface.
#
# This is only needed when using wpa_supplicant-2.5 or older, OR
# when wpa_supplicant has not been built with CONFIG_MATCH_IFACE, OR
# wpa_supplicant was launched without the -M flag to activate
# interface matching.

if [ -z "$wpa_supplicant_conf" ]; then
	for x in \
		/etc/wpa_supplicant/wpa_supplicant-"$interface".conf \
		/etc/wpa_supplicant/wpa_supplicant.conf \
		/etc/wpa_supplicant-"$interface".conf \
		/etc/wpa_supplicant.conf \
	; do
		if [ -s "$x" ]; then
			wpa_supplicant_conf="$x"
			break
		fi
	done
fi
: ${wpa_supplicant_conf:=/etc/wpa_supplicant.conf}

wpa_supplicant_ctrldir()
{
	dir=$(key_get_value "[[:space:]]*ctrl_interface=" \
		"$wpa_supplicant_conf")
	dir=$(trim "$dir")
	case "$dir" in
	DIR=*)
		dir=${dir##DIR=}
		dir=${dir%%[[:space:]]GROUP=*}
		dir=$(trim "$dir")
		;;
	esac
	printf %s "$dir"
}

wpa_supplicant_start()
{
	# If the carrier is up, don't bother checking anything
	[ "$ifcarrier" = "up" ] && return 0

	# Pre flight checks
	if [ ! -s "$wpa_supplicant_conf" ]; then
		syslog warn \
			"$wpa_supplicant_conf does not exist"
		syslog warn "not interacting with wpa_supplicant(8)"
		return 1
	fi
	dir=$(wpa_supplicant_ctrldir)
	if [ -z "$dir" ]; then
		syslog warn \
			"ctrl_interface not defined in $wpa_supplicant_conf"
		syslog warn "not interacting with wpa_supplicant(8)"
		return 1
	fi

	wpa_cli -p "$dir" -i "$interface" status >/dev/null 2>&1 && return 0
	syslog info "starting wpa_supplicant"
	driver=${wpa_supplicant_driver:+-D}$wpa_supplicant_driver
	err=$(wpa_supplicant -B -c"$wpa_supplicant_conf" -i"$interface" \
	    "$driver" 2>&1)
	errn=$?
	if [ $errn != 0 ]; then
		syslog err "failed to start wpa_supplicant"
		syslog err "$err"
	fi
	return $errn
}

wpa_supplicant_reconfigure()
{
	dir=$(wpa_supplicant_ctrldir)
	[ -z "$dir" ] && return 1
	if ! wpa_cli -p "$dir" -i "$interface" status >/dev/null 2>&1; then
		wpa_supplicant_start
		return $?
	fi
	syslog info "reconfiguring wpa_supplicant"
	err=$(wpa_cli -p "$dir" -i "$interface" reconfigure 2>&1)
	errn=$?
	if [ $errn != 0 ]; then
		syslog err "failed to reconfigure wpa_supplicant"
		syslog err "$err"
	fi
	return $errn
}

wpa_supplicant_stop()
{
	dir=$(wpa_supplicant_ctrldir)
	[ -z "$dir" ] && return 1
	wpa_cli -p "$dir" -i "$interface" status >/dev/null 2>&1 || return 0
	syslog info "stopping wpa_supplicant"
	err=$(wpa_cli -i"$interface" terminate 2>&1)
	errn=$?
	if [ $errn != 0 ]; then
		syslog err "failed to stop wpa_supplicant"
		syslog err "$err"
	fi
	return $errn
}

if [ "$ifwireless" = "1" ] && \
    command -v wpa_supplicant >/dev/null 2>&1 && \
    command -v wpa_cli >/dev/null 2>&1
then
	case "$reason" in
	PREINIT)		wpa_supplicant_start;;
	RECONFIGURE)		wpa_supplicant_reconfigure;;
	DEPARTED|STOPPED)	wpa_supplicant_stop;;
	esac
fi


================================================
FILE: hooks/15-timezone
================================================
# SPDX-License-Identifier: BSD-2-Clause
# Copyright (c) 2017-2020 Roy Marples <roy@marples.name>

# Configure timezone

: ${localtime:=/etc/localtime}

set_zoneinfo()
{
	[ -z "$new_tzdb_timezone" ] && return 0

	zoneinfo_dir=
	for d in \
		/usr/share/zoneinfo	\
		/usr/lib/zoneinfo	\
		/var/share/zoneinfo	\
		/var/zoneinfo		\
	; do
		if [ -d "$d" ]; then
			zoneinfo_dir="$d"
			break
		fi
	done

	if [ -z "$zoneinfo_dir" ]; then
		syslog warning "timezone directory not found"
		return 1
	fi

	zone_file="$zoneinfo_dir/$new_tzdb_timezone"
	if [ ! -e "$zone_file" ]; then
		syslog warning "no timezone definition for $new_tzdb_timezone"
		return 1
	fi

	if copy_file "$zone_file" "$localtime"; then
		syslog info "timezone changed to $new_tzdb_timezone"
	fi
}

# For ease of use, map DHCP6 names onto our DHCP4 names
case "$reason" in
BOUND6|RENEW6|REBIND6|REBOOT6|INFORM6)
	new_tzdb_timezone="$new_dhcp6_tzdb_timezone"
	;;
esac

if $if_configured && $if_up; then
 	set_zoneinfo
fi


================================================
FILE: hooks/20-resolv.conf
================================================
# SPDX-License-Identifier: BSD-2-Clause
# Copyright (c) 2017-2025 Roy Marples <roy@marples.name>

# Generate /etc/resolv.conf
# Support resolvconf(8) if available
# We can merge other dhcpcd resolv.conf files into one like resolvconf,
# but resolvconf is preferred as other applications like VPN clients
# can readily hook into it.
# Also, resolvconf can configure local nameservers such as bind
# or dnsmasq. This is important as the libc resolver isn't that powerful.

resolv_conf_dir="$state_dir/resolv.conf"
nocarrier_roaming_dir="$state_dir/roaming"
NL="
"
: ${resolvconf:=resolvconf}
if command -v "$resolvconf" >/dev/null 2>&1; then
	have_resolvconf=true
else
	have_resolvconf=false
fi

build_resolv_conf()
{
	cf="$state_dir/resolv.conf.$ifname"

	# Build a list of interfaces
	interfaces=$(list_interfaces "$resolv_conf_dir")

	# Build the resolv.conf
	header=
	if [ -n "$interfaces" ]; then
		# Build the header
		for x in ${interfaces}; do
			header="$header${header:+, }$x"
		done

		# Build the search list
		domain=$(cd "$resolv_conf_dir"; \
			key_get_value "domain " ${interfaces})
		search=$(cd "$resolv_conf_dir"; \
			key_get_value "search " ${interfaces})
		set -- ${domain}
		domain="$1"
		[ -n "$2" ] && search="$search $*"
		[ -n "$search" ] && search="$(uniqify $search)"
		[ "$domain" = "$search" ] && search=
		[ -n "$domain" ] && domain="domain $domain$NL"
		[ -n "$search" ] && search="search $search$NL"

		# Build the nameserver list
		srvs=$(cd "$resolv_conf_dir"; \
			key_get_value "nameserver " ${interfaces})
		for x in $(uniqify $srvs); do
			servers="${servers}nameserver $x$NL"
		done
	fi
	header="$signature_base${header:+ $from }$header"

	# Assemble resolv.conf using our head and tail files
	[ -f "$cf" ] && rm -f "$cf"
	[ -d "$resolv_conf_dir" ] || mkdir -p "$resolv_conf_dir"
	printf '%s\n' "$header" > "$cf"
	if [ -f /etc/resolv.conf.head ]; then
		cat /etc/resolv.conf.head >> "$cf"
	else
		printf '%s\n' "# /etc/resolv.conf.head can replace this line" >> "$cf"
	fi
	printf %s "$domain$search$servers" >> "$cf"
	if [ -f /etc/resolv.conf.tail ]; then
		cat /etc/resolv.conf.tail >> "$cf"
	else
		printf '%s\n' "# /etc/resolv.conf.tail can replace this line" >> "$cf"
	fi
	if change_file /etc/resolv.conf "$cf"; then
		chmod 644 /etc/resolv.conf
	fi
	rm -f "$cf"
}

# Extract any ND DNS options from the RA
# Obey the lifetimes
eval_nd_dns()
{

	eval rdnsstime=\$nd${i}_rdnss${j}_lifetime
	if [ -n "$rdnsstime" ]; then
		ltime=$(($rdnsstime - $offset))
		if [ "$ltime" -gt 0 ]; then
			eval rdnss=\$nd${i}_rdnss${j}_servers
			if [ -n "$rdnss" ]; then
				new_rdnss="$new_rdnss${new_rdnss:+ }$rdnss"
			fi
		fi
	fi

	eval dnssltime=\$nd${i}_dnssl${j}_lifetime
	if [ -n "$dnssltime" ]; then
		ltime=$(($dnssltime - $offset))
		if [ "$ltime" -gt 0 ]; then
			eval dnssl=\$nd${i}_dnssl${j}_search
			if [ -n "$dnssl" ]; then
				new_dnssl="$new_dnssl${new_dnssl:+ }$dnssl"
			fi
		fi
	fi

	# Break when we don't have either
	[ -z "$rdnsstime" ] && [ -z "$dnssltime" ] && return 1

	j=$(($j + 1))
	return 0
}

add_resolv_conf()
{
	conf="$signature$NL"
	warn=true

	# Loop to extract the ND DNS options using our indexed shell values
	i=1
	j=1
	while true; do
		eval acquired=\$nd${i}_acquired
		[ -z "$acquired" ] && break
		eval now=\$nd${i}_now
		[ -z "$now" ] && break
		offset=$(($now - $acquired))
		while true; do
			eval_nd_dns || break
		done
		i=$(($i + 1))
		j=1
	done
	[ -n "$new_rdnss" ] && \
	    new_domain_name_servers="$new_domain_name_servers${new_domain_name_servers:+ }$new_rdnss"
	[ -n "$new_dnssl" ] && \
	    new_domain_search="$new_domain_search${new_domain_search:+ }$new_dnssl"

	# Derive a new domain from our various hostname options
	if [ -z "$new_domain_name" ]; then
		if [ "$new_dhcp6_fqdn" != "${new_dhcp6_fqdn#*.}" ]; then
			new_domain_name="${new_dhcp6_fqdn#*.}"
		elif [ "$new_fqdn" != "${new_fqdn#*.}" ]; then
			new_domain_name="${new_fqdn#*.}"
		elif [ "$new_host_name" != "${new_host_name#*.}" ]; then
			new_domain_name="${new_host_name#*.}"
		fi
	fi

	# If we don't have any configuration, remove it
	if [ -z "$new_domain_name_servers" ] &&
	   [ -z "$new_domain_name" ] &&
	   [ -z "$new_domain_search" ]; then
		remove_resolv_conf
		return $?
	fi

	if [ -n "$new_domain_name" ]; then
		set -- $new_domain_name
		if valid_domainname "$1"; then
			conf="${conf}domain $1$NL"
		else
			syslog err "Invalid domain name: $1"
		fi
		# If there is no search this, make this one
		if [ -z "$new_domain_search" ]; then
			new_domain_search="$new_domain_name"
			[ "$new_domain_name" = "$1" ] && warn=true
		fi
	fi
	if [ -n "$new_domain_search" ]; then
		new_domain_search=$(uniqify $new_domain_search)
		if valid_domainname_list $new_domain_search; then
			conf="${conf}search $new_domain_search$NL"
		elif ! $warn; then
			syslog err "Invalid domain name in list:" \
			    "$new_domain_search"
		fi
	fi
	new_domain_name_servers=$(uniqify $new_domain_name_servers)
	for x in ${new_domain_name_servers}; do
		conf="${conf}nameserver $x$NL"
	done
	if $have_resolvconf; then
		[ -n "$ifmetric" ] && export IF_METRIC="$ifmetric"
		printf %s "$conf" | "$resolvconf" -a "$ifname"
		return $?
	fi

	if [ -e "$resolv_conf_dir/$ifname" ]; then
		rm -f "$resolv_conf_dir/$ifname"
	fi
	[ -d "$resolv_conf_dir" ] || mkdir -p "$resolv_conf_dir"
	printf %s "$conf" > "$resolv_conf_dir/$ifname"
	build_resolv_conf
}

remove_resolv_conf()
{
	if $have_resolvconf; then
		"$resolvconf" -d "$ifname" -f
	else
		if [ -e "$resolv_conf_dir/$ifname" ]; then
			rm -f "$resolv_conf_dir/$ifname"
		fi
		build_resolv_conf
	fi
}

# For ease of use, map DHCP6 names onto our DHCP4 names
case "$reason" in
BOUND6|RENEW6|REBIND6|REBOOT6|INFORM6)
	new_domain_name_servers="$new_dhcp6_name_servers"
	new_domain_search="$new_dhcp6_domain_search"
	;;
esac

if $if_configured; then
	if $have_resolvconf && [ "$reason" = NOCARRIER_ROAMING ]; then
		# avoid calling resolvconf -c on CARRIER unless we roam
		mkdir -p "$nocarrier_roaming_dir"
		printf ' \n' >"$nocarrier_roaming_dir/$interface"
		"$resolvconf" -C "$interface.*"
	elif $have_resolvconf && [ "$reason" = CARRIER ]; then
		# Not all resolvconf implementations support -c
		if [ -e "$nocarrier_roaming_dir/$interface" ]; then
			rm -f "$nocarrier_roaming_dir/$interface"
			"$resolvconf" -c "$interface.*"
		fi
	elif $if_up || [ "$reason" = ROUTERADVERT ]; then
		add_resolv_conf
	elif $if_down; then
		remove_resolv_conf
	fi
fi


================================================
FILE: hooks/29-lookup-hostname
================================================
# SPDX-License-Identifier: BSD-2-Clause
# Copyright (c) 2017-2022 Roy Marples <roy@marples.name>

# Lookup the hostname in DNS if not set

lookup_hostname()
{
	[ -z "$new_ip_address" ] && return 1
	# Silly ISC programs love to send error text to stdout
	if command -v dig >/dev/null 2>&1; then
		h=$(dig +short -x $new_ip_address)
		if [ $? = 0 ]; then
			printf '%s\n' "$h" | sed 's/\.$//'
			return 0
		fi
	elif command -v host >/dev/null 2>&1; then
		h=$(host $new_ip_address)
		if [ $? = 0 ]; then 
			printf '%s\n' "$h" \
			| sed 's/.* domain name pointer \(.*\)./\1/'
			return 0
		fi
	elif command -v getent >/dev/null 2>&1; then
		h=$(getent hosts $new_ip_address)
		if [ $? = 0 ]; then
			printf '%s\n' "$h" | sed 's/[^ ]* *\([^ ]*\).*/\1/'
			return 0
		 fi
	fi
	return 1
}

set_hostname()
{
	if [ -z "${new_host_name}${new_fqdn_name}" ]; then
		export new_host_name="$(lookup_hostname)"
	fi
}

if $if_up; then
	set_hostname
fi


================================================
FILE: hooks/30-hostname.in
================================================
# SPDX-License-Identifier: BSD-2-Clause
# Copyright (c) 2020-2024 Roy Marples <roy@marples.name>

# Set the hostname from DHCP data if required

# A hostname can either be a short hostname or a FQDN.
# hostname_fqdn=true
# hostname_fqdn=false
# hostname_fqdn=server

# A value of server means just what the server says, don't manipulate it.
# This could lead to an inconsistent hostname on a DHCPv4 and DHCPv6 network
# where the DHCPv4 hostname is short and the DHCPv6 has an FQDN.
# DHCPv6 has no hostname option.
# RFC4702 section 3.1 says FQDN should be prefered over hostname.
#
# As such, the default is hostname_fqdn=true so that a consistent hostname
# is always assigned.
: ${hostname_fqdn:=true}

# If we used to set the hostname, but relinquish control of it, we should
# reset to the default value.
: ${hostname_default=@DEFAULT_HOSTNAME@}

# Some systems don't have hostname(1)
_hostname()
{
	if [ -z "${1+x}" ]; then
		if [ -r /proc/sys/kernel/hostname ]; then
			read name </proc/sys/kernel/hostname && printf '%s\n' "$name"
		elif command -v hostname >/dev/null 2>/dev/null; then
			hostname
		elif sysctl kern.hostname >/dev/null 2>&1; then
			sysctl -n kern.hostname
		elif sysctl kernel.hostname >/dev/null 2>&1; then
			sysctl -n kernel.hostname
		else
			return 1
		fi
		return $?
	fi

	if [ -w /proc/sys/kernel/hostname ]; then
		printf '%s\n' "$1" >/proc/sys/kernel/hostname
	elif [ -n "$1" ] && command -v hostname >/dev/null 2>&1; then
		hostname "$1"
	elif sysctl kern.hostname >/dev/null 2>&1; then
		sysctl -w "kern.hostname=$1" >/dev/null
	elif sysctl kernel.hostname >/dev/null 2>&1; then
		sysctl -w "kernel.hostname=$1" >/dev/null
	else
		# May fail to set a blank hostname
		hostname "$1"
	fi
}

is_default_hostname()
{
	case "$1" in
	""|"$hostname_default"|localhost|localhost.localdomain)
		return 0;;
	esac
	return 1
}

need_hostname()
{
	# Always load the hostname variable for future use
	hostname="$(_hostname)"
	is_default_hostname "$hostname" && return 0

	case "$force_hostname" in
	[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|1) return 0;;
	esac

	if [ -n "$old_fqdn" ]; then
		if ${hfqdn} || ! ${hshort}; then
			[ "$hostname" = "$old_fqdn" ]
		else
			[ "$hostname" = "${old_fqdn%%.*}" ]
		fi
	elif [ -n "$old_host_name" ]; then
		if ${hfqdn}; then
			if [ -n "$old_domain_name" ] &&
			   [ "$old_host_name" = "${old_host_name#*.}" ]
			then
				[ "$hostname" = \
				    "$old_host_name.$old_domain_name" ]
			else
				[ "$hostname" = "$old_host_name" ]
			fi
		elif ${hshort}; then
			[ "$hostname" = "${old_host_name%%.*}" ]
		else
			[ "$hostname" = "$old_host_name" ]
		fi
	else
		# No old hostname
		false
	fi
}

try_hostname()
{
	[ "$hostname" = "$1" ] && return 0
	if valid_domainname "$1"; then
		syslog info "Setting hostname: $1"
		_hostname "$1"
	else
		syslog err "Invalid hostname: $1"
	fi
}

set_hostname()
{
	hfqdn=false
	hshort=false
	case "$hostname_fqdn" in
	[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|1)	hfqdn=true;;
	""|[Ss][Ee][Rr][Vv][Ee][Rr])		;;
	*)					hshort=true;;
	esac

	need_hostname || return 0

	if [ -n "$new_fqdn" ]; then
		if ${hfqdn} || ! ${hshort}; then
			try_hostname "$new_fqdn"
		else
			try_hostname "${new_fqdn%%.*}"
		fi
	elif [ -n "$new_host_name" ]; then
		if ${hfqdn}; then
			if [ -n "$new_domain_name" ] &&
			   [ "$new_host_name" = "${new_host_name#*.}" ]
			then
				try_hostname "$new_host_name.$new_domain_name"
			else
				try_hostname "$new_host_name"
			fi
		elif ${hshort}; then
			try_hostname "${new_host_name%%.*}"
		else
			try_hostname "$new_host_name"
		fi
	elif ! is_default_hostname "$hostname"; then
		try_hostname "$hostname_default"
	fi
}

# For ease of use, map DHCP6 names onto our DHCP4 names
case "$reason" in
BOUND6|RENEW6|REBIND6|REBOOT6|INFORM6)
	new_fqdn="$new_dhcp6_fqdn"
	old_fqdn="$old_dhcp6_fqdn"
	;;
esac

if $if_configured && $if_up && [ "$reason" != ROUTERADVERT ]; then
	set_hostname
fi


================================================
FILE: hooks/50-dhcpcd-compat
================================================
# SPDX-License-Identifier: BSD-2-Clause
# Copyright (c) 2017 Roy Marples <roy@marples.name>

# Compat enter hook shim for older dhcpcd versions

IPADDR=$new_ip_address
INTERFACE=$interface
NETMASK=$new_subnet_mask
BROADCAST=$new_broadcast_address
NETWORK=$new_network_number
DHCPSID=$new_dhcp_server_identifier
GATEWAYS=$new_routers
DNSSERVERS=$new_domain_name_servers
DNSDOMAIN=$new_domain_name
DNSSEARCH=$new_domain_search
NISDOMAIN=$new_nis_domain
NISSERVERS=$new_nis_servers
NTPSERVERS=$new_ntp_servers

GATEWAY=
for x in $new_routers; do
	GATEWAY="$GATEWAY${GATEWAY:+,}$x"
done
DNS=
for x in $new_domain_name_servers; do
	DNS="$DNS${DNS:+,}$x"
done

r="down"
case "$reason" in
RENEW) r="up";;
BOUND|INFORM|REBIND|REBOOT|TEST|TIMEOUT|IPV4LL) r="new";;
esac

if [ "$r" != "down" ]; then
	rm -f /var/lib/dhcpcd-"$INTERFACE".info
	for x in IPADDR INTERFACE NETMASK BROADCAST NETWORK DHCPSID GATEWAYS \
		DNSSERVERS DNSDOMAIN DNSSEARCH NISDOMAIN NISSERVERS \
		NTPSERVERS GATEWAY DNS; do
		eval printf '%s\\n' "$x=\'\$$x\'" >> /var/lib/dhcpcd-"$INTERFACE".info
	done
fi

set -- /var/lib/dhcpcd-"$INTERFACE".info "$r"


================================================
FILE: hooks/50-ntp.conf
================================================
# SPDX-License-Identifier: BSD-2-Clause
# Copyright (c) 2017-2026 Roy Marples <roy@marples.name>

# Sample dhcpcd hook script for NTP
# It will configure either one of NTP, OpenNTP or Chrony (in that order)
# and will default to NTP if no default config is found.

# Like our resolv.conf hook script, we store a database of ntp.conf files
# and merge into /etc/ntp.conf

# You can set the env var NTP_CONF to override the derived default on
# systems with >1 NTP client installed.
# Here is an example for OpenNTP
#   dhcpcd -e NTP_CONF=/usr/pkg/etc/ntpd.conf
# or by adding this to /etc/dhcpcd.conf
#   env NTP_CONF=/usr/pkg/etc/ntpd.conf
# or by adding this to /etc/dhcpcd.enter-hook
#   NTP_CONF=/usr/pkg/etc/ntpd.conf
# To use Chrony instead, simply change ntpd.conf to chrony.conf in the
# above examples.

: ${ntp_confs:=ntp.conf ntpd.conf chrony.conf}
: ${ntp_conf_dirs=/etc /usr/pkg/etc /usr/local/etc}
ntp_conf_dir="$state_dir/ntp.conf"

# If NTP_CONF is not set, work out a good default
if [ -z "$NTP_CONF" ]; then
	for d in ${ntp_conf_dirs}; do
		for f in ${ntp_confs}; do
			if [ -e "$d/$f" ]; then
				NTP_CONF="$d/$f"
				break 2
			fi
		done
	done
	[ -e "$NTP_CONF" ] || NTP_CONF=/etc/ntp.conf
fi

# Derive service name from configuration
if [ -z "$ntp_service" ]; then
	case "$NTP_CONF" in
	*chrony.conf)		ntp_service=chronyd;;
	*)			ntp_service=ntpd;;
	esac
fi

# Debian has a separate file for DHCP config to avoid stamping on
# the master.
if [ "$ntp_service" = ntpd ] && command -v invoke-rc.d >/dev/null 2>&1; then
	[ -e /var/lib/ntp ] || mkdir /var/lib/ntp
	: ${ntp_service:=ntp}
	: ${NTP_DHCP_CONF:=/var/lib/ntp/ntp.conf.dhcp}
fi

: ${ntp_restart_cmd:=service_condcommand $ntp_service restart}

ntp_conf=${NTP_CONF}
NL="
"

build_ntp_conf()
{
	cf="$state_dir/ntp.conf.$ifname"

	# Build a list of interfaces
	interfaces=$(list_interfaces "$ntp_conf_dir")

	header=
	servers=
	if [ -n "$interfaces" ]; then
		# Build the header
		for x in ${interfaces}; do
			header="$header${header:+, }$x"
		done

		# Build a server list
	
Download .txt
gitextract_70kvohjb/

├── .clang-format
├── .clang-tidy
├── .clangd
├── .github/
│   └── workflows/
│       ├── build.yml
│       └── format.yml
├── .gitignore
├── BUILDING.md
├── LICENSE
├── Makefile
├── Makefile.inc
├── README.md
├── compat/
│   ├── _strtoi.h
│   ├── arc4random.c
│   ├── arc4random.h
│   ├── arc4random_uniform.c
│   ├── arc4random_uniform.h
│   ├── bitops.h
│   ├── chacha_private.h
│   ├── closefrom.c
│   ├── closefrom.h
│   ├── consttime_memequal.h
│   ├── crypt/
│   │   ├── hmac.c
│   │   ├── hmac.h
│   │   ├── md5.c
│   │   ├── md5.h
│   │   ├── sha256.c
│   │   └── sha256.h
│   ├── crypt_openssl/
│   │   ├── hmac.c
│   │   ├── hmac.h
│   │   ├── sha256.c
│   │   └── sha256.h
│   ├── dprintf.c
│   ├── dprintf.h
│   ├── endian.h
│   ├── pidfile.c
│   ├── pidfile.h
│   ├── queue.h
│   ├── reallocarray.c
│   ├── reallocarray.h
│   ├── setproctitle.c
│   ├── setproctitle.h
│   ├── strlcpy.c
│   ├── strlcpy.h
│   ├── strtoi.c
│   ├── strtoi.h
│   └── strtou.c
├── config-null.mk
├── configure
├── hooks/
│   ├── 01-test
│   ├── 10-wpa_supplicant
│   ├── 15-timezone
│   ├── 20-resolv.conf
│   ├── 29-lookup-hostname
│   ├── 30-hostname.in
│   ├── 50-dhcpcd-compat
│   ├── 50-ntp.conf
│   ├── 50-timesyncd.conf
│   ├── 50-yp.conf
│   ├── 50-ypbind.in
│   ├── Makefile
│   ├── dhcpcd-run-hooks.8.in
│   └── dhcpcd-run-hooks.in
├── iconfig.mk
├── src/
│   ├── GNUmakefile
│   ├── Makefile
│   ├── Makefile.inc
│   ├── arp.c
│   ├── arp.h
│   ├── auth.c
│   ├── auth.h
│   ├── bpf-bsd.c
│   ├── bpf-dlpi.c
│   ├── bpf-dlpi.h
│   ├── bpf-linux.c
│   ├── bpf-pcap.c
│   ├── bpf.c
│   ├── bpf.h
│   ├── common.c
│   ├── common.h
│   ├── control.c
│   ├── control.h
│   ├── defs.h
│   ├── dev/
│   │   ├── Makefile
│   │   └── udev.c
│   ├── dev.c
│   ├── dev.h
│   ├── dhcp-common.c
│   ├── dhcp-common.h
│   ├── dhcp.c
│   ├── dhcp.h
│   ├── dhcp6.c
│   ├── dhcp6.h
│   ├── dhcpcd-definitions-small.conf
│   ├── dhcpcd-definitions.conf
│   ├── dhcpcd-embedded.c.in
│   ├── dhcpcd-embedded.h.in
│   ├── dhcpcd.8.in
│   ├── dhcpcd.c
│   ├── dhcpcd.conf
│   ├── dhcpcd.conf.5.in
│   ├── dhcpcd.h
│   ├── duid.c
│   ├── duid.h
│   ├── eloop.c
│   ├── eloop.h
│   ├── genembedc
│   ├── genembedh
│   ├── if-bsd.c
│   ├── if-linux-wext.c
│   ├── if-linux.c
│   ├── if-options.c
│   ├── if-options.h
│   ├── if-sun.c
│   ├── if.c
│   ├── if.h
│   ├── ipv4.c
│   ├── ipv4.h
│   ├── ipv4ll.c
│   ├── ipv4ll.h
│   ├── ipv6.c
│   ├── ipv6.h
│   ├── ipv6nd.c
│   ├── ipv6nd.h
│   ├── logerr.c
│   ├── logerr.h
│   ├── privsep-bpf.c
│   ├── privsep-bpf.h
│   ├── privsep-bsd.c
│   ├── privsep-control.c
│   ├── privsep-control.h
│   ├── privsep-inet.c
│   ├── privsep-inet.h
│   ├── privsep-linux.c
│   ├── privsep-root.c
│   ├── privsep-root.h
│   ├── privsep-sun.c
│   ├── privsep.c
│   ├── privsep.h
│   ├── queue.h
│   ├── route.c
│   ├── route.h
│   ├── sa.c
│   ├── sa.h
│   ├── script.c
│   └── script.h
├── tests/
│   ├── Makefile
│   └── crypt/
│       ├── .gitignore
│       ├── GNUmakefile
│       ├── Makefile
│       ├── README.md
│       ├── run-test.c
│       ├── test.h
│       ├── test_hmac_md5.c
│       └── test_sha256.c
└── vendor/
    ├── README.md
    ├── queue.h
    ├── rbtree.c
    └── rbtree.h
Download .txt
SYMBOL INDEX (2109 symbols across 93 files)

FILE: compat/_strtoi.h
  function __TYPE (line 51) | __TYPE

FILE: compat/arc4random.c
  type _rs (line 67) | struct _rs {
  type _rsx (line 73) | struct _rsx {
  type _rs (line 81) | struct _rs
  type _rsx (line 81) | struct _rsx
  function _dhcpcd_getentropy (line 101) | static int
  function _getentropy_fail (line 130) | static inline void
  function _rs_forkhandler (line 139) | static inline void
  function _rs_forkdetect (line 145) | static inline void
  function _rs_allocate (line 161) | static inline int
  function _rs_init (line 179) | static inline void
  function _rs_stir (line 194) | static void
  function _rs_stir_if_needed (line 228) | static inline void
  function _rs_rekey (line 240) | static inline void
  function _rs_random_buf (line 263) | static inline void
  function _rs_random_u32 (line 287) | static inline void
  function arc4random (line 301) | uint32_t
  function arc4random_buf (line 312) | void

FILE: compat/arc4random_uniform.c
  function arc4random_uniform (line 37) | uint32_t

FILE: compat/bitops.h
  function ffs32 (line 43) | static inline int __unused
  function ffs64 (line 77) | static inline int __unused
  function fls32 (line 118) | static __inline int __unused
  function fls64 (line 152) | static int __unused

FILE: compat/chacha_private.h
  type u8 (line 11) | typedef unsigned char u8;
  type u32 (line 12) | typedef unsigned int u32;
  type chacha_ctx (line 14) | typedef struct
  function chacha_keysetup (line 56) | static void
  function chacha_ivsetup (line 81) | static void
  function chacha_encrypt_bytes (line 90) | static void

FILE: compat/closefrom.c
  function sys_close_range (line 34) | static inline int
  function closefrom_fallback (line 46) | static int
  function closefrom (line 68) | void

FILE: compat/consttime_memequal.h
  function consttime_memequal (line 9) | inline static int

FILE: compat/crypt/hmac.c
  type hmac (line 70) | struct hmac {
  type hmac (line 132) | struct hmac
  function hmac (line 143) | ssize_t

FILE: compat/crypt/md5.c
  function MD5Init (line 51) | void
  function MD5Transform (line 79) | static void
  function MD5Update (line 179) | void
  function MD5Final (line 217) | void

FILE: compat/crypt/md5.h
  type MD5_CTX (line 25) | typedef struct MD5Context {

FILE: compat/crypt/sha256.c
  function be32enc_vect (line 64) | static void
  function be32dec_vect (line 77) | static void
  function SHA256_Transform (line 117) | static void
  function SHA256_Pad (line 212) | static void
  function SHA256_Init (line 234) | void
  function SHA256_Update (line 253) | void
  function SHA256_Final (line 296) | void

FILE: compat/crypt/sha256.h
  type SHA256_CTX (line 37) | typedef struct SHA256Context {

FILE: compat/crypt_openssl/hmac.c
  function hmac (line 34) | ssize_t

FILE: compat/crypt_openssl/sha256.c
  function dhcpcd_SHA256_Init (line 33) | void
  function dhcpcd_SHA256_Update (line 41) | void
  function dhcpcd_SHA256_Final (line 51) | void

FILE: compat/crypt_openssl/sha256.h
  type dhcpcd_SHA256_CTX (line 33) | typedef struct dhcpcd_SHA256Context {

FILE: compat/dprintf.c
  function vdprintf (line 36) | int
  function dprintf (line 55) | int

FILE: compat/endian.h
  function be32enc (line 34) | inline static void
  function be64enc (line 44) | inline static void
  function be16dec (line 52) | inline static uint16_t
  function be32dec (line 59) | inline static uint32_t
  function be64dec (line 66) | inline static uint64_t

FILE: compat/pidfile.c
  function pidfile_close (line 57) | static int
  function pidfile_clean (line 75) | int
  function pidfile_cleanup (line 106) | static void
  function pidfile_varrun_path (line 118) | static int
  function pid_t (line 136) | pid_t
  function pid_t (line 177) | pid_t

FILE: compat/setproctitle.c
  function spt_min (line 60) | static inline size_t
  function spt_clearenv (line 70) | static int
  function spt_copyenv (line 87) | static int
  function spt_copyargs (line 145) | static int
  function setproctitle_init (line 165) | void
  function setproctitle_fini (line 230) | void
  function setproctitle_impl (line 252) | static void

FILE: compat/setproctitle.h
  function setprogname (line 44) | static inline void

FILE: compat/strlcpy.c
  function strlcpy (line 29) | size_t

FILE: src/arp.c
  type arphdr (line 66) | struct arphdr
  function arp_request (line 68) | static ssize_t
  function arp_report_conflicted (line 120) | static void
  function arp_found (line 145) | static void
  function arp_validate (line 204) | static bool
  function arp_packet (line 231) | void
  function arp_read (line 324) | static void
  function arp_probed (line 357) | static void
  function arp_probe1 (line 366) | static void
  function arp_probe (line 392) | void
  type arp_state (line 402) | struct arp_state
  type interface (line 403) | struct interface
  type in_addr (line 403) | struct in_addr
  type iarp_state (line 405) | struct iarp_state
  type arp_state (line 406) | struct arp_state
  function arp_announced (line 420) | static void
  function arp_announce1 (line 433) | static void
  function arp_announce (line 473) | static void
  type arp_state (line 509) | struct arp_state
  type interface (line 510) | struct interface
  type in_addr (line 510) | struct in_addr
  type arp_state (line 512) | struct arp_state
  type arp_state (line 529) | struct arp_state
  type interface (line 530) | struct interface
  type in_addr (line 530) | struct in_addr
  type iarp_state (line 532) | struct iarp_state
  type arp_state (line 533) | struct arp_state
  function arp_free (line 581) | void
  function arp_freeaddr (line 617) | void
  function arp_drop (line 626) | void

FILE: src/arp.h
  type arp_msg (line 57) | struct arp_msg {
  type arp_state (line 68) | struct arp_state {
  type iarp_state (line 86) | struct iarp_state {
  type interface (line 94) | struct interface
  type arp_state (line 95) | struct arp_state
  type interface (line 95) | struct interface
  type in_addr (line 95) | struct in_addr
  type arp_state (line 96) | struct arp_state
  type arp_state (line 97) | struct arp_state
  type interface (line 97) | struct interface
  type in_addr (line 98) | struct in_addr
  type arp_state (line 99) | struct arp_state
  type interface (line 99) | struct interface
  type in_addr (line 99) | struct in_addr
  type arp_state (line 100) | struct arp_state
  type interface (line 101) | struct interface
  type in_addr (line 101) | struct in_addr
  type interface (line 102) | struct interface

FILE: src/auth.c
  function dhcp_auth_reset (line 80) | void
  type token (line 104) | struct token
  type authstate (line 105) | struct authstate
  type auth (line 105) | struct auth
  type token (line 114) | struct token
  type bootp (line 340) | struct bootp
  type bootp (line 342) | struct bootp
  type bootp (line 343) | struct bootp
  function auth_get_rdm_monotonic (line 407) | int
  function get_next_rdm_monotonic_clock (line 458) | static uint64_t
  function get_next_rdm_monotonic (line 474) | static uint64_t
  function dhcp_auth_encode (line 510) | ssize_t

FILE: src/auth.h
  type token (line 52) | struct token {
  type auth (line 64) | struct auth {
  type authstate (line 78) | struct authstate {
  type authstate (line 84) | struct authstate
  type token (line 86) | struct token
  type authstate (line 86) | struct authstate
  type auth (line 86) | struct auth
  type dhcpcd_ctx (line 89) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 90) | struct dhcpcd_ctx
  type auth (line 90) | struct auth
  type token (line 91) | struct token

FILE: src/bpf-bsd.c
  type bpf (line 48) | struct bpf
  type interface (line 49) | struct interface
  type bpf (line 50) | struct bpf
  type in_addr (line 50) | struct in_addr
  type in_addr (line 51) | struct in_addr
  type bpf (line 53) | struct bpf
  type bpf_version (line 54) | struct bpf_version
  type ifreq (line 55) | struct ifreq
  function bpf_read (line 143) | ssize_t
  function bpf_setfilter (line 211) | int
  function bpf_setwfilter (line 220) | int
  function bpf_lockfilter (line 238) | int
  function bpf_writev (line 252) | ssize_t
  function bpf_close (line 259) | void

FILE: src/bpf-dlpi.c
  type bpf_dlpi (line 41) | struct bpf_dlpi {
  function bpf_dlpi_open (line 47) | int
  function bpf_writev (line 77) | ssize_t
  function bpf_dlpi_close (line 101) | void

FILE: src/bpf-dlpi.h
  type bpf (line 32) | struct bpf
  type bpf (line 34) | struct bpf
  type bpf (line 35) | struct bpf

FILE: src/bpf-linux.c
  type bpf (line 43) | struct bpf
  type interface (line 44) | struct interface
  type bpf (line 45) | struct bpf
  type in_addr (line 45) | struct in_addr
  type in_addr (line 46) | struct in_addr
  type bpf (line 48) | struct bpf
  type sockaddr (line 50) | struct sockaddr
  type sockaddr_ll (line 51) | struct sockaddr_ll
  type sockaddr_storage (line 52) | struct sockaddr_storage
  function bpf_read (line 117) | ssize_t
  function bpf_setfilter (line 172) | int
  function bpf_setwfilter (line 185) | int
  function bpf_lockfilter (line 194) | int
  function bpf_writev (line 208) | ssize_t
  function bpf_close (line 214) | void

FILE: src/bpf-pcap.c
  type bpf (line 55) | struct bpf
  type interface (line 56) | struct interface
  type bpf (line 57) | struct bpf
  type in_addr (line 57) | struct in_addr
  type in_addr (line 58) | struct in_addr
  type bpf (line 61) | struct bpf
  function bpf_read (line 121) | ssize_t
  function bpf_writev (line 152) | ssize_t
  function bpf_setfilter (line 179) | int
  function bpf_setwfilter (line 188) | int
  function bpf_lockfilter (line 214) | int
  function bpf_close (line 234) | void

FILE: src/bpf.c
  function bpf_frame_header_len (line 83) | size_t
  type interface (line 95) | struct interface
  type ether_header (line 101) | struct ether_header
  type ether_header (line 102) | struct ether_header
  type interface (line 111) | struct interface
  type ether_header (line 117) | struct ether_header
  type ether_header (line 118) | struct ether_header
  function bpf_frame_bcast (line 128) | int
  function bpf_send (line 141) | ssize_t
  function bpf_cmp_hwaddr (line 169) | static unsigned int
  type bpf_insn (line 253) | struct bpf_insn
  type ether_header (line 256) | struct ether_header
  type ether_header (line 261) | struct ether_header
  type arphdr (line 264) | struct arphdr
  type arphdr (line 269) | struct arphdr
  type ether_arp (line 271) | struct ether_arp
  type bpf_insn (line 276) | struct bpf_insn
  type arphdr (line 278) | struct arphdr
  type arphdr (line 282) | struct arphdr
  type arphdr (line 288) | struct arphdr
  function bpf_arp_rw (line 302) | static int
  function bpf_filter_arp (line 369) | int
  type bpf_insn (line 383) | struct bpf_insn
  type bpf_insn (line 387) | struct bpf_insn
  type ether_header (line 390) | struct ether_header
  type ether_header (line 395) | struct ether_header
  type bpf_insn (line 399) | struct bpf_insn
  type ip (line 407) | struct ip
  type ip (line 412) | struct ip
  type bpf_insn (line 425) | struct bpf_insn
  type udphdr (line 428) | struct udphdr
  type bpf_insn (line 434) | struct bpf_insn
  function bpf_bootp_rw (line 451) | static int
  function bpf_filter_bootp (line 500) | int

FILE: src/bpf.h
  type bpf (line 57) | struct bpf {
  type iovec (line 67) | struct iovec
  type interface (line 70) | struct interface
  type interface (line 71) | struct interface
  type interface (line 72) | struct interface
  type interface (line 73) | struct interface
  type bpf (line 74) | struct bpf
  type interface (line 74) | struct interface
  type bpf (line 75) | struct bpf
  type in_addr (line 75) | struct in_addr
  type in_addr (line 76) | struct in_addr
  type bpf (line 77) | struct bpf
  type bpf (line 78) | struct bpf
  type bpf (line 79) | struct bpf
  type bpf (line 80) | struct bpf
  type bpf (line 81) | struct bpf
  type bpf (line 82) | struct bpf
  type iovec (line 82) | struct iovec
  type bpf (line 83) | struct bpf
  type bpf (line 85) | struct bpf
  type in_addr (line 85) | struct in_addr
  type bpf (line 86) | struct bpf
  type in_addr (line 86) | struct in_addr

FILE: src/common.c
  function hwaddr_aton (line 75) | size_t
  function readfile (line 112) | ssize_t
  function writefile (line 130) | ssize_t
  function filemtime (line 144) | int
  function is_root_local (line 202) | int
  function lifetime_left (line 217) | uint32_t

FILE: src/common.h
  type timespec (line 175) | struct timespec
  type timespec (line 175) | struct timespec

FILE: src/control.c
  function control_queue_free (line 58) | static void
  function control_free (line 80) | void
  function control_hangup (line 95) | static void
  function control_handle_read (line 107) | static int
  function control_handle_write (line 146) | static int
  function control_handle_data (line 202) | static void
  function control_recvdata (line 222) | void
  type fd_list (line 277) | struct fd_list
  type dhcpcd_ctx (line 278) | struct dhcpcd_ctx
  type fd_list (line 280) | struct fd_list
  function control_handle1 (line 297) | static void
  function control_handle (line 341) | static void
  function control_handle_unpriv (line 349) | static void
  function make_path (line 357) | static int
  function make_sock (line 383) | static int
  function control_start1 (line 400) | static int
  function control_start (line 441) | int
  function control_unlink (line 473) | static int
  function control_stop (line 491) | int
  function control_open (line 533) | int
  function control_send (line 551) | ssize_t
  function control_queue (line 575) | int

FILE: src/control.h
  type fd_data (line 47) | struct fd_data {
  type fd_list (line 56) | struct fd_list {
  type dhcpcd_ctx (line 72) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 73) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 75) | struct dhcpcd_ctx
  type fd_list (line 76) | struct fd_list
  type dhcpcd_ctx (line 76) | struct dhcpcd_ctx
  type fd_list (line 77) | struct fd_list
  type fd_list (line 78) | struct fd_list
  type fd_list (line 79) | struct fd_list
  type fd_list (line 80) | struct fd_list

FILE: src/dev.c
  function dev_initialised (line 41) | int
  function dev_listening (line 55) | int
  function dev_stop1 (line 69) | static void
  function dev_stop (line 87) | void
  function dev_start2 (line 93) | static int
  function dev_start1 (line 131) | static int
  function dev_handle_data (line 165) | static void
  function dev_start (line 179) | int

FILE: src/dev.h
  type dev (line 32) | struct dev {
  type dev_dhcpcd (line 41) | struct dev_dhcpcd {
  type dev (line 45) | struct dev
  type dev_dhcpcd (line 45) | struct dev_dhcpcd
  type dhcpcd_ctx (line 50) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 51) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 52) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 53) | struct dhcpcd_ctx

FILE: src/dev/udev.c
  type udev (line 46) | struct udev
  type udev_monitor (line 47) | struct udev_monitor
  type dev_dhcpcd (line 49) | struct dev_dhcpcd
  function udev_listening (line 51) | static int
  function udev_initialised (line 57) | static int
  function udev_handle_device (line 76) | static int
  function udev_stop (line 105) | static void
  function udev_start (line 119) | static int
  function dev_init (line 169) | int

FILE: src/dhcp-common.c
  type if_options (line 49) | struct if_options
  function dhcp_print_option_encoding (line 76) | void
  type dhcp_opt (line 140) | struct dhcp_opt
  type interface (line 143) | struct interface
  type dhcp_opt (line 145) | struct dhcp_opt
  function dhcp_vendor (line 158) | ssize_t
  function make_option_mask (line 182) | int
  function encode_rfc1035 (line 251) | size_t
  function decode_rfc1035 (line 307) | ssize_t
  function valid_domainname (line 411) | static ssize_t
  function print_string (line 478) | ssize_t
  function dhcp_optlen (line 580) | static ssize_t
  function print_option (line 620) | static ssize_t
  function dhcp_set_leasefile (line 837) | int
  function dhcp_envoption (line 867) | void
  function dhcp_zero_index (line 980) | void
  function dhcp_readfile (line 993) | ssize_t
  function dhcp_writefile (line 1007) | ssize_t
  function dhcp_filemtime (line 1022) | int
  function dhcp_unlink (line 1036) | int
  function dhcp_read_hwaddr_aton (line 1050) | size_t

FILE: src/dhcp-common.h
  type dhcp_opt (line 88) | struct dhcp_opt {
  type if_options (line 107) | struct if_options
  type dhcp_opt (line 108) | struct dhcp_opt
  type dhcp_opt (line 112) | struct dhcp_opt
  type dhcp_opt (line 119) | struct dhcp_opt
  type dhcp_opt (line 119) | struct dhcp_opt
  type interface (line 125) | struct interface
  type dhcpcd_ctx (line 127) | struct dhcpcd_ctx
  type dhcp_opt (line 128) | struct dhcp_opt
  type dhcpcd_ctx (line 129) | struct dhcpcd_ctx
  type dhcp_opt (line 130) | struct dhcp_opt
  type dhcp_opt (line 132) | struct dhcp_opt
  type dhcpcd_ctx (line 134) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 135) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 137) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 138) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 139) | struct dhcpcd_ctx

FILE: src/dhcp.c
  type ip (line 99) | struct ip
  type udphdr (line 100) | struct udphdr
  type bootp (line 101) | struct bootp
  type dhcp_op (line 105) | struct dhcp_op {
  type dhcp_op (line 110) | struct dhcp_op
  type interface (line 119) | struct interface
  type arp_state (line 122) | struct arp_state
  type arp_msg (line 122) | struct arp_msg
  type interface (line 124) | struct interface
  type bootp (line 124) | struct bootp
  type in_addr (line 125) | struct in_addr
  type interface (line 127) | struct interface
  function dhcp_printoptions (line 129) | void
  type dhcpcd_ctx (line 157) | struct dhcpcd_ctx
  type bootp (line 157) | struct bootp
  function get_option_addr (line 271) | static int
  function get_option_uint32 (line 285) | static int
  function get_option_uint16 (line 302) | static int
  function get_option_uint8 (line 319) | static int
  function print_rfc3442 (line 334) | ssize_t
  function decode_rfc3442_rt (line 385) | static int
  function print_rfc3361 (line 446) | ssize_t
  type dhcpcd_ctx (line 495) | struct dhcpcd_ctx
  type bootp (line 495) | struct bootp
  function route_netmask (line 517) | static uint32_t
  function get_option_routes (line 546) | static int
  function dhcp_get_mtu (line 650) | uint16_t
  function dhcp_get_routes (line 671) | int
  function dhcp_message_add_addr (line 682) | static int
  type rfc3396_ctx (line 709) | struct rfc3396_ctx {
  function rfc3396_write (line 722) | static ssize_t
  function rfc3396_write_byte (line 762) | static ssize_t
  type rfc3396_ctx (line 769) | struct rfc3396_ctx
  function make_message (line 779) | static ssize_t
  function read_lease (line 1231) | static size_t
  type dhcp_opt (line 1315) | struct dhcp_opt
  type if_options (line 1316) | struct if_options
  type dhcp_opt (line 1319) | struct dhcp_opt
  type dhcpcd_ctx (line 1330) | struct dhcpcd_ctx
  type dhcp_opt (line 1331) | struct dhcp_opt
  type dhcp_opt (line 1334) | struct dhcp_opt
  function dhcp_env (line 1361) | ssize_t
  function get_lease (line 1474) | static void
  type dhcp_op (line 1534) | struct dhcp_op
  function dhcp_fallback (line 1542) | static void
  function dhcp_new_xid (line 1552) | static void
  function dhcp_closebpf (line 1600) | static void
  function dhcp_closeinet (line 1618) | static void
  function dhcp_close (line 1638) | void
  function dhcp_openudp (line 1652) | int
  function in_cksum (line 1692) | static uint16_t
  type bootp_pkt (line 1713) | struct bootp_pkt
  type in_addr (line 1715) | struct in_addr
  type in_addr (line 1715) | struct in_addr
  type bootp_pkt (line 1717) | struct bootp_pkt
  type ip (line 1718) | struct ip
  type udphdr (line 1719) | struct udphdr
  function dhcp_sendudp (line 1763) | static ssize_t
  function send_message (line 1804) | static void
  function send_inform (line 1927) | static void
  function send_discover (line 1933) | static void
  function send_request (line 1939) | static void
  function send_renew (line 1945) | static void
  function send_rebind (line 1951) | static void
  function dhcp_discover (line 1957) | void
  function dhcp_requestfailed (line 1986) | static void
  function dhcp_request (line 2000) | static void
  function dhcp_expire (line 2015) | static void
  function dhcp_decline (line 2034) | static void
  function dhcp_startrenew (line 2046) | static void
  function dhcp_renew (line 2072) | void
  function dhcp_rebind (line 2078) | static void
  function dhcp_finish_dad (line 2098) | static void
  function dhcp_addr_duplicated (line 2138) | static bool
  function dhcp_arp_announced (line 2182) | static void
  function dhcp_arp_defend_failed (line 2189) | static void
  type arp_state (line 2210) | struct arp_state
  type arp_state (line 2212) | struct arp_state
  type interface (line 2213) | struct interface
  type in_addr (line 2213) | struct in_addr
  type arp_state (line 2215) | struct arp_state
  function dhcp_arping (line 2234) | static int
  function dhcp_arp_not_found (line 2266) | static void
  function dhcp_arp_found (line 2282) | static void
  function dhcp_bound (line 2325) | static void
  function dhcp_bind (line 2366) | void
  function dhcp_message_new (line 2519) | static size_t
  function dhcp_arp_address (line 2548) | static int
  function dhcp_arp_bind (line 2606) | static void
  function dhcp_lastlease (line 2614) | static void
  function dhcp_static (line 2634) | static void
  function dhcp_inform (line 2665) | void
  function dhcp_reboot_newopts (line 2727) | void
  function dhcp_reboot (line 2745) | static void
  function dhcp_deconfigure (line 2809) | static void
  function dhcp_drop (line 2854) | void
  function blacklisted_ip (line 2922) | static int
  function whitelisted_ip (line 2936) | static unsigned int
  function log_dhcp (line 2949) | static void
  function dhcp_redirect_dhcp (line 3020) | static void
  function dhcp_handledhcp (line 3046) | static void
  type ip (line 3493) | struct ip
  type udphdr (line 3497) | struct udphdr
  type udphdr (line 3498) | struct udphdr
  function is_packet_udp_bootp (line 3502) | static bool
  type ip_pseudo (line 3542) | struct ip_pseudo {
  function checksums_valid (line 3551) | static bool
  function dhcp_handlebootp (line 3599) | static void
  function dhcp_packet (line 3623) | void
  function dhcp_readbpf (line 3693) | static void
  function dhcp_recvmsg (line 3725) | void
  function dhcp_readudp (line 3774) | static void
  function dhcp_handleudp (line 3826) | static void
  function dhcp_handleifudp (line 3834) | static void
  function dhcp_openbpf (line 3842) | static int
  function dhcp_free (line 3880) | void
  function dhcp_initstate (line 3927) | static int
  function dhcp_init (line 3950) | static int
  function dhcp_start1 (line 4028) | static void
  function dhcp_start (line 4204) | void
  function dhcp_abort (line 4269) | void
  type ipv4_addr (line 4286) | struct ipv4_addr
  type ipv4_addr (line 4287) | struct ipv4_addr
  type interface (line 4289) | struct interface
  type dhcp_state (line 4290) | struct dhcp_state
  type if_options (line 4291) | struct if_options
  function dhcp_dump (line 4371) | int

FILE: src/dhcp.h
  type DHO (line 89) | enum DHO {
  type FQDN (line 136) | enum FQDN {
  type bootp (line 152) | struct bootp {
  type bootp_pkt (line 173) | struct bootp_pkt {
  type dhcp_lease (line 179) | struct dhcp_lease {
  type DHS (line 195) | enum DHS {
  type dhcp_state (line 210) | struct dhcp_state {
  type in_addr (line 257) | struct in_addr
  type interface (line 258) | struct interface
  type dhcpcd_ctx (line 259) | struct dhcpcd_ctx
  type msghdr (line 259) | struct msghdr
  type dhcpcd_ctx (line 260) | struct dhcpcd_ctx
  type dhcp_opt (line 260) | struct dhcp_opt
  type interface (line 262) | struct interface
  type interface (line 263) | struct interface
  type interface (line 264) | struct interface
  type bootp (line 265) | struct bootp
  type ipv4_addr (line 267) | struct ipv4_addr
  type ipv4_addr (line 267) | struct ipv4_addr
  type interface (line 268) | struct interface
  type interface (line 269) | struct interface
  type interface (line 270) | struct interface
  type interface (line 272) | struct interface
  type interface (line 273) | struct interface
  type interface (line 274) | struct interface
  type interface (line 275) | struct interface
  type interface (line 276) | struct interface
  type interface (line 277) | struct interface
  type interface (line 278) | struct interface

FILE: src/dhcp6.c
  type dhcp6_message (line 81) | struct dhcp6_message {
  type dhcp6_message (line 86) | struct dhcp6_message
  type dhcp6_option (line 88) | struct dhcp6_option {
  type dhcp6_option (line 93) | struct dhcp6_option
  type dhcp6_ia_na (line 95) | struct dhcp6_ia_na {
  type dhcp6_ia_na (line 100) | struct dhcp6_ia_na
  type dhcp6_ia_ta (line 102) | struct dhcp6_ia_ta {
  type dhcp6_ia_ta (line 105) | struct dhcp6_ia_ta
  type dhcp6_ia_addr (line 107) | struct dhcp6_ia_addr {
  type dhcp6_ia_addr (line 112) | struct dhcp6_ia_addr
  type dhcp6_pd_addr (line 117) | struct dhcp6_pd_addr {
  type dhcp6_pd_addr (line 123) | struct dhcp6_pd_addr
  type dhcp6_op (line 132) | struct dhcp6_op {
  type dhcp6_op (line 137) | struct dhcp6_op
  type dhcp_compat (line 145) | struct dhcp_compat {
  type dhcp_compat (line 155) | struct dhcp_compat
  type interface (line 170) | struct interface
  type interface (line 174) | struct interface
  type interface (line 175) | struct interface
  type interface (line 180) | struct interface
  function dhcp6_printoptions (line 192) | void
  function dhcp6_makeuser (line 216) | static size_t
  function dhcp6_makevendor (line 260) | static size_t
  function dhcp6_makevendoropts (line 331) | static size_t
  type dhcp6_option (line 400) | struct dhcp6_option
  type dhcp6_message (line 432) | struct dhcp6_message
  type dhcp6_message (line 437) | struct dhcp6_message
  type dhcp6_message (line 438) | struct dhcp6_message
  type dhcpcd_ctx (line 443) | struct dhcpcd_ctx
  type dhcp_opt (line 444) | struct dhcp_opt
  type dhcp6_option (line 446) | struct dhcp6_option
  type dhcp_opt (line 448) | struct dhcp_opt
  function dhcp6_updateelapsed (line 479) | static bool
  function dhcp6_newxid (line 524) | static void
  type if_sla (line 569) | struct if_sla
  type interface (line 570) | struct interface
  type if_ia (line 573) | struct if_ia
  function dhcp6_delegateaddr (line 587) | static int
  function dhcp6_makemessage (line 691) | static int
  type dhcp6_op (line 1230) | struct dhcp6_op
  function dhcp6_freedrop_addrs (line 1238) | static void
  function dhcp6_delete_delegates (line 1253) | static void
  function dhcp6_update_auth (line 1268) | static ssize_t
  type in6_addr (line 1286) | struct in6_addr
  function dhcp6_sendmessage (line 1287) | static int
  function dhcp6_sendinform (line 1476) | static void
  function dhcp6_senddiscover2 (line 1482) | static void
  function dhcp6_senddiscover1 (line 1488) | static void
  function dhcp6_senddiscover (line 1505) | static void
  function dhcp6_sendrequest (line 1515) | static void
  function dhcp6_sendrebind (line 1521) | static void
  function dhcp6_sendrenew (line 1527) | static void
  function dhcp6_sendconfirm (line 1533) | static void
  function dhcp6_senddecline (line 1539) | static void
  function dhcp6_sendrelease (line 1545) | static void
  function dhcp6_startrenew (line 1551) | static void
  function dhcp6_renew (line 1581) | void
  function dhcp6_dadcompleted (line 1587) | bool
  type ipv6_addr (line 1605) | struct ipv6_addr
  type interface (line 1606) | struct interface
  type dhcp6_state (line 1607) | struct dhcp6_state
  type ipv6_addr (line 1608) | struct ipv6_addr
  function dhcp6_addrequestedaddrs (line 1659) | static void
  function dhcp6_startdiscover (line 1693) | static void
  function dhcp6_startinform (line 1739) | static void
  function dhcp6_startdiscoinform (line 1777) | static bool
  function dhcp6_fail (line 1791) | static void
  function dhcp6_failloglevel (line 1833) | static int
  function dhcp6_failconfirm (line 1841) | static void
  function dhcp6_failrequest (line 1856) | static void
  function dhcp6_failinform (line 1866) | static void
  function dhcp6_failrebindpd (line 1878) | static void
  function dhcp6_hasprefixdelegation (line 1892) | static int
  function dhcp6_startrebind (line 1911) | static void
  function dhcp6_startrequest (line 1951) | static void
  function dhcp6_startconfirm (line 1974) | static void
  function dhcp6_startexpire (line 2008) | static void
  function dhcp6_faildecline (line 2020) | static void
  function dhcp6_startdecline (line 2029) | static void
  function dhcp6_finishrelease (line 2050) | static void
  function dhcp6_startrelease (line 2063) | static void
  function dhcp6_checkstatusok (line 2090) | static int
  type ipv6_addr (line 2171) | struct ipv6_addr
  type interface (line 2172) | struct interface
  type in6_addr (line 2172) | struct in6_addr
  type dhcp6_state (line 2175) | struct dhcp6_state
  type ipv6_addr (line 2176) | struct ipv6_addr
  type ipv6_addr (line 2187) | struct ipv6_addr
  type dhcpcd_ctx (line 2188) | struct dhcpcd_ctx
  type in6_addr (line 2188) | struct in6_addr
  type interface (line 2191) | struct interface
  type ipv6_addr (line 2192) | struct ipv6_addr
  type dhcp6_state (line 2193) | struct dhcp6_state
  function dhcp6_findna (line 2206) | static int
  function dhcp6_findpd (line 2280) | static int
  function dhcp6_findia (line 2408) | static int
  function dhcp6_deprecatedele (line 2548) | static void
  function dhcp6_deprecateaddrs (line 2587) | static void
  function dhcp6_validatelease (line 2629) | static int
  function dhcp6_readlease (line 2669) | static ssize_t
  function dhcp6_startinit (line 2776) | static void
  type ipv6_addr (line 2824) | struct ipv6_addr
  type interface (line 2825) | struct interface
  type ipv6_addr (line 2825) | struct ipv6_addr
  type if_sla (line 2826) | struct if_sla
  type if_ia (line 2826) | struct if_ia
  type dhcp6_state (line 2828) | struct dhcp6_state
  type in6_addr (line 2829) | struct in6_addr
  type ipv6_addr (line 2830) | struct ipv6_addr
  function dhcp6_script_try_run (line 2906) | static void
  function dhcp6_find_delegates (line 2944) | size_t
  function dhcp6_delegate_prefix (line 2950) | static void
  function dhcp6_find_delegates1 (line 3050) | static void
  function dhcp6_find_delegates (line 3056) | size_t
  function dhcp6_bind (line 3119) | static void
  function dhcp6_adjust_max_rt (line 3348) | static void
  type interface (line 3386) | struct interface
  type dhcp6_message (line 3386) | struct dhcp6_message
  type dhcpcd_ctx (line 3389) | struct dhcpcd_ctx
  type dhcp6_state (line 3392) | struct dhcp6_state
  type dhcp_opt (line 3395) | struct dhcp_opt
  type if_options (line 3396) | struct if_options
  type ipv6_addr (line 3647) | struct ipv6_addr
  function dhcp6_recvmsg (line 3675) | void
  function dhcp6_recv (line 3806) | static void
  function dhcp6_recvaddr (line 3847) | static void
  function dhcp6_recvctx (line 3856) | static void
  function dhcp6_openraw (line 3864) | int
  function dhcp6_openudp (line 3888) | int
  function dhcp6_activateinterfaces (line 3933) | static void
  function dhcp6_start1 (line 3965) | static void
  function dhcp6_start (line 4030) | int
  function dhcp6_reboot (line 4124) | void
  function dhcp6_freedrop (line 4146) | static void
  function dhcp6_drop (line 4237) | void
  function dhcp6_free (line 4243) | void
  function dhcp6_abort (line 4249) | void
  function dhcp6_handleifa (line 4275) | void
  function dhcp6_env (line 4307) | ssize_t
  function dhcp6_dump (line 4434) | int

FILE: src/dhcp6.h
  type DH6S (line 162) | enum DH6S {
  type dhcp6_state (line 181) | struct dhcp6_state {
  type in6_addr (line 234) | struct in6_addr
  type dhcpcd_ctx (line 235) | struct dhcpcd_ctx
  type msghdr (line 235) | struct msghdr
  type ipv6_addr (line 235) | struct ipv6_addr
  type dhcpcd_ctx (line 236) | struct dhcpcd_ctx
  type dhcp_opt (line 236) | struct dhcp_opt
  type ipv6_addr (line 238) | struct ipv6_addr
  type interface (line 238) | struct interface
  type in6_addr (line 239) | struct in6_addr
  type ipv6_addr (line 240) | struct ipv6_addr
  type dhcpcd_ctx (line 240) | struct dhcpcd_ctx
  type in6_addr (line 240) | struct in6_addr
  type interface (line 242) | struct interface
  type interface (line 243) | struct interface
  type DH6S (line 243) | enum DH6S
  type interface (line 244) | struct interface
  type interface (line 245) | struct interface
  type interface (line 246) | struct interface
  type dhcp6_message (line 247) | struct dhcp6_message
  type interface (line 248) | struct interface
  type ipv6_addr (line 249) | struct ipv6_addr
  type interface (line 250) | struct interface
  type interface (line 251) | struct interface
  type interface (line 252) | struct interface
  type interface (line 253) | struct interface

FILE: src/dhcpcd.c
  function usage (line 104) | static void
  function free_globals (line 130) | static void
  function handle_exit_timeout (line 190) | static void
  function dhcpcd_ifafwaiting (line 227) | int
  function dhcpcd_afwaiting (line 266) | int
  function dhcpcd_ipwaited (line 302) | static int
  function dhcpcd_daemonised (line 325) | void
  function dhcpcd_daemonise (line 351) | void
  function dhcpcd_drop_af (line 394) | static void
  function dhcpcd_drop (line 424) | static void
  function dhcpcd_ifrunning (line 430) | static bool
  function dhcpcd_dropped (line 448) | void
  function stop_interface (line 477) | static void
  function configure_interface1 (line 485) | static void
  function dhcpcd_selectprofile (line 627) | int
  function configure_interface (line 665) | static void
  function dhcpcd_initstate1 (line 689) | static void
  function dhcpcd_initstate (line 710) | static void
  function dhcpcd_reportssid (line 717) | static void
  function dhcpcd_nocarrier_roaming (line 731) | static void
  function dhcpcd_handlecarrier (line 753) | void
  function warn_iaid_conflict (line 869) | static void
  function dhcpcd_initduid (line 903) | static void
  function dhcpcd_startinterface (line 923) | void
  function dhcpcd_prestartinterface (line 1013) | static void
  function run_preinit (line 1040) | static void
  function dhcpcd_activateinterface (line 1054) | void
  function dhcpcd_handleinterface (line 1075) | int
  function dhcpcd_handlelink (line 1159) | static void
  function dhcpcd_checkcarrier (line 1177) | static void
  function dhcpcd_setlinkrcvbuf (line 1189) | static void
  function dhcpcd_runprestartinterface (line 1207) | static void
  function dhcpcd_linkoverflow (line 1216) | void
  function dhcpcd_handlehwaddr (line 1296) | void
  function if_reboot (line 1334) | static void
  function reload_config (line 1355) | static void
  function reconf_reboot (line 1377) | static void
  function stop_all_interfaces (line 1426) | static bool
  function dhcpcd_ifrenew (line 1453) | static void
  function dhcpcd_renew (line 1475) | static void
  function dhcpcd_signal_cb (line 1487) | static void
  function dhcpcd_handleargs (line 1578) | int
  function dhcpcd_readdump2 (line 1774) | static void
  function dhcpcd_readdump1 (line 1814) | static void
  function dhcpcd_readdump0 (line 1850) | static void
  function dhcpcd_readdumptimeout (line 1878) | static void
  function dhcpcd_readdump (line 1887) | static int
  function dhcpcd_fork_cb (line 1898) | static void
  function dhcpcd_pidfile_timeout (line 1941) | static void
  function dhcpcd_exit_timeout (line 1955) | static void
  function dup_null (line 1970) | static int
  function main (line 1987) | int

FILE: src/dhcpcd.h
  type interface (line 71) | struct interface {
  type passwd (line 116) | struct passwd
  type dhcpcd_ctx (line 118) | struct dhcpcd_ctx {
  type interface (line 260) | struct interface
  type dhcpcd_ctx (line 261) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 262) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 263) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 265) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 266) | struct dhcpcd_ctx
  type fd_list (line 266) | struct fd_list
  type interface (line 267) | struct interface
  type interface (line 269) | struct interface
  type interface (line 270) | struct interface
  type interface (line 271) | struct interface
  type interface (line 272) | struct interface
  type interface (line 275) | struct interface

FILE: src/duid.c
  function duid_machineuuid (line 61) | static size_t
  function duid_make_uuid (line 101) | static size_t
  function duid_make (line 123) | size_t
  function duid_get (line 156) | static size_t
  function duid_init (line 239) | size_t

FILE: src/duid.h
  type interface (line 37) | struct interface
  type dhcpcd_ctx (line 38) | struct dhcpcd_ctx
  type interface (line 38) | struct interface

FILE: src/eloop.c
  type eloop_event (line 96) | struct eloop_event {
  type eloop_timeout (line 107) | struct eloop_timeout {
  type eloop (line 116) | struct eloop {
  function eloop_event_setup_fds (line 167) | static int
  function eloop_grow_events (line 208) | static int
  function eloop_event_count (line 227) | size_t
  function eloop_signal_kqueue (line 235) | static int
  function eloop_event_kqueue (line 263) | static int
  function eloop_event_epoll (line 300) | static int
  function eloop_event_add (line 322) | int
  function eloop_event_delete (line 380) | int
  function eloop_timespec_diff (line 426) | unsigned long long
  function eloop_reduce_timers (line 461) | static int
  function eloop_q_timeout_add (line 502) | static int
  function eloop_q_timeout_add_tv (line 551) | int
  function eloop_q_timeout_add_sec (line 568) | int
  function eloop_q_timeout_add_msec (line 575) | int
  function eloop_q_timeout_delete (line 592) | int
  function eloop_exit (line 611) | void
  function eloop_open (line 619) | static int
  function eloop_clear (line 653) | static void
  function eloop_forked (line 695) | int
  function eloop_signal_set_cb (line 741) | int
  function eloop_signal3 (line 767) | static void
  function eloop_signal_mask (line 784) | int
  type eloop (line 814) | struct eloop
  type eloop (line 817) | struct eloop
  function eloop_free (line 845) | void
  function eloop_pollevents (line 860) | static unsigned short
  function eloop_waitfd (line 878) | int
  function eloop_run_kqueue (line 893) | static int
  function eloop_run_epoll (line 942) | static int
  function eloop_run_ppoll (line 1001) | static int
  function eloop_start (line 1034) | int

FILE: src/eloop.h
  type eloop (line 53) | struct eloop
  type eloop (line 69) | struct eloop
  type eloop (line 70) | struct eloop
  type eloop (line 72) | struct eloop
  type timespec (line 74) | struct timespec
  type timespec (line 75) | struct timespec
  type eloop (line 84) | struct eloop
  type timespec (line 84) | struct timespec
  type eloop (line 86) | struct eloop
  type eloop (line 88) | struct eloop
  type eloop (line 90) | struct eloop
  type eloop (line 92) | struct eloop
  type eloop (line 94) | struct eloop
  type eloop (line 96) | struct eloop
  type eloop (line 97) | struct eloop
  type eloop (line 98) | struct eloop
  type eloop (line 99) | struct eloop
  type eloop (line 101) | struct eloop

FILE: src/if-bsd.c
  type rtm (line 113) | struct rtm {
  function os_init (line 118) | int
  function if_init (line 124) | int
  function if_conf (line 131) | int
  function if_opensockets_os (line 138) | int
  function if_closesockets_os (line 238) | void
  function if_ioctllink (line 265) | static int
  function if_setmac (line 279) | int
  function if_ignore1 (line 316) | static bool
  function if_ignoregroup (line 329) | int
  function if_ignore (line 357) | bool
  function if_indirect_ioctl (line 382) | static int
  function if_carrier (line 400) | int
  function if_roaming (line 426) | bool
  function if_linkaddr (line 440) | static void
  function if_getssid1 (line 450) | static int
  function if_getssid (line 498) | int
  function if_vimaster (line 519) | int
  function if_vlanid (line 537) | unsigned short
  function get_addrs (line 560) | static int
  type interface (line 584) | struct interface
  type dhcpcd_ctx (line 585) | struct dhcpcd_ctx
  type sockaddr_dl (line 585) | struct sockaddr_dl
  type interface (line 598) | struct interface
  type interface (line 612) | struct interface
  type dhcpcd_ctx (line 613) | struct dhcpcd_ctx
  type sockaddr (line 613) | struct sockaddr
  type sockaddr_dl (line 622) | struct sockaddr_dl
  type sockaddr_in (line 629) | struct sockaddr_in
  type ipv4_addr (line 630) | struct ipv4_addr
  type sockaddr_in6 (line 642) | struct sockaddr_in6
  type ipv6_addr (line 644) | struct ipv6_addr
  function if_copysa (line 666) | static void
  function if_route (line 684) | int
  function if_realroute (line 832) | static bool
  function if_copyrt (line 854) | static int
  function if_sysctl (line 931) | static int
  function if_initrt (line 946) | int
  function if_address (line 999) | int
  function if_addrflags (line 1027) | int
  function if_ioctl6 (line 1053) | static int
  function if_address6 (line 1067) | int
  function if_addrflags6 (line 1166) | int
  function if_getlifetime6 (line 1187) | int
  function if_announce (line 1228) | static int
  function if_ifinfo (line 1246) | static int
  function if_rtm (line 1266) | static int
  function if_ifa (line 1315) | static int
  function if_dispatch (line 1538) | static int
  function if_missfilter0 (line 1573) | static int
  function if_missfilter (line 1611) | int
  function if_missfilter_apply (line 1617) | int
  type rt_msghdr (line 1641) | struct rt_msghdr
  function if_handlelink (line 1642) | int
  function if_machinearch (line 1678) | int
  function inet6_sysctl (line 1690) | static int
  function if_applyra (line 1709) | int
  function if_af_attach (line 1760) | static int
  function if_set_ifxflags (line 1771) | static int
  function if_disable_rtadv (line 1818) | void
  function if_setup_inet6 (line 1834) | void

FILE: src/if-linux-wext.c
  function if_getssid_wext (line 65) | int

FILE: src/if-linux.c
  type interface (line 173) | struct interface
  type in_addr (line 173) | struct in_addr
  function if_machinearch (line 182) | int
  function if_machinearch (line 228) | int
  function check_proc_int (line 256) | static int
  function check_proc_uint (line 272) | static int
  function if_writepathuint (line 288) | static ssize_t
  function if_init (line 300) | int
  function if_conf (line 322) | int
  function if_bridge (line 338) | static bool
  function if_tap (line 349) | static bool
  function if_ignore (line 361) | bool
  function if_vimaster (line 370) | int
  function if_vlanid (line 376) | unsigned short
  function if_linksocket (line 389) | int
  type stat (line 408) | struct stat
  type dirent (line 410) | struct dirent
  function os_init (line 435) | int
  function if_opensockets_os (line 447) | int
  function if_closesockets_os (line 510) | void
  function if_setmac (line 531) | int
  function if_carrier (line 571) | int
  function if_roaming (line 577) | bool
  function if_getnetlink (line 598) | int
  function if_copyrt (line 674) | static int
  function link_route (line 822) | static int
  function link_addr (line 864) | static int
  function l2addr_len (line 992) | static uint8_t
  function link_neigh (line 1011) | static int
  function link_netlink (line 1049) | static int
  function if_handlelink (line 1162) | int
  function if_netlinkpriv (line 1176) | static bool
  function if_sendnetlink (line 1195) | static int
  function add_attr_l (line 1257) | static int
  function add_attr_8 (line 1280) | static int
  function add_attr_32 (line 1288) | static int
  function rta_add_attr_32 (line 1309) | static int
  type nlattr (line 1330) | struct nlattr
  type nlattr (line 1331) | struct nlattr
  type nlmg (line 1347) | struct nlmg {
  function nla_put_32 (line 1353) | static int
  function nla_put_string (line 1375) | static int
  function nla_parse (line 1397) | static int
  function genl_parse (line 1415) | static int
  function _gnl_getfamily (line 1428) | static int
  function gnl_getfamily (line 1445) | static int
  function _if_getssid_nl80211 (line 1463) | static int
  function if_getssid_nl80211 (line 1515) | static int
  function if_getssid (line 1551) | int
  type nlma (line 1570) | struct nlma {
  type ifiaddr (line 1577) | struct ifiaddr {
  function _if_addressexists (line 1583) | static int
  function if_addressexists (line 1613) | static int
  type nlmr (line 1637) | struct nlmr {
  function if_route (line 1643) | int
  function _if_initrt (line 1776) | static int
  function if_initrt (line 1794) | int
  function if_address (line 1810) | int
  function if_addrflags (line 1864) | int
  function if_address6 (line 1874) | int
  type ifiaddr6 (line 1936) | struct ifiaddr6 {
  function _if_addrflags6 (line 1943) | static int
  function if_addrflags6 (line 1990) | int
  function if_getlifetime6 (line 2018) | int
  type nlml (line 2026) | struct nlml {
  type rtattr (line 2033) | struct rtattr
  type nlmsghdr (line 2034) | struct nlmsghdr
  type rtattr (line 2036) | struct rtattr
  function add_attr_nest_end (line 2043) | static void
  function if_disable_autolinklocal (line 2050) | static int
  function if_setup_inet6 (line 2082) | void
  function if_applyra (line 2127) | int

FILE: src/if-options.c
  type option (line 66) | struct option
  function parse_str (line 260) | static ssize_t
  function parse_iaid1 (line 388) | static int
  function parse_iaid (line 414) | static int
  function parse_uint32 (line 421) | static int
  function parse_addr (line 461) | static int
  function parse_addr (line 497) | static int
  function set_option_space (line 506) | static void
  function free_dhcp_opt_embenc (line 563) | void
  function parse_option (line 633) | static int
  function parse_config_line (line 2569) | static int
  function finish_config (line 2594) | static void
  type if_options (line 2623) | struct if_options
  type dhcpcd_ctx (line 2624) | struct dhcpcd_ctx
  type if_options (line 2626) | struct if_options
  type if_options (line 2659) | struct if_options
  type dhcpcd_ctx (line 2660) | struct dhcpcd_ctx
  type if_options (line 2663) | struct if_options
  type dhcp_opt (line 2671) | struct dhcp_opt
  type dhcp_opt (line 2673) | struct dhcp_opt
  function add_options (line 2930) | int
  function free_options (line 3005) | void

FILE: src/if-options.h
  type option (line 195) | struct option
  type if_sla (line 197) | struct if_sla {
  type if_ia (line 205) | struct if_ia {
  type vivco (line 221) | struct vivco {
  type vsio_so (line 226) | struct vsio_so {
  type vsio (line 231) | struct vsio {
  type if_options (line 238) | struct if_options {
  type if_options (line 319) | struct if_options
  type dhcpcd_ctx (line 319) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 321) | struct dhcpcd_ctx
  type if_options (line 321) | struct if_options
  type dhcp_opt (line 323) | struct dhcp_opt
  type dhcpcd_ctx (line 324) | struct dhcpcd_ctx
  type if_options (line 324) | struct if_options

FILE: src/if-sun.c
  type ifaddrs (line 61) | struct ifaddrs
  type rtm (line 104) | struct rtm {
  type dhcpcd_ctx (line 109) | struct dhcpcd_ctx
  function os_init (line 111) | int
  function if_init (line 117) | int
  function if_conf (line 138) | int
  function if_opensockets_os (line 144) | int
  function if_closesockets_os (line 180) | void
  function if_setmac (line 196) | int
  function if_carrier (line 203) | int
  function if_roaming (line 243) | bool
  function if_mtu_os (line 249) | int
  function if_getssid (line 266) | int
  function if_ignore (line 274) | bool
  function if_vlanid (line 280) | unsigned short
  function if_vimaster (line 286) | int
  function if_machinearch (line 292) | int
  type linkwalk (line 300) | struct linkwalk {
  function boolean_t (line 305) | static boolean_t
  type ifaddrs (line 377) | struct ifaddrs
  type ifaddrs (line 380) | struct ifaddrs
  type sockaddr_dl (line 381) | struct sockaddr_dl
  type sockaddr (line 395) | struct sockaddr
  function if_getifaddrs (line 406) | int
  function if_linkaddr (line 437) | static void
  function get_addrs (line 446) | static int
  type interface (line 470) | struct interface
  type dhcpcd_ctx (line 471) | struct dhcpcd_ctx
  type sockaddr_dl (line 471) | struct sockaddr_dl
  type interface (line 484) | struct interface
  type interface (line 498) | struct interface
  type dhcpcd_ctx (line 499) | struct dhcpcd_ctx
  type sockaddr (line 499) | struct sockaddr
  type sockaddr_dl (line 508) | struct sockaddr_dl
  type sockaddr_in (line 515) | struct sockaddr_in
  type ipv4_addr (line 516) | struct ipv4_addr
  type sockaddr_in6 (line 528) | struct sockaddr_in6
  type ipv6_addr (line 529) | struct ipv6_addr
  function if_route0 (line 548) | static void
  function if_route (line 638) | int
  function if_copyrt (line 651) | static int
  type rt (line 710) | struct rt
  type dhcpcd_ctx (line 711) | struct dhcpcd_ctx
  type rt (line 711) | struct rt
  type rtm (line 713) | struct rtm
  type iovec (line 715) | struct iovec
  type msghdr (line 716) | struct msghdr
  type rt (line 718) | struct rt
  function if_finishrt (line 742) | static int
  function if_addrflags0 (line 801) | static int
  function if_rtm (line 821) | static int
  function if_getalias (line 860) | static bool
  function if_getbrdaddr (line 888) | static int
  function if_ifa (line 903) | static int
  function if_ifinfo (line 1033) | static int
  function if_dispatch (line 1059) | static int
  function if_handlelink (line 1082) | int
  function if_octetstr (line 1110) | static void
  function if_setflags (line 1126) | static int
  function if_addaddr (line 1142) | static int
  function if_getaf_fd (line 1178) | static int
  function if_getsubnet (line 1194) | int
  function if_plumblif (line 1210) | static int
  function if_plumbif (line 1227) | static int
  function if_unplumbif (line 1338) | static int
  function if_plumb (line 1351) | static int
  function if_walkrt (line 1367) | static int
  function if_walkrt6 (line 1425) | static int
  function if_parsert (line 1479) | static int
  function if_initrt (line 1574) | int
  function if_address (line 1591) | int
  function if_addrflags (line 1622) | int
  function if_address6 (line 1632) | int
  function if_addrflags6 (line 1675) | int
  function if_getlifetime6 (line 1685) | int
  function if_applyra (line 1693) | int
  function if_setup_inet6 (line 1706) | void

FILE: src/if.c
  function if_free (line 81) | void
  function if_opensockets (line 106) | int
  function if_closesockets (line 130) | void
  function if_ioctl (line 147) | int
  function if_setflag (line 157) | int
  function if_is_link_up (line 182) | bool
  function if_randomisemac (line 191) | int
  function if_hasconf (line 231) | static int
  function if_markaddrsstale (line 243) | void
  function if_learnaddrs (line 258) | void
  function if_freeifaddrs (line 350) | void
  function if_deletestaleaddrs (line 368) | void
  function if_valid_hwaddr (line 383) | bool
  function if_check_arphrd (line 402) | static unsigned int
  type if_head (line 439) | struct if_head
  type dhcpcd_ctx (line 440) | struct dhcpcd_ctx
  type ifaddrs (line 440) | struct ifaddrs
  type ifaddrs (line 443) | struct ifaddrs
  type if_head (line 446) | struct if_head
  type interface (line 447) | struct interface
  type if_spec (line 448) | struct if_spec
  type sockaddr_dl (line 451) | struct sockaddr_dl
  type if_laddrreq (line 453) | struct if_laddrreq
  type sockaddr_ll (line 456) | struct sockaddr_ll
  type ifreq (line 459) | struct ifreq
  type ifreq (line 665) | struct ifreq
  function if_nametospec (line 726) | int
  type interface (line 797) | struct interface
  type if_head (line 798) | struct if_head
  type if_spec (line 801) | struct if_spec
  type interface (line 802) | struct interface
  type interface (line 818) | struct interface
  type if_head (line 819) | struct if_head
  type interface (line 824) | struct interface
  type if_head (line 825) | struct if_head
  type interface (line 830) | struct interface
  type dhcpcd_ctx (line 831) | struct dhcpcd_ctx
  type interface (line 833) | struct interface
  function if_getmtu (line 842) | int
  function if_makealias (line 858) | int
  type interface (line 867) | struct interface
  type dhcpcd_ctx (line 868) | struct dhcpcd_ctx
  type msghdr (line 868) | struct msghdr
  type cmsghdr (line 870) | struct cmsghdr
  type interface (line 872) | struct interface
  type sockaddr_dl (line 875) | struct sockaddr_dl
  type in_pktinfo (line 877) | struct in_pktinfo
  type in6_pktinfo (line 881) | struct in6_pktinfo
  type cmsghdr (line 886) | struct cmsghdr
  type cmsghdr (line 887) | struct cmsghdr
  type sockaddr_dl (line 894) | struct sockaddr_dl
  function xsocket (line 943) | int
  function xsocketpair (line 989) | int

FILE: src/if.h
  type IOCTL_REQUEST_TYPE (line 66) | typedef IOCTL_REQUEST_TYPE ioctl_request_t;
  type ioctl_request_t (line 68) | typedef unsigned long ioctl_request_t;
  type priv (line 127) | struct priv {
  type priv (line 137) | struct priv {
  type priv (line 144) | struct priv {
  type ifaddrs (line 154) | struct ifaddrs
  type ifaddrs (line 155) | struct ifaddrs
  type dhcpcd_ctx (line 157) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 160) | struct dhcpcd_ctx
  type interface (line 167) | struct interface
  type interface (line 168) | struct interface
  type interface (line 171) | struct interface
  type if_head (line 173) | struct if_head
  type dhcpcd_ctx (line 173) | struct dhcpcd_ctx
  type ifaddrs (line 173) | struct ifaddrs
  type dhcpcd_ctx (line 175) | struct dhcpcd_ctx
  type ifaddrs (line 175) | struct ifaddrs
  type if_head (line 176) | struct if_head
  type dhcpcd_ctx (line 177) | struct dhcpcd_ctx
  type if_head (line 177) | struct if_head
  type ifaddrs (line 177) | struct ifaddrs
  type if_head (line 178) | struct if_head
  type interface (line 179) | struct interface
  type if_head (line 179) | struct if_head
  type interface (line 180) | struct interface
  type if_head (line 180) | struct if_head
  type interface (line 181) | struct interface
  type dhcpcd_ctx (line 181) | struct dhcpcd_ctx
  type interface (line 182) | struct interface
  type interface (line 183) | struct interface
  type interface (line 184) | struct interface
  type interface (line 190) | struct interface
  type if_spec (line 197) | struct if_spec {
  type if_spec (line 205) | struct if_spec
  type interface (line 209) | struct interface
  type interface (line 210) | struct interface
  type interface (line 211) | struct interface
  type dhcpcd_ctx (line 213) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 214) | struct dhcpcd_ctx
  type interface (line 215) | struct interface
  type dhcpcd_ctx (line 217) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 218) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 219) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 220) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 221) | struct dhcpcd_ctx
  type interface (line 222) | struct interface
  type interface (line 223) | struct interface
  type rt (line 253) | struct rt
  type dhcpcd_ctx (line 254) | struct dhcpcd_ctx
  type interface (line 256) | struct interface
  type sockaddr (line 256) | struct sockaddr
  type dhcpcd_ctx (line 257) | struct dhcpcd_ctx
  type ipv4_addr (line 260) | struct ipv4_addr
  type interface (line 261) | struct interface
  type in_addr (line 261) | struct in_addr
  type interface (line 268) | struct interface
  type ra (line 271) | struct ra
  type ipv6_addr (line 272) | struct ipv6_addr
  type ra (line 274) | struct ra
  type ipv6_addr (line 275) | struct ipv6_addr
  type interface (line 276) | struct interface
  type in6_addr (line 276) | struct in6_addr
  type ipv6_addr (line 278) | struct ipv6_addr
  type interface (line 285) | struct interface
  type dhcpcd_ctx (line 285) | struct dhcpcd_ctx
  type msghdr (line 285) | struct msghdr
  type sockaddr_nl (line 289) | struct sockaddr_nl
  type dhcpcd_ctx (line 290) | struct dhcpcd_ctx
  type iovec (line 290) | struct iovec
  type dhcpcd_ctx (line 291) | struct dhcpcd_ctx
  type nlmsghdr (line 291) | struct nlmsghdr

FILE: src/ipv4.c
  function inet_ntocidr (line 69) | uint8_t
  function inet_cidrtoaddr (line 82) | int
  function ipv4_getnetmask (line 103) | uint32_t
  type ipv4_addr (line 122) | struct ipv4_addr
  type interface (line 123) | struct interface
  type in_addr (line 123) | struct in_addr
  type in_addr (line 124) | struct in_addr
  type ipv4_state (line 126) | struct ipv4_state
  type ipv4_addr (line 127) | struct ipv4_addr
  type ipv4_addr (line 140) | struct ipv4_addr
  type interface (line 141) | struct interface
  type ipv4_state (line 143) | struct ipv4_state
  type ipv4_addr (line 144) | struct ipv4_addr
  type ipv4_addr (line 156) | struct ipv4_addr
  type interface (line 157) | struct interface
  type in_addr (line 157) | struct in_addr
  type ipv4_state (line 159) | struct ipv4_state
  type ipv4_addr (line 160) | struct ipv4_addr
  type ipv4_addr (line 173) | struct ipv4_addr
  type interface (line 174) | struct interface
  type in_addr (line 174) | struct in_addr
  type ipv4_state (line 176) | struct ipv4_state
  type ipv4_addr (line 177) | struct ipv4_addr
  type ipv4_addr (line 190) | struct ipv4_addr
  type dhcpcd_ctx (line 191) | struct dhcpcd_ctx
  type in_addr (line 191) | struct in_addr
  type interface (line 193) | struct interface
  type ipv4_addr (line 194) | struct ipv4_addr
  type ipv4_addr (line 204) | struct ipv4_addr
  type dhcpcd_ctx (line 205) | struct dhcpcd_ctx
  type in_addr (line 205) | struct in_addr
  type interface (line 207) | struct interface
  type ipv4_addr (line 208) | struct ipv4_addr
  type ipv4_addr (line 218) | struct ipv4_addr
  type dhcpcd_ctx (line 219) | struct dhcpcd_ctx
  type in_addr (line 219) | struct in_addr
  type interface (line 221) | struct interface
  type ipv4_addr (line 222) | struct ipv4_addr
  function ipv4_hasaddr (line 232) | int
  function ipv4_ifcmp (line 247) | int
  function inet_dhcproutes (line 281) | static int
  function inet_routerhostroute (line 377) | static int
  function inet_getroutes (line 486) | bool
  function ipv4_deladdr (line 519) | int
  type ipv4_state (line 561) | struct ipv4_state
  type interface (line 562) | struct interface
  type ipv4_state (line 564) | struct ipv4_state
  function ipv4_aliasaddr (line 581) | static int
  type ipv4_addr (line 626) | struct ipv4_addr
  type interface (line 627) | struct interface
  type in_addr (line 627) | struct in_addr
  type in_addr (line 628) | struct in_addr
  type in_addr (line 628) | struct in_addr
  type ipv4_state (line 631) | struct ipv4_state
  type ipv4_addr (line 632) | struct ipv4_addr
  type ipv4_addr (line 635) | struct ipv4_addr
  type ipv4_addr (line 643) | struct ipv4_addr
  function ipv4_daddaddr (line 723) | static int
  type ipv4_addr (line 740) | struct ipv4_addr
  type interface (line 743) | struct interface
  type dhcp_state (line 744) | struct dhcp_state
  type dhcp_lease (line 745) | struct dhcp_lease
  type if_options (line 746) | struct if_options
  type ipv4_addr (line 747) | struct ipv4_addr
  function ipv4_markaddrsstale (line 826) | void
  function ipv4_deletestaleaddrs (line 841) | void
  function ipv4_handleifa (line 859) | void
  function ipv4_free (line 955) | void

FILE: src/ipv4.h
  type ipv4_addr (line 87) | struct ipv4_addr {
  type ipv4_state (line 115) | struct ipv4_state {
  type ipv4_state (line 124) | struct ipv4_state
  type interface (line 124) | struct interface
  type interface (line 125) | struct interface
  type interface (line 125) | struct interface
  type in_addr (line 126) | struct in_addr
  type in_addr (line 127) | struct in_addr
  type interface (line 129) | struct interface
  type dhcpcd_ctx (line 131) | struct dhcpcd_ctx
  type ipv4_addr (line 137) | struct ipv4_addr
  type ipv4_addr (line 138) | struct ipv4_addr
  type interface (line 138) | struct interface
  type in_addr (line 138) | struct in_addr
  type in_addr (line 139) | struct in_addr
  type in_addr (line 139) | struct in_addr
  type ipv4_addr (line 140) | struct ipv4_addr
  type ipv4_addr (line 142) | struct ipv4_addr
  type interface (line 142) | struct interface
  type in_addr (line 142) | struct in_addr
  type in_addr (line 143) | struct in_addr
  type ipv4_addr (line 144) | struct ipv4_addr
  type interface (line 144) | struct interface
  type ipv4_addr (line 145) | struct ipv4_addr
  type dhcpcd_ctx (line 145) | struct dhcpcd_ctx
  type in_addr (line 145) | struct in_addr
  type ipv4_addr (line 146) | struct ipv4_addr
  type dhcpcd_ctx (line 146) | struct dhcpcd_ctx
  type in_addr (line 147) | struct in_addr
  type ipv4_addr (line 148) | struct ipv4_addr
  type dhcpcd_ctx (line 148) | struct dhcpcd_ctx
  type in_addr (line 148) | struct in_addr
  type interface (line 149) | struct interface
  type interface (line 150) | struct interface
  type dhcpcd_ctx (line 151) | struct dhcpcd_ctx
  type if_head (line 151) | struct if_head
  type in_addr (line 152) | struct in_addr
  type in_addr (line 152) | struct in_addr
  type in_addr (line 152) | struct in_addr
  type interface (line 155) | struct interface

FILE: src/ipv4ll.c
  type in_addr (line 54) | struct in_addr
  type in_addr (line 55) | struct in_addr
  function ipv4ll_pickaddr (line 58) | static void
  function ipv4ll_subnetroute (line 90) | int
  function ipv4ll_defaultroute (line 115) | int
  function ipv4ll_env (line 141) | ssize_t
  function ipv4ll_announced_arp (line 173) | static void
  function ipv4ll_free_arp (line 182) | static void
  function ipv4ll_freearp (line 193) | static void
  function ipv4ll_not_found (line 210) | static void
  function ipv4ll_found (line 262) | static void
  function ipv4ll_defend_failed (line 277) | static void
  function ipv4ll_not_found_arp (line 293) | static void
  function ipv4ll_found_arp (line 299) | static void
  function ipv4ll_defend_failed_arp (line 305) | static void
  function ipv4ll_start (line 312) | void
  function ipv4ll_start_arp (line 406) | static void
  function ipv4ll_drop (line 432) | void
  function ipv4ll_reset (line 481) | void
  function ipv4ll_free (line 493) | void
  function ipv4ll_recvrt (line 506) | int
  type ipv4_addr (line 529) | struct ipv4_addr
  type ipv4_addr (line 530) | struct ipv4_addr
  type interface (line 532) | struct interface
  type ipv4ll_state (line 533) | struct ipv4ll_state

FILE: src/ipv4ll.h
  type ipv4ll_state (line 43) | struct ipv4ll_state {
  type interface (line 64) | struct interface
  type interface (line 65) | struct interface
  type interface (line 66) | struct interface
  type ipv4_addr (line 70) | struct ipv4_addr
  type ipv4_addr (line 70) | struct ipv4_addr
  type rt (line 72) | struct rt
  type interface (line 75) | struct interface
  type interface (line 76) | struct interface
  type interface (line 77) | struct interface

FILE: src/ipv6.c
  function ipv6_init (line 128) | int
  function ipv6_readsecret (line 149) | static ssize_t
  type reslowhigh (line 198) | struct reslowhigh {
  function ipv6_reserved (line 210) | static bool
  function ipv6_makehwaddr (line 230) | static int
  function ipv6_makestableprivate1 (line 273) | static int
  function ipv6_makestableprivate (line 350) | int
  function ipv6_maketemporaryaddress (line 371) | static int
  function ipv6_makeprefix (line 398) | static int
  function ipv6_mask (line 412) | int
  function ipv6_prefixlen (line 438) | uint8_t
  function ipv6_makeaddr (line 472) | int
  function in6_to_h64 (line 541) | static void
  function h64_to_in6 (line 548) | static void
  function ipv6_userprefix (line 555) | int
  function ipv6_checkaddrflags (line 616) | void
  function ipv6_deletedaddr (line 648) | static void
  function ipv6_deleteaddr (line 671) | void
  type ipv6_state (line 694) | struct ipv6_state
  type interface (line 695) | struct interface
  type ipv6_state (line 697) | struct ipv6_state
  function ipv6_addaddr1 (line 713) | static int
  function ipv6_aliasaddr (line 832) | static int
  function ipv6_addaddr (line 890) | int
  function ipv6_findaddrmatch (line 919) | int
  type ipv6_addr (line 935) | struct ipv6_addr
  type dhcpcd_ctx (line 936) | struct dhcpcd_ctx
  type in6_addr (line 936) | struct in6_addr
  type ipv6_addr (line 939) | struct ipv6_addr
  type ipv6_addr (line 941) | struct ipv6_addr
  function ipv6_doaddr (line 961) | int
  function ipv6_addaddrs (line 987) | ssize_t
  function ipv6_freeaddr (line 1008) | void
  function ipv6_freedrop_addrs (line 1035) | void
  type ipv6_addr (line 1084) | struct ipv6_addr
  type interface (line 1085) | struct interface
  type ipv6_state (line 1087) | struct ipv6_state
  type ipv6_addr (line 1088) | struct ipv6_addr
  type ipv6_addr (line 1108) | struct ipv6_addr
  type interface (line 1109) | struct interface
  type ipv6_addr (line 1111) | struct ipv6_addr
  type interface (line 1112) | struct interface
  function ipv6_handleifa (line 1133) | void
  function ipv6_hasaddr (line 1291) | int
  type ipv6_addr (line 1303) | struct ipv6_addr
  type interface (line 1304) | struct interface
  type in6_addr (line 1304) | struct in6_addr
  type ipv6_state (line 1307) | struct ipv6_state
  type ipv6_addr (line 1308) | struct ipv6_addr
  type ipv6_addr (line 1329) | struct ipv6_addr
  type interface (line 1330) | struct interface
  type in6_addr (line 1330) | struct in6_addr
  type ipv6_state (line 1332) | struct ipv6_state
  type ipv6_addr (line 1333) | struct ipv6_addr
  type in6_addr (line 1334) | struct in6_addr
  type ipv6_addr (line 1348) | struct ipv6_addr
  type dhcpcd_ctx (line 1349) | struct dhcpcd_ctx
  type in6_addr (line 1349) | struct in6_addr
  type interface (line 1351) | struct interface
  type ipv6_addr (line 1352) | struct ipv6_addr
  type ipv6_addr (line 1362) | struct ipv6_addr
  type interface (line 1363) | struct interface
  type in6_addr (line 1363) | struct in6_addr
  type ipv6_state (line 1365) | struct ipv6_state
  type ipv6_addr (line 1366) | struct ipv6_addr
  type ipv6_addr (line 1378) | struct ipv6_addr
  type dhcpcd_ctx (line 1379) | struct dhcpcd_ctx
  type in6_addr (line 1379) | struct in6_addr
  type interface (line 1381) | struct interface
  type ipv6_addr (line 1382) | struct ipv6_addr
  function ipv6_addlinklocalcallback (line 1392) | int
  type ipv6_addr (line 1416) | struct ipv6_addr
  type interface (line 1417) | struct interface
  type ipv6_addr (line 1419) | struct ipv6_addr
  type in6_addr (line 1420) | struct in6_addr
  function ipv6_addlinklocal (line 1436) | static int
  function ipv6_tryaddlinklocal (line 1518) | static int
  function ipv6_setscope (line 1544) | void
  function ipv6_getscope (line 1563) | unsigned int
  type ipv6_addr (line 1580) | struct ipv6_addr
  type interface (line 1581) | struct interface
  type in6_addr (line 1581) | struct in6_addr
  type ipv6_addr (line 1584) | struct ipv6_addr
  function ipv6_staticdadcallback (line 1664) | static void
  function ipv6_env (line 1698) | ssize_t
  function ipv6_staticdadcompleted (line 1712) | int
  function ipv6_startstatic (line 1731) | int
  function ipv6_start (line 1771) | int
  function ipv6_freedrop (line 1802) | void
  function ipv6_ctxfree (line 1833) | void
  function ipv6_handleifa_addrs (line 1840) | int
  function ipv6_regen_desync (line 1894) | static void
  function ipv6_tempdadcallback (line 1917) | static void
  type ipv6_addr (line 1942) | struct ipv6_addr
  type ipv6_addr (line 1943) | struct ipv6_addr
  type timespec (line 1943) | struct timespec
  type ipv6_state (line 1945) | struct ipv6_state
  type interface (line 1946) | struct interface
  type ipv6_addr (line 1947) | struct ipv6_addr
  type ipv6_addr (line 1976) | struct ipv6_addr
  type ipv6_addr (line 1977) | struct ipv6_addr
  type ipv6_state (line 1979) | struct ipv6_state
  type ipv6_addr (line 1980) | struct ipv6_addr
  function ipv6_addtempaddrs (line 2053) | void
  function ipv6_regentempaddr0 (line 2067) | static void
  function ipv6_regentempaddr (line 2080) | static void
  function ipv6_regentempaddrs (line 2089) | void
  function ipv6_markaddrsstale (line 2124) | void
  function ipv6_deletestaleaddrs (line 2140) | void
  type rt (line 2158) | struct rt
  type interface (line 2159) | struct interface
  type ra (line 2159) | struct ra
  type rt (line 2161) | struct rt
  type rt (line 2174) | struct rt
  type interface (line 2175) | struct interface
  type ra (line 2175) | struct ra
  type ipv6_addr (line 2176) | struct ipv6_addr
  type rt (line 2178) | struct rt
  type in6_addr (line 2179) | struct in6_addr
  type interface (line 2198) | struct interface
  type rt (line 2231) | struct rt
  type ra (line 2232) | struct ra
  type rt (line 2234) | struct rt
  function inet6_staticroutes (line 2248) | static int
  function inet6_raroutes (line 2271) | static int
  function inet6_dhcproutes (line 2367) | static int
  function inet6_getroutes (line 2406) | bool

FILE: src/ipv6.h
  type ipv6_addr (line 174) | struct ipv6_addr {
  type ll_callback (line 234) | struct ll_callback {
  type ipv6_state (line 241) | struct ipv6_state {
  type dhcpcd_ctx (line 255) | struct dhcpcd_ctx
  type in6_addr (line 256) | struct in6_addr
  type in6_addr (line 256) | struct in6_addr
  type interface (line 257) | struct interface
  type in6_addr (line 258) | struct in6_addr
  type interface (line 258) | struct interface
  type in6_addr (line 259) | struct in6_addr
  type in6_addr (line 260) | struct in6_addr
  type in6_addr (line 261) | struct in6_addr
  type in6_addr (line 262) | struct in6_addr
  type in6_addr (line 263) | struct in6_addr
  type interface (line 265) | struct interface
  type interface (line 266) | struct interface
  type ipv6_addr (line 267) | struct ipv6_addr
  type timespec (line 267) | struct timespec
  type ipv6_addr (line 268) | struct ipv6_addr
  type timespec (line 268) | struct timespec
  type ipv6_addrhead (line 269) | struct ipv6_addrhead
  type ipv6_addr (line 270) | struct ipv6_addr
  type ipv6_addrhead (line 271) | struct ipv6_addrhead
  type interface (line 272) | struct interface
  type dhcpcd_ctx (line 273) | struct dhcpcd_ctx
  type if_head (line 273) | struct if_head
  type in6_addr (line 274) | struct in6_addr
  type in6_addr (line 274) | struct in6_addr
  type ipv6_addrhead (line 275) | struct ipv6_addrhead
  type ipv6_addr (line 275) | struct ipv6_addr
  type ipv6_addr (line 277) | struct ipv6_addr
  type interface (line 277) | struct interface
  type in6_addr (line 277) | struct in6_addr
  type interface (line 279) | struct interface
  type ipv6_addr (line 280) | struct ipv6_addr
  type interface (line 280) | struct interface
  type ipv6_addr (line 281) | struct ipv6_addr
  type in6_addr (line 281) | struct in6_addr
  type ipv6_addr (line 283) | struct ipv6_addr
  type dhcpcd_ctx (line 283) | struct dhcpcd_ctx
  type in6_addr (line 283) | struct in6_addr
  type ipv6_addr (line 285) | struct ipv6_addr
  type dhcpcd_ctx (line 285) | struct dhcpcd_ctx
  type in6_addr (line 286) | struct in6_addr
  type ipv6_addr (line 287) | struct ipv6_addr
  type dhcpcd_ctx (line 287) | struct dhcpcd_ctx
  type in6_addr (line 288) | struct in6_addr
  type interface (line 290) | struct interface
  type sockaddr_in6 (line 291) | struct sockaddr_in6
  type sockaddr_in6 (line 292) | struct sockaddr_in6
  type ipv6_addr (line 293) | struct ipv6_addr
  type interface (line 293) | struct interface
  type in6_addr (line 293) | struct in6_addr
  type ipv6_addr (line 295) | struct ipv6_addr
  type interface (line 296) | struct interface
  type ipv6_addr (line 301) | struct ipv6_addr
  type ipv6_addr (line 301) | struct ipv6_addr
  type timespec (line 302) | struct timespec
  type ipv6_addr (line 303) | struct ipv6_addr
  type ipv6_addr (line 303) | struct ipv6_addr
  type interface (line 304) | struct interface
  type timespec (line 304) | struct timespec
  type interface (line 308) | struct interface
  type interface (line 309) | struct interface
  type interface (line 310) | struct interface
  type interface (line 311) | struct interface
  type dhcpcd_ctx (line 312) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 313) | struct dhcpcd_ctx

FILE: src/ipv6nd.c
  type nd_opt_ri (line 77) | struct nd_opt_ri { /* Route Information option RFC4191 */
  type nd_opt_ri (line 85) | struct nd_opt_ri
  type nd_opt_rdnss (line 91) | struct nd_opt_rdnss { /* RDNSS option RFC 6106 */
  type nd_opt_rdnss (line 98) | struct nd_opt_rdnss
  type nd_opt_dnssl (line 103) | struct nd_opt_dnssl { /* DNSSL option RFC 6106 */
  type nd_opt_dnssl (line 110) | struct nd_opt_dnssl
  type routeinfo (line 151) | struct routeinfo
  type ra (line 151) | struct ra
  type in6_addr (line 152) | struct in6_addr
  type routeinfohead (line 153) | struct routeinfohead
  function ipv6nd_printoptions (line 200) | void
  function ipv6nd_open (line 223) | int
  function ipv6nd_openif (line 274) | int
  function ipv6nd_makersprobe (line 315) | static int
  function ipv6nd_sendrsprobe (line 346) | static void
  function ipv6nd_expire (line 443) | static void
  function ipv6nd_startexpire (line 459) | void
  function ipv6nd_rtpref (line 475) | int
  function ipv6nd_sortrouters (line 493) | static void
  function ipv6nd_applyra (line 529) | static void
  function ipv6nd_neighbour (line 568) | void
  type ipv6_addr (line 608) | struct ipv6_addr
  type interface (line 609) | struct interface
  type in6_addr (line 609) | struct in6_addr
  type ra (line 612) | struct ra
  type ipv6_addr (line 613) | struct ipv6_addr
  type ipv6_addr (line 629) | struct ipv6_addr
  type dhcpcd_ctx (line 630) | struct dhcpcd_ctx
  type in6_addr (line 630) | struct in6_addr
  type ra (line 633) | struct ra
  type ipv6_addr (line 634) | struct ipv6_addr
  type ipv6_addr (line 648) | struct ipv6_addr
  type ra (line 649) | struct ra
  type in6_addr (line 649) | struct in6_addr
  type ipv6_addr (line 651) | struct ipv6_addr
  type ipv6_addr (line 663) | struct ipv6_addr
  type interface (line 664) | struct interface
  type in6_addr (line 664) | struct in6_addr
  type ra (line 667) | struct ra
  type ipv6_addr (line 668) | struct ipv6_addr
  function ipv6nd_removefreedrop_ra (line 681) | static void
  function ipv6nd_freedrop_ra (line 698) | static void
  function ipv6nd_free (line 704) | ssize_t
  function ipv6nd_scriptrun (line 751) | static void
  function ipv6nd_addaddr (line 797) | static void
  function ipv6nd_dadcompleted (line 805) | int
  function ipv6nd_dadcallback (line 824) | static void
  type ipv6_addr (line 912) | struct ipv6_addr
  type ra (line 913) | struct ra
  type ipv6_addr (line 913) | struct ipv6_addr
  type dhcpcd_ctx (line 915) | struct dhcpcd_ctx
  type ra (line 916) | struct ra
  type ipv6_addr (line 917) | struct ipv6_addr
  type DH6S (line 937) | enum DH6S {
  function dhcp6_start (line 941) | static int
  function ipv6nd_handlera (line 949) | static void
  function ipv6nd_hasralifetime (line 1500) | bool
  function ipv6nd_hasradhcp (line 1514) | bool
  type dhcpcd_ctx (line 1532) | struct dhcpcd_ctx
  type dhcp_opt (line 1533) | struct dhcp_opt
  type nd_opt_hdr (line 1535) | struct nd_opt_hdr
  type dhcp_opt (line 1537) | struct dhcp_opt
  function ipv6nd_env (line 1567) | ssize_t
  function ipv6nd_handleifa (line 1675) | void
  function ipv6nd_expirera (line 1692) | void
  function ipv6nd_drop (line 1872) | void
  function ipv6nd_recvmsg (line 1896) | void
  function ipv6nd_handledata (line 1938) | static void
  function ipv6nd_startrs2 (line 1993) | static void
  function ipv6nd_startrs1 (line 2026) | static void
  function ipv6nd_startrs (line 2043) | void
  function ipv6nd_abort (line 2055) | void
  type routeinfo (line 2063) | struct routeinfo
  type ra (line 2064) | struct ra
  type in6_addr (line 2064) | struct in6_addr
  type routeinfo (line 2067) | struct routeinfo
  type routeinfo (line 2077) | struct routeinfo
  function routeinfohead_free (line 2093) | static void

FILE: src/ipv6nd.h
  type routeinfo (line 41) | struct routeinfo {
  type ra (line 53) | struct ra {
  type rs_state (line 78) | struct rs_state {
  type interface (line 118) | struct interface
  type dhcpcd_ctx (line 120) | struct dhcpcd_ctx
  type msghdr (line 120) | struct msghdr
  type dhcpcd_ctx (line 122) | struct dhcpcd_ctx
  type dhcp_opt (line 122) | struct dhcp_opt
  type interface (line 124) | struct interface
  type interface (line 125) | struct interface
  type ipv6_addr (line 126) | struct ipv6_addr
  type interface (line 126) | struct interface
  type in6_addr (line 127) | struct in6_addr
  type ipv6_addr (line 128) | struct ipv6_addr
  type dhcpcd_ctx (line 128) | struct dhcpcd_ctx
  type in6_addr (line 128) | struct in6_addr
  type ipv6_addr (line 130) | struct ipv6_addr
  type interface (line 130) | struct interface
  type in6_addr (line 131) | struct in6_addr
  type interface (line 132) | struct interface
  type interface (line 134) | struct interface
  type interface (line 136) | struct interface
  type ipv6_addr (line 137) | struct ipv6_addr
  type interface (line 138) | struct interface
  type ipv6_addr (line 139) | struct ipv6_addr
  type interface (line 140) | struct interface
  type interface (line 141) | struct interface
  type dhcpcd_ctx (line 142) | struct dhcpcd_ctx
  type in6_addr (line 142) | struct in6_addr
  type interface (line 143) | struct interface

FILE: src/logerr.c
  type logctx (line 57) | struct logctx {
  type logctx (line 70) | struct logctx
  function logprintdate (line 108) | static int
  function vlogprintf_r (line 128) | static int vlogprintf_r(struct logctx *ctx, FILE *stream,
  function vlogmessage (line 212) | static int vlogmessage(int pri, const char *fmt,
  function logmessage (line 265) | void logmessage(int pri, const char *fmt, ...)
  function vlogerrmessage (line 274) | static void vlogerrmessage(int pri, const char *fmt,
  function logerrmessage (line 285) | void logerrmessage(int pri, const char *fmt, ...)
  function log_debug (line 294) | void
  function log_debugx (line 304) | void
  function log_info (line 314) | void
  function log_infox (line 324) | void
  function log_warn (line 334) | void
  function log_warnx (line 344) | void
  function log_err (line 354) | void
  function log_errx (line 364) | void
  function loggetfd (line 374) | int
  function logsetfd (line 382) | void
  function logreadfd (line 398) | ssize_t
  function loggetopts (line 444) | unsigned int
  function logsetopts (line 452) | void
  function logsettag (line 464) | void
  function logopen (line 477) | int
  function logclose (line 513) | void

FILE: src/privsep-bpf.c
  function ps_bpf_recvbpf (line 58) | static void
  function ps_bpf_recvmsgcb (line 105) | static ssize_t
  function ps_bpf_recvmsg (line 138) | static void
  function ps_bpf_start_bpf (line 148) | static int
  function ps_bpf_cmd (line 186) | ssize_t
  function ps_bpf_dispatch (line 279) | ssize_t
  function ps_bpf_send (line 321) | static ssize_t
  function ps_bpf_openarp (line 341) | ssize_t
  function ps_bpf_closearp (line 348) | ssize_t
  function ps_bpf_sendarp (line 354) | ssize_t
  function ps_bpf_openbootp (line 363) | ssize_t
  function ps_bpf_closebootp (line 370) | ssize_t
  function ps_bpf_sendbootp (line 376) | ssize_t

FILE: src/privsep-bpf.h
  type dhcpcd_ctx (line 32) | struct dhcpcd_ctx
  type ps_msghdr (line 32) | struct ps_msghdr
  type msghdr (line 32) | struct msghdr
  type dhcpcd_ctx (line 33) | struct dhcpcd_ctx
  type ps_msghdr (line 33) | struct ps_msghdr
  type msghdr (line 34) | struct msghdr
  type interface (line 37) | struct interface
  type in_addr (line 37) | struct in_addr
  type interface (line 38) | struct interface
  type in_addr (line 38) | struct in_addr
  type interface (line 39) | struct interface
  type in_addr (line 39) | struct in_addr
  type interface (line 43) | struct interface
  type interface (line 44) | struct interface
  type interface (line 45) | struct interface
  type interface (line 46) | struct interface
  type interface (line 47) | struct interface
  type interface (line 48) | struct interface

FILE: src/privsep-bsd.c
  function ps_root_doioctldom (line 66) | static ssize_t
  function ps_root_doroute (line 140) | static ssize_t
  function ps_root_doindirectioctl (line 147) | static ssize_t
  function ps_root_doifignoregroup (line 183) | static ssize_t
  function ps_root_dosysctl (line 196) | static ssize_t
  function ps_root_os (line 265) | ssize_t
  function ps_root_ioctldom (line 313) | static ssize_t
  function ps_root_ioctllink (line 322) | ssize_t
  function ps_root_ioctl6 (line 329) | ssize_t
  function ps_root_route (line 336) | ssize_t
  function ps_root_indirectioctl (line 345) | ssize_t
  function ps_root_ifignoregroup (line 376) | ssize_t
  function ps_root_sysctl (line 387) | ssize_t

FILE: src/privsep-control.c
  function ps_ctl_startcb (line 41) | static int
  function ps_ctl_recvmsg (line 67) | static void
  function ps_ctl_handleargs (line 76) | ssize_t
  function ps_ctl_dispatch (line 100) | static ssize_t
  function ps_ctl_dodispatch (line 142) | static void
  function ps_ctl_recv (line 152) | static void
  function ps_ctl_listen (line 181) | static void
  function pid_t (line 208) | pid_t
  function ps_ctl_stop (line 267) | int
  function ps_ctl_sendargs (line 273) | ssize_t
  function ps_ctl_sendeof (line 285) | ssize_t

FILE: src/privsep-control.h
  type dhcpcd_ctx (line 35) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 36) | struct dhcpcd_ctx
  type fd_list (line 37) | struct fd_list
  type fd_list (line 38) | struct fd_list
  type fd_list (line 39) | struct fd_list

FILE: src/privsep-inet.c
  function ps_inet_recvbootp (line 53) | static void
  function ps_inet_recvra (line 65) | static void
  function ps_inet_recvdhcp6 (line 85) | static void
  function ps_inet_canstart (line 96) | bool
  function ps_inet_startcb (line 117) | static int
  function ps_inet_validudp (line 211) | static bool
  function ps_inet_validnd (line 232) | static bool
  function ps_inet_sendmsg (line 257) | static ssize_t
  function ps_inet_recvmsg (line 302) | static void
  function ps_inet_dispatch (line 312) | ssize_t
  function ps_inet_dodispatch (line 340) | static void
  function pid_t (line 350) | pid_t
  function ps_inet_stop (line 374) | int
  function ps_inet_recvinbootp (line 381) | static void
  function ps_inet_listenin (line 391) | static int
  function ps_inet_recvin6nd (line 423) | static void
  function ps_inet_listennd (line 432) | static int
  function ps_inet_recvin6dhcp6 (line 460) | static void
  function ps_inet_listenin6 (line 470) | static int
  function ps_inet_recvmsgpsp (line 501) | static void
  function ps_inet_cmd (line 511) | ssize_t
  function ps_inet_in_docmd (line 600) | static ssize_t
  function ps_inet_openbootp (line 618) | ssize_t
  function ps_inet_closebootp (line 624) | ssize_t
  function ps_inet_sendbootp (line 630) | ssize_t
  function ps_inet_ifp_docmd (line 641) | static ssize_t
  function ps_inet_opennd (line 657) | ssize_t
  function ps_inet_closend (line 663) | ssize_t
  function ps_inet_sendnd (line 669) | ssize_t
  function ps_inet_sendnd (line 675) | ssize_t
  function ps_inet_in6_docmd (line 685) | static ssize_t
  function ps_inet_opendhcp6 (line 702) | ssize_t
  function ps_inet_closedhcp6 (line 708) | ssize_t
  function ps_inet_senddhcp6 (line 714) | ssize_t

FILE: src/privsep-inet.h
  type dhcpcd_ctx (line 32) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 33) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 34) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 35) | struct dhcpcd_ctx
  type ps_msghdr (line 35) | struct ps_msghdr
  type msghdr (line 35) | struct msghdr
  type ps_msghdr (line 36) | struct ps_msghdr
  type msghdr (line 36) | struct msghdr
  type ipv4_addr (line 39) | struct ipv4_addr
  type ipv4_addr (line 40) | struct ipv4_addr
  type ipv4_addr (line 41) | struct ipv4_addr
  type interface (line 42) | struct interface
  type msghdr (line 42) | struct msghdr
  type ipv6_addr (line 46) | struct ipv6_addr
  type interface (line 48) | struct interface
  type interface (line 49) | struct interface
  type interface (line 51) | struct interface
  type msghdr (line 51) | struct msghdr
  type ipv6_addr (line 53) | struct ipv6_addr
  type ipv6_addr (line 54) | struct ipv6_addr
  type interface (line 55) | struct interface
  type msghdr (line 55) | struct msghdr

FILE: src/privsep-linux.c
  function ps_root_dosendnetlink (line 62) | static ssize_t
  function ps_root_os (line 91) | ssize_t
  function ps_root_sendnetlink (line 104) | ssize_t
  type sock_filter (line 279) | struct sock_filter
  type seccomp_data (line 281) | struct seccomp_data
  type seccomp_data (line 285) | struct seccomp_data
  type sock_fprog (line 521) | struct sock_fprog
  function ps_seccomp_violation (line 527) | static void
  function ps_seccomp_debug (line 535) | static int
  function ps_seccomp_enter (line 555) | int

FILE: src/privsep-root.c
  type psr_error (line 62) | struct psr_error {
  type psr_ctx (line 69) | struct psr_ctx {
  function ps_root_readerrorcb (line 77) | static ssize_t
  function ps_root_readerror (line 132) | ssize_t
  function ps_root_mreaderror (line 146) | ssize_t
  function ps_root_writeerror (line 162) | static ssize_t
  function ps_root_doioctl (line 201) | static ssize_t
  function ps_root_run_script (line 245) | static ssize_t
  function ps_root_validpath (line 274) | static bool
  function ps_root_dowritefile (line 306) | static ssize_t
  function ps_root_monordm (line 325) | static ssize_t
  function ps_root_dogetifaddrs (line 338) | static ssize_t
  function ps_root_recvmsgcb (line 436) | static ssize_t
  function ps_root_recvmsg (line 595) | static void
  function ps_root_handleinterface (line 606) | static int
  function ps_root_startcb (line 628) | static int
  function ps_root_signalcb (line 701) | void
  function ps_root_devcb (line 753) | static ssize_t
  function ps_root_dispatchcb (line 783) | static ssize_t
  function ps_root_dispatch (line 805) | static void
  function ps_root_log (line 815) | static void
  function pid_t (line 827) | pid_t
  function ps_root_close (line 889) | void
  function ps_root_stop (line 914) | int
  function ps_root_stopprocesses (line 987) | ssize_t
  function ps_root_script (line 998) | ssize_t
  function ps_root_ioctl (line 1006) | ssize_t
  function ps_root_unlink (line 1024) | ssize_t
  function ps_root_readfile (line 1033) | ssize_t
  function ps_root_writefile (line 1043) | ssize_t
  function ps_root_filemtime (line 1064) | ssize_t
  function ps_root_logreopen (line 1073) | ssize_t
  function ps_root_getifaddrs (line 1082) | int
  function ps_root_getauthrdm (line 1162) | int
  function ps_root_dev_initialised (line 1173) | int
  function ps_root_dev_listening (line 1182) | int

FILE: src/privsep-root.h
  type dhcpcd_ctx (line 38) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 39) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 40) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 43) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 44) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 45) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 46) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 47) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 48) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 49) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 51) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 52) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 53) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 54) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 56) | struct dhcpcd_ctx
  type ifaddrs (line 56) | struct ifaddrs
  type dhcpcd_ctx (line 59) | struct dhcpcd_ctx
  type ps_msghdr (line 59) | struct ps_msghdr
  type msghdr (line 59) | struct msghdr
  type dhcpcd_ctx (line 62) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 63) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 64) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 65) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 67) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 68) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 72) | struct dhcpcd_ctx
  type msghdr (line 72) | struct msghdr
  type dhcpcd_ctx (line 76) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 77) | struct dhcpcd_ctx

FILE: src/privsep-sun.c
  function ps_root_doioctl6 (line 43) | static ssize_t
  function ps_root_doroute (line 60) | static ssize_t
  function ps_root_os (line 78) | ssize_t
  function ps_root_ioctl6 (line 104) | ssize_t
  function ps_root_route (line 114) | ssize_t

FILE: src/privsep.c
  function ps_init (line 95) | int
  function ps_dropprivs (line 124) | static int
  function ps_setbuf0 (line 195) | static int
  function ps_setbuf (line 214) | static int
  function ps_setbuf_fdpair (line 229) | int
  function ps_rights_limit_ioctl (line 238) | int
  function ps_rights_limit_fd_fctnl (line 249) | int
  function ps_rights_limit_fd (line 261) | int
  function ps_rights_limit_fd_sockopt (line 272) | int
  function ps_rights_limit_fd_rdonly (line 284) | int
  function ps_rights_limit_fdpair (line 295) | int
  function ps_rights_limit_stdio (line 303) | static int
  function ps_processhangup (line 321) | static void
  function pid_t (line 343) | pid_t
  function ps_process_timeout (line 480) | void
  function ps_stopprocess (line 489) | int
  function ps_start (line 528) | int
  function ps_entersandbox (line 580) | int
  function ps_managersandbox (line 609) | int
  function ps_stop (line 665) | int
  function ps_waitforprocs (line 694) | bool
  function ps_stopwait (line 709) | int
  function ps_freeprocess (line 744) | void
  function ps_free (line 778) | static void
  function ps_unrollmsg (line 802) | int
  function ps_sendpsmmsg (line 848) | ssize_t
  function ps_sendpsmdata (line 927) | ssize_t
  function ps_sendmsg (line 942) | ssize_t
  function ps_sendcmd (line 985) | ssize_t
  function ps_sendcmdmsg (line 1002) | ssize_t
  function ps_recvmsg (line 1011) | ssize_t
  function ps_daemonised (line 1045) | ssize_t
  function ps_recvpsmsg (line 1065) | ssize_t
  type ps_process (line 1145) | struct ps_process
  type dhcpcd_ctx (line 1146) | struct dhcpcd_ctx
  type ps_id (line 1146) | struct ps_id
  type ps_process (line 1148) | struct ps_process
  type ps_process (line 1160) | struct ps_process
  type dhcpcd_ctx (line 1161) | struct dhcpcd_ctx
  type ps_process (line 1163) | struct ps_process
  type ps_process (line 1173) | struct ps_process
  type dhcpcd_ctx (line 1174) | struct dhcpcd_ctx
  type ps_id (line 1174) | struct ps_id
  type ps_process (line 1176) | struct ps_process
  function ps_freeprocesses (line 1195) | void

FILE: src/privsep.h
  type ps_addr (line 135) | struct ps_addr {
  type ps_id (line 147) | struct ps_id {
  type ps_msghdr (line 154) | struct ps_msghdr {
  type ps_msg (line 165) | struct ps_msg {
  type bpf (line 170) | struct bpf
  type ps_process (line 172) | struct ps_process {
  type dhcpcd_ctx (line 205) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 206) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 207) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 208) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 210) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 211) | struct dhcpcd_ctx
  type msghdr (line 213) | struct msghdr
  type ps_msghdr (line 213) | struct ps_msghdr
  type dhcpcd_ctx (line 214) | struct dhcpcd_ctx
  type ps_msghdr (line 214) | struct ps_msghdr
  type msghdr (line 215) | struct msghdr
  type dhcpcd_ctx (line 216) | struct dhcpcd_ctx
  type ps_msghdr (line 216) | struct ps_msghdr
  type dhcpcd_ctx (line 218) | struct dhcpcd_ctx
  type msghdr (line 219) | struct msghdr
  type dhcpcd_ctx (line 220) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 222) | struct dhcpcd_ctx
  type msghdr (line 223) | struct msghdr
  type dhcpcd_ctx (line 225) | struct dhcpcd_ctx
  type ps_msghdr (line 226) | struct ps_msghdr
  type msghdr (line 226) | struct msghdr
  type ps_process (line 244) | struct ps_process
  type ps_process (line 247) | struct ps_process
  type ps_process (line 248) | struct ps_process
  type ps_process (line 249) | struct ps_process
  type dhcpcd_ctx (line 249) | struct dhcpcd_ctx
  type ps_id (line 249) | struct ps_id
  type ps_process (line 250) | struct ps_process
  type dhcpcd_ctx (line 250) | struct dhcpcd_ctx
  type ps_process (line 251) | struct ps_process
  type dhcpcd_ctx (line 251) | struct dhcpcd_ctx
  type ps_id (line 251) | struct ps_id
  type dhcpcd_ctx (line 252) | struct dhcpcd_ctx
  type ps_process (line 254) | struct ps_process
  type dhcpcd_ctx (line 255) | struct dhcpcd_ctx
  type ps_process (line 255) | struct ps_process

FILE: src/route.c
  function rt_maskedaddr (line 80) | static void
  function rt_cmp_netmask (line 112) | static int
  function rt_cmp_dest (line 120) | int
  function rt_compare_os (line 136) | static int
  function rt_compare_list (line 153) | static int
  function rt_compare_proto (line 165) | static int
  type rt (line 212) | struct rt
  type rt (line 219) | struct rt
  type rt (line 226) | struct rt
  function rt_compare_free (line 231) | static int
  type rt (line 240) | struct rt
  function rt_init (line 245) | void
  function rt_is_default (line 254) | bool
  function rt_desc (line 261) | static void
  function rt_headclear0 (line 301) | void
  function rt_headclear (line 323) | void
  function rt_headfree (line 333) | static void
  function rt_dispose (line 344) | void
  type rt (line 359) | struct rt
  type dhcpcd_ctx (line 360) | struct dhcpcd_ctx
  type rt (line 362) | struct rt
  function rt_setif (line 382) | void
  type rt (line 395) | struct rt
  type interface (line 396) | struct interface
  type rt (line 398) | struct rt
  type rt (line 407) | struct rt
  type rt (line 408) | struct rt
  type dhcpcd_ctx (line 408) | struct dhcpcd_ctx
  type rt (line 419) | struct rt
  type rt (line 420) | struct rt
  function rt_free (line 426) | void
  function rt_freeif (line 451) | void
  function rt_recvrt (line 471) | void
  function rt_cmp_mtu (line 504) | static int
  function rt_cmp_lifetime (line 525) | static int
  function rt_add (line 552) | static bool
  function rt_delete (line 686) | static bool
  type rt (line 699) | struct rt
  type rt (line 699) | struct rt
  function rt_doroute (line 710) | static bool
  function rt_build (line 750) | void

FILE: src/route.h
  type rt (line 87) | struct rt {
  type dhcpcd_ctx (line 139) | struct dhcpcd_ctx
  type dhcpcd_ctx (line 140) | struct dhcpcd_ctx
  type rt (line 141) | struct rt
  type interface (line 142) | struct interface
  type rt (line 143) | struct rt
  type dhcpcd_ctx (line 144) | struct dhcpcd_ctx
  type rt (line 147) | struct rt
  type dhcpcd_ctx (line 147) | struct dhcpcd_ctx
  type rt (line 148) | struct rt
  type interface (line 148) | struct interface
  type rt (line 149) | struct rt
  type interface (line 149) | struct interface
  type rt (line 150) | struct rt
  type rt (line 150) | struct rt
  type dhcpcd_ctx (line 150) | struct dhcpcd_ctx
  type rt (line 151) | struct rt
  type rt (line 151) | struct rt
  type rt (line 152) | struct rt
  type rt (line 152) | struct rt
  type rt (line 153) | struct rt
  type dhcpcd_ctx (line 154) | struct dhcpcd_ctx

FILE: src/sa.c
  function socklen_t (line 55) | socklen_t
  function socklen_t (line 76) | socklen_t
  function socklen_t (line 97) | socklen_t
  function sa_is_unspecified (line 119) | bool
  type in6_addr (line 148) | struct in6_addr
  function sa_is_allones (line 151) | bool
  function sa_is_loopback (line 180) | bool
  function sa_toprefix (line 209) | int
  function ipbytes_fromprefix (line 296) | static void
  function in6_addr_fromprefix (line 318) | void
  function sa_fromprefix (line 324) | int
  type sockaddr (line 368) | struct sockaddr
  type sockaddr_dl (line 385) | struct sockaddr_dl
  type sockaddr_ll (line 397) | struct sockaddr_ll
  function sa_cmp (line 407) | int
  function sa_in_init (line 458) | void
  function sa_in6_init (line 475) | void

FILE: src/sa.h
  type sockaddr (line 37) | struct sockaddr
  type sockaddr_in (line 38) | struct sockaddr_in
  type sockaddr_in6 (line 39) | struct sockaddr_in6
  type sockaddr (line 58) | struct sockaddr
  type sockaddr (line 59) | struct sockaddr
  type sockaddr (line 63) | struct sockaddr
  type sockaddr (line 65) | struct sockaddr
  type sockaddr (line 66) | struct sockaddr
  type sockaddr (line 67) | struct sockaddr
  type sockaddr (line 68) | struct sockaddr
  type sockaddr (line 69) | struct sockaddr
  type sockaddr (line 70) | struct sockaddr
  type in6_addr (line 71) | struct in6_addr
  type sockaddr (line 72) | struct sockaddr
  type sockaddr (line 73) | struct sockaddr
  type sockaddr (line 73) | struct sockaddr
  type sockaddr (line 74) | struct sockaddr
  type in_addr (line 74) | struct in_addr
  type sockaddr (line 75) | struct sockaddr
  type in6_addr (line 75) | struct in6_addr

FILE: src/script.c
  function if_printoptions (line 69) | void
  function pid_t (line 78) | pid_t
  function append_config (line 118) | static int
  function efprintf (line 145) | int
  type dhcpcd_ctx (line 163) | struct dhcpcd_ctx
  function make_env (line 206) | static long
  function send_interface1 (line 562) | static int
  function send_interface (line 575) | int
  function script_status (line 666) | static int
  function script_run (line 680) | static int
  function script_dump (line 704) | int
  function script_runreason (line 726) | int

FILE: src/script.h
  type dhcpcd_ctx (line 36) | struct dhcpcd_ctx
  type fd_list (line 38) | struct fd_list
  type interface (line 38) | struct interface
  type interface (line 40) | struct interface

FILE: tests/crypt/run-test.c
  function main (line 31) | int main(void)

FILE: tests/crypt/test_hmac_md5.c
  function print_hmac (line 41) | static void
  function test_hmac (line 52) | static void
  function hmac_md5_test1 (line 63) | static void
  function hmac_md5_test2 (line 82) | static void
  function hmac_md5_test3 (line 98) | static void
  function hmac_md5_test4 (line 119) | static void
  function hmac_md5_test5 (line 140) | static void
  function hmac_md5_test6 (line 159) | static void
  function hmac_md5_test7 (line 178) | static void
  function test_hmac_md5 (line 197) | int test_hmac_md5(void)

FILE: tests/crypt/test_sha256.c
  function print_md (line 46) | static void
  function test_md (line 57) | static void
  function sha256_test1 (line 68) | static void
  function sha256_test2 (line 88) | static void
  function sha256_test3 (line 108) | static void
  function test_sha256 (line 131) | int test_sha256(void)

FILE: vendor/queue.h
  type type (line 189) | struct type
  type type (line 301) | struct type
  type type (line 569) | struct type

FILE: vendor/rbtree.c
  type rb_tree (line 91) | struct rb_tree
  type rb_node (line 91) | struct rb_node
  type rb_tree (line 92) | struct rb_tree
  type rb_node (line 92) | struct rb_node
  type rb_node (line 95) | struct rb_node
  type rb_tree (line 95) | struct rb_tree
  type rb_node (line 96) | struct rb_node
  type rb_tree (line 97) | struct rb_tree
  type rb_node (line 97) | struct rb_node
  type rb_node (line 98) | struct rb_node
  function rb_tree_init (line 110) | void
  type rb_tree (line 133) | struct rb_tree
  type rb_node (line 137) | struct rb_node
  type rb_tree (line 152) | struct rb_tree
  type rb_node (line 156) | struct rb_node
  type rb_tree (line 173) | struct rb_tree
  type rb_node (line 177) | struct rb_node
  type rb_tree (line 194) | struct rb_tree
  type rb_node (line 198) | struct rb_node
  type rb_node (line 212) | struct rb_node
  type rb_node (line 235) | struct rb_node
  type rb_node (line 265) | struct rb_node
  function rb_tree_reparent_nodes (line 337) | static void
  function rb_tree_insert_rebalance (line 401) | static void
  function rb_tree_prune_node (line 507) | static void
  function rb_tree_swap_prune_and_rebalance (line 559) | static void
  function rb_tree_prune_blackred_branch (line 712) | static void
  function rb_tree_remove_node (line 757) | void
  function rb_tree_removal_rebalance (line 822) | static void
  type rb_tree (line 974) | struct rb_tree
  type rb_node (line 978) | struct rb_node
  type rb_node (line 1023) | struct rb_node
  type rb_tree (line 1024) | struct rb_tree
  type rb_node (line 1024) | struct rb_node
  function rb_tree_count_black (line 1069) | static unsigned int
  function rb_tree_check_node (line 1085) | static bool
  function rb_tree_check (line 1287) | void
  function rb_tree_mark_depth (line 1331) | static void
  function rb_tree_depths (line 1352) | void

FILE: vendor/rbtree.h
  type rb_node_t (line 54) | typedef struct rb_node {
  type rb_tree_ops_t (line 164) | typedef struct {
  type rb_tree_t (line 171) | typedef struct rb_tree {
Condensed preview — 158 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (1,684K chars).
[
  {
    "path": ".clang-format",
    "chars": 5187,
    "preview": "# Basic .clang-format taken from FreeBSD\n---\nBasedOnStyle: WebKit\nAlignAfterOpenBracket: DontAlign\nAlignConsecutiveMacro"
  },
  {
    "path": ".clang-tidy",
    "chars": 320,
    "preview": "# Disable DeprecatedOrUnsafeBufferHandling - our use of these is fine\n# and musl does not support the the _s variants.\n#"
  },
  {
    "path": ".clangd",
    "chars": 301,
    "preview": "If:\n  PathMatch: src/dev/.*\\.c\nCompileFlags:\n  Add: [-I.., -I../.., -I../../compat, -I../../vendor]\n---\nIf:\n  PathMatch:"
  },
  {
    "path": ".github/workflows/build.yml",
    "chars": 3162,
    "preview": "name: Build\n\non:\n  push:\n    branches: [ master ]\n  pull_request:\n    branches: [ master ]\n\nenv:\n  CC: clang\n\njobs:\n  ub"
  },
  {
    "path": ".github/workflows/format.yml",
    "chars": 363,
    "preview": "name: Clang Format Checker\non:\n  push:\n  pull_request:\n    branches: [master]\njobs:\n  clang-format-checking:\n    runs-on"
  },
  {
    "path": ".gitignore",
    "chars": 526,
    "preview": "# Ignore configure generated files\nconfig.h\nconfig.mk\nconfig.log\n\n# Ignore object files\n.depend\n*.o\n*.So\n*.so\ndhcpcd\n\n# "
  },
  {
    "path": "BUILDING.md",
    "chars": 9409,
    "preview": "<!-- SPDX-License-Identifier: BSD-2-Clause -->\n<!-- Copyright (c) 2017-2025 Roy Marples <roy@marples.name> -->\n\n# Buildi"
  },
  {
    "path": "LICENSE",
    "chars": 1302,
    "preview": "Copyright (c) 2006-2025 Roy Marples <roy@marples.name>\nAll rights reserved.\n\nRedistribution and use in source and binary"
  },
  {
    "path": "Makefile",
    "chars": 3289,
    "preview": "# SPDX-License-Identifier: BSD-2-Clause\n# Copyright (c) 2006-2025 Roy Marples <roy@marples.name>\n\nSUBDIRS=\tsrc hooks\n\nPA"
  },
  {
    "path": "Makefile.inc",
    "chars": 1121,
    "preview": "# SPDX-License-Identifier: BSD-2-Clause\n# Copyright (c) 2009-2025 Roy Marples <roy@marples.name>\n\n# System definitions\n\n"
  },
  {
    "path": "README.md",
    "chars": 3387,
    "preview": "<!-- SPDX-License-Identifier: BSD-2-Clause -->\n<!-- Copyright (c) 2017-2023 Roy Marples <roy@marples.name> -->\n\n# dhcpcd"
  },
  {
    "path": "compat/_strtoi.h",
    "chars": 2962,
    "preview": "/*\t$NetBSD: _strtoi.h,v 1.1 2015/01/22 02:15:59 christos Exp $\t*/\n\n/*-\n * SPDX-License-Identifier: BSD-3-Clause\n * Copyr"
  },
  {
    "path": "compat/arc4random.c",
    "chars": 7435,
    "preview": "/*\t$OpenBSD: arc4random.c,v 1.58 2022/07/31 13:41:45 tb Exp $\t*/\n\n/*\n * SPDX-License-Identifier: ISC\n * Copyright (c) 19"
  },
  {
    "path": "compat/arc4random.h",
    "chars": 469,
    "preview": "/*\n * Arc4 random number generator for OpenBSD.\n * SPDX-License-Identifier: ISC\n * Copyright 1996 David Mazieres <dm@lcs"
  },
  {
    "path": "compat/arc4random_uniform.c",
    "chars": 1946,
    "preview": "/*\t$OpenBSD: arc4random_uniform.c,v 1.3 2019/01/20 02:59:07 bcook Exp $\t*/\n\n/*\n * SPDX-License-Identifier: ISC\n * Copyri"
  },
  {
    "path": "compat/arc4random_uniform.h",
    "chars": 950,
    "preview": "/*\n * SPDX-License-Identifier: ISC\n * Copyright (c) 2008, Damien Miller <djm@openbsd.org>\n *\n * Permission to use, copy,"
  },
  {
    "path": "compat/bitops.h",
    "chars": 3735,
    "preview": "/*\t$NetBSD: bitops.h,v 1.11 2012/12/07 02:27:58 christos Exp $\t*/\n\n/*-\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyr"
  },
  {
    "path": "compat/chacha_private.h",
    "chars": 5431,
    "preview": "/*\n * SPDX-License-Identifier: CC0-1.0\n *\n * chacha-merged.c version 20080118\n * D. J. Bernstein\n * Public domain.\n */\n\n"
  },
  {
    "path": "compat/closefrom.c",
    "chars": 2033,
    "preview": "/*\n * SPDX-License-Identifier: ISC\n *\n * Copyright (c) 2004-2005, 2007, 2010, 2012-2015, 2017-2018\n *\tTodd C. Miller <To"
  },
  {
    "path": "compat/closefrom.h",
    "chars": 939,
    "preview": "/*\n * SPDX-License-Identifier: ISC\n * Copyright (c) 2004-2005, 2007, 2010, 2012-2015, 2017-2018\n *\tTodd C. Miller <Todd."
  },
  {
    "path": "compat/consttime_memequal.h",
    "chars": 736,
    "preview": "/*\n * SPDX-License-Identifier: CC0-1.0\n * Written by Matthias Drochner <drochner@NetBSD.org>.\n * Public domain.\n */\n\n#if"
  },
  {
    "path": "compat/crypt/hmac.c",
    "chars": 5069,
    "preview": "/*\t$NetBSD: hmac.c,v 1.5 2017/10/05 09:59:04 roy Exp $\t*/\n\n/*-\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c)"
  },
  {
    "path": "compat/crypt/hmac.h",
    "chars": 1747,
    "preview": "/*\t$NetBSD: hmac.c,v 1.5 2017/10/05 09:59:04 roy Exp $\t*/\n\n/*-\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c)"
  },
  {
    "path": "compat/crypt/md5.c",
    "chars": 8006,
    "preview": "/* SPDX-License-Identifier: CC0-1.0\n * This code implements the MD5 message-digest algorithm.\n * The algorithm is due to"
  },
  {
    "path": "compat/crypt/md5.h",
    "chars": 1182,
    "preview": "/*\n * This code implements the MD5 message-digest algorithm.\n * SPDX-License-Identifier: CC0-1.0\n * The algorithm is due"
  },
  {
    "path": "compat/crypt/sha256.c",
    "chars": 8452,
    "preview": "/*-\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright 2005 Colin Percival\n * All rights reserved.\n *\n * Redistributi"
  },
  {
    "path": "compat/crypt/sha256.h",
    "chars": 1761,
    "preview": "/*-\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright 2005 Colin Percival\n * All rights reserved.\n *\n * Redistributi"
  },
  {
    "path": "compat/crypt_openssl/hmac.c",
    "chars": 1883,
    "preview": "/*\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2023 Canonical Ltd.\n *\n * Redistribution and use in source "
  },
  {
    "path": "compat/crypt_openssl/hmac.h",
    "chars": 1528,
    "preview": "/*\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2023 Canonical Ltd.\n *\n * Redistribution and use in source "
  },
  {
    "path": "compat/crypt_openssl/sha256.c",
    "chars": 2016,
    "preview": "/*\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2023 Canonical Ltd.\n *\n * Redistribution and use in source "
  },
  {
    "path": "compat/crypt_openssl/sha256.h",
    "chars": 1897,
    "preview": "/*\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2023 Canonical Ltd.\n *\n * Redistribution and use in source "
  },
  {
    "path": "compat/dprintf.c",
    "chars": 1946,
    "preview": "/*\n * dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2017 Roy Marples <roy@m"
  },
  {
    "path": "compat/dprintf.h",
    "chars": 1837,
    "preview": "/*\n * dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2017 Roy Marples <roy@m"
  },
  {
    "path": "compat/endian.h",
    "chars": 2225,
    "preview": "/*\n * dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2014 Roy Marples <roy@m"
  },
  {
    "path": "compat/pidfile.c",
    "chars": 6750,
    "preview": "/*\t$NetBSD: pidfile.c,v 1.16 2021/08/01 15:29:29 andvar Exp $\t*/\n\n/*-\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyri"
  },
  {
    "path": "compat/pidfile.h",
    "chars": 1749,
    "preview": "/*-\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 1999, 2016 The NetBSD Foundation, Inc.\n * All rights reser"
  },
  {
    "path": "compat/queue.h",
    "chars": 276,
    "preview": "/*\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2014-2025 Roy Marples <roy@marples.name>\n */\n\n/* This stub "
  },
  {
    "path": "compat/reallocarray.c",
    "chars": 2231,
    "preview": "/* $NetBSD: reallocarr.c,v 1.4 2015/08/20 20:08:04 joerg Exp $ */\n\n/*-\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyr"
  },
  {
    "path": "compat/reallocarray.h",
    "chars": 1621,
    "preview": "/* $NetBSD: reallocarr.c,v 1.4 2015/08/20 20:08:04 joerg Exp $ */\n\n/*-\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyr"
  },
  {
    "path": "compat/setproctitle.c",
    "chars": 6971,
    "preview": "/*\n * SPDX-License-Identifier: MIT\n * Copyright © 2010 William Ahern\n * Copyright © 2012-2013 Guillem Jover <guillem@had"
  },
  {
    "path": "compat/setproctitle.h",
    "chars": 2001,
    "preview": "/*\n * SPDX-License-Identifier: MIT\n * Copyright © 2010 William Ahern\n * Copyright © 2012-2013 Guillem Jover <guillem@had"
  },
  {
    "path": "compat/strlcpy.c",
    "chars": 1636,
    "preview": "/*\t$OpenBSD: strlcpy.c,v 1.16 2019/01/25 00:19:25 millert Exp $\t*/\n\n/*\n * SPDX-License-Identifier: ISC\n * Copyright (c) "
  },
  {
    "path": "compat/strlcpy.h",
    "chars": 999,
    "preview": "/*\t$OpenBSD: strlcpy.c,v 1.15 2016/10/16 17:37:39 dtucker Exp $\t*/\n\n/*\n * SPDX-License-Identifier: ISC\n * Copyright (c) "
  },
  {
    "path": "compat/strtoi.c",
    "chars": 2332,
    "preview": "/*\t$NetBSD: strtoi.c,v 1.3 2019/11/28 12:33:23 roy Exp $\t*/\n\n/*-\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright ("
  },
  {
    "path": "compat/strtoi.h",
    "chars": 2197,
    "preview": "/*-\n * SPDX-License-Identifier: BSD-3-Clause\n * Copyright (c) 1990, 1993\n *\tThe Regents of the University of California."
  },
  {
    "path": "compat/strtou.c",
    "chars": 2333,
    "preview": "/*\t$NetBSD: strtou.c,v 1.3 2019/11/28 12:33:23 roy Exp $\t*/\n\n/*-\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright ("
  },
  {
    "path": "config-null.mk",
    "chars": 164,
    "preview": "# SPDX-License-Identifier: BSD-2-Clause\n# Copyright (c) 2014 Roy Marples <roy@marples.name>\n\n# This space left intention"
  },
  {
    "path": "configure",
    "chars": 47961,
    "preview": "#!/bin/sh\n# SPDX-License-Identifier: BSD-2-Clause\n# Copyright (c) 2009-2025 Roy Marples <roy@marples.name>\n\n# Try and be"
  },
  {
    "path": "hooks/01-test",
    "chars": 877,
    "preview": "# SPDX-License-Identifier: BSD-2-Clause\n# Copyright (c) 2017-2020 Roy Marples <roy@marples.name>\n\n# Echo the interface f"
  },
  {
    "path": "hooks/10-wpa_supplicant",
    "chars": 2940,
    "preview": "# SPDX-License-Identifier: BSD-2-Clause\n# Copyright (c) 2017-2024 Roy Marples <roy@marples.name>\n\n# Start, reconfigure a"
  },
  {
    "path": "hooks/15-timezone",
    "chars": 983,
    "preview": "# SPDX-License-Identifier: BSD-2-Clause\n# Copyright (c) 2017-2020 Roy Marples <roy@marples.name>\n\n# Configure timezone\n\n"
  },
  {
    "path": "hooks/20-resolv.conf",
    "chars": 6429,
    "preview": "# SPDX-License-Identifier: BSD-2-Clause\n# Copyright (c) 2017-2025 Roy Marples <roy@marples.name>\n\n# Generate /etc/resolv"
  },
  {
    "path": "hooks/29-lookup-hostname",
    "chars": 939,
    "preview": "# SPDX-License-Identifier: BSD-2-Clause\n# Copyright (c) 2017-2022 Roy Marples <roy@marples.name>\n\n# Lookup the hostname "
  },
  {
    "path": "hooks/30-hostname.in",
    "chars": 3892,
    "preview": "# SPDX-License-Identifier: BSD-2-Clause\n# Copyright (c) 2020-2024 Roy Marples <roy@marples.name>\n\n# Set the hostname fro"
  },
  {
    "path": "hooks/50-dhcpcd-compat",
    "chars": 1117,
    "preview": "# SPDX-License-Identifier: BSD-2-Clause\n# Copyright (c) 2017 Roy Marples <roy@marples.name>\n\n# Compat enter hook shim fo"
  },
  {
    "path": "hooks/50-ntp.conf",
    "chars": 3787,
    "preview": "# SPDX-License-Identifier: BSD-2-Clause\n# Copyright (c) 2017-2026 Roy Marples <roy@marples.name>\n\n# Sample dhcpcd hook s"
  },
  {
    "path": "hooks/50-timesyncd.conf",
    "chars": 1580,
    "preview": "# SPDX-License-Identifier: BSD-2-Clause\n# Copyright (c) 2022-2026 Roy Marples <roy@marples.name>\n\nif [ ! -d /run/systemd"
  },
  {
    "path": "hooks/50-yp.conf",
    "chars": 1288,
    "preview": "# SPDX-License-Identifier: BSD-2-Clause\n# Copyright (c) 2017-2020 Roy Marples <roy@marples.name>\n\n# Sample dhcpcd hook f"
  },
  {
    "path": "hooks/50-ypbind.in",
    "chars": 1945,
    "preview": "# SPDX-License-Identifier: BSD-2-Clause\n# Copyright (c) 2017-2021 Roy Marples <roy@marples.name>\n\n# Sample dhcpcd hook f"
  },
  {
    "path": "hooks/Makefile",
    "chars": 2170,
    "preview": "# SPDX-License-Identifier: BSD-2-Clause\n# Copyright (c) 2017-2023 Roy Marples <roy@marples.name>\n\nTOP=\t../\ninclude ${TOP"
  },
  {
    "path": "hooks/dhcpcd-run-hooks.8.in",
    "chars": 7305,
    "preview": ".\\\" SPDX-License-Identifier: BSD-2-Clause\n.\\\" Copyright (c) 2006-2025 Roy Marples\n.\\\" All rights reserved\n.\\\"\n.\\\" Redist"
  },
  {
    "path": "hooks/dhcpcd-run-hooks.in",
    "chars": 8404,
    "preview": "#!/bin/sh\n# SPDX-License-Identifier: BSD-2-Clause\n# Copyright (c) 2017-2022 Roy Marples <roy@marples.name>\n\n# dhcpcd cli"
  },
  {
    "path": "iconfig.mk",
    "chars": 411,
    "preview": "# SPDX-License-Identifier: BSD-2-Clause\n# Copyright (c) 2014-2019 Roy Marples <roy@marples.name>\n\n# Nasty hack so that m"
  },
  {
    "path": "src/GNUmakefile",
    "chars": 459,
    "preview": "# SPDX-License-Identifier: BSD-2-Clause\n# Copyright (c) 2017 Roy Marples <roy@marples.name>\n\n# GNU Make does not automag"
  },
  {
    "path": "src/Makefile",
    "chars": 5023,
    "preview": "# SPDX-License-Identifier: BSD-2-Clause\n# Copyright (c) 2017-2025 Roy Marples <roy@marples.name>\n\n# dhcpcd Makefile\n\nPRO"
  },
  {
    "path": "src/Makefile.inc",
    "chars": 280,
    "preview": "check-format:\n\tfind . -iname \"*.c\" -o -iname \"*.h\" | \\\n\t\txargs -- clang-format --dry-run --Werror\n\nformat:\n\tfind . -inam"
  },
  {
    "path": "src/arp.c",
    "chars": 16742,
    "preview": "/*\n * dhcpcd - ARP handler\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@marples."
  },
  {
    "path": "src/arp.h",
    "chars": 3522,
    "preview": "/*\n * dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@m"
  },
  {
    "path": "src/auth.c",
    "chars": 17985,
    "preview": "/*\n * dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@m"
  },
  {
    "path": "src/auth.h",
    "chars": 2813,
    "preview": "/*\n * dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@m"
  },
  {
    "path": "src/bpf-bsd.c",
    "chars": 6596,
    "preview": "/*\n * BPF BSD interface\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@marples.nam"
  },
  {
    "path": "src/bpf-dlpi.c",
    "chars": 3015,
    "preview": "/*\n * BPF DLPI interface\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@marples.na"
  },
  {
    "path": "src/bpf-dlpi.h",
    "chars": 1574,
    "preview": "/*\n * BPF DLPI interface\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@marples.na"
  },
  {
    "path": "src/bpf-linux.c",
    "chars": 5885,
    "preview": "/*\n * BPF Linux interface\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@marples.n"
  },
  {
    "path": "src/bpf-pcap.c",
    "chars": 6194,
    "preview": "/*\n * BPF libpcap interface\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2025 Joan Lledó <jlledom@member.fs"
  },
  {
    "path": "src/bpf.c",
    "chars": 14146,
    "preview": "/*\n * dhcpcd: BPF arp and bootp filtering\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marple"
  },
  {
    "path": "src/bpf.h",
    "chars": 3546,
    "preview": "/*\n * dhcpcd: BPF arp and bootp filtering\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marple"
  },
  {
    "path": "src/common.c",
    "chars": 5308,
    "preview": "/*\n * dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@m"
  },
  {
    "path": "src/common.h",
    "chars": 5715,
    "preview": "/*\n * dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@m"
  },
  {
    "path": "src/control.c",
    "chars": 13651,
    "preview": "/*\n * dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@m"
  },
  {
    "path": "src/control.h",
    "chars": 2665,
    "preview": "/*\n * dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@m"
  },
  {
    "path": "src/defs.h",
    "chars": 2339,
    "preview": "/*\n * dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@m"
  },
  {
    "path": "src/dev/Makefile",
    "chars": 928,
    "preview": "# SPDX-License-Identifier: BSD-2-Clause\n# Copyright (c) 2017-2025 Roy Marples <roy@marples.name>\n\nTOP=\t../../\ninclude ${"
  },
  {
    "path": "src/dev/udev.c",
    "chars": 4574,
    "preview": "/*\n * dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@m"
  },
  {
    "path": "src/dev.c",
    "chars": 4828,
    "preview": "/*\n * dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@m"
  },
  {
    "path": "src/dev.h",
    "chars": 2053,
    "preview": "/*\n * dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@m"
  },
  {
    "path": "src/dhcp-common.c",
    "chars": 23653,
    "preview": "/*\n * dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@m"
  },
  {
    "path": "src/dhcp-common.h",
    "chars": 5140,
    "preview": "/*\n * dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@m"
  },
  {
    "path": "src/dhcp.c",
    "chars": 110131,
    "preview": "/*\n * dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@m"
  },
  {
    "path": "src/dhcp.h",
    "chars": 7897,
    "preview": "/*\n * dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@m"
  },
  {
    "path": "src/dhcp6.c",
    "chars": 109697,
    "preview": "/*\n * dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@m"
  },
  {
    "path": "src/dhcp6.h",
    "chars": 8251,
    "preview": "/*\n * dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@m"
  },
  {
    "path": "src/dhcpcd-definitions-small.conf",
    "chars": 4019,
    "preview": "# SPDX-License-Identifier: BSD-2-Clause\n# Copyright (c) 2006-2025 Roy Marples <roy@marples.name>\n# All rights reserved\n\n"
  },
  {
    "path": "src/dhcpcd-definitions.conf",
    "chars": 20948,
    "preview": "# SPDX-License-Identifier: BSD-2-Clause\n# Copyright (c) 2006-2025 Roy Marples <roy@marples.name>\n# All rights reserved\n\n"
  },
  {
    "path": "src/dhcpcd-embedded.c.in",
    "chars": 1658,
    "preview": "/*\n * DO NOT EDIT!\n * Automatically generated from dhcpcd-embedded.conf\n * Ths allows us to simply generate DHCP structu"
  },
  {
    "path": "src/dhcpcd-embedded.h.in",
    "chars": 1749,
    "preview": "/*\n * dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@m"
  },
  {
    "path": "src/dhcpcd.8.in",
    "chars": 26377,
    "preview": ".\\\" SPDX-License-Identifier: BSD-2-Clause\n.\\\" Copyright (c) 2006-2025 Roy Marples\n.\\\" All rights reserved\n.\\\"\n.\\\" Redist"
  },
  {
    "path": "src/dhcpcd.c",
    "chars": 65622,
    "preview": "/*\n * dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@m"
  },
  {
    "path": "src/dhcpcd.conf",
    "chars": 1389,
    "preview": "# SPDX-License-Identifier: BSD-2-Clause\n# Copyright (c) 2017-2025 Roy Marples <roy@marples.name>\n\n# A sample configurati"
  },
  {
    "path": "src/dhcpcd.conf.5.in",
    "chars": 33216,
    "preview": ".\\\" SPDX-License-Identifier: BSD-2-Clause\n.\\\" Copyright (c) 2006-2025 Roy Marples\n.\\\" All rights reserved\n.\\\"\n.\\\" Redist"
  },
  {
    "path": "src/dhcpcd.h",
    "chars": 7267,
    "preview": "/*\n * dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@m"
  },
  {
    "path": "src/duid.c",
    "chars": 6209,
    "preview": "/*\n * dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@m"
  },
  {
    "path": "src/duid.h",
    "chars": 1733,
    "preview": "/* dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@marp"
  },
  {
    "path": "src/eloop.c",
    "chars": 24476,
    "preview": "/*\n * eloop - portable event based main loop.\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2026 Roy Ma"
  },
  {
    "path": "src/eloop.h",
    "chars": 3964,
    "preview": "/*\n * dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2026 Roy Marples <roy@m"
  },
  {
    "path": "src/genembedc",
    "chars": 603,
    "preview": "#!/bin/sh\n# SPDX-License-Identifier: BSD-2-Clause\n# Copyright (c) 2017-2020 Roy Marples <roy@marples.name>\n\nset -e\n\n: ${"
  },
  {
    "path": "src/genembedh",
    "chars": 967,
    "preview": "#!/bin/sh\n# SPDX-License-Identifier: BSD-2-Clause\n# Copyright (c) 2017-2019 Roy Marples <roy@marples.name>\n\nset -e\n\n: ${"
  },
  {
    "path": "src/if-bsd.c",
    "chars": 48852,
    "preview": "/*\n * BSD interface driver for dhcpcd\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <r"
  },
  {
    "path": "src/if-linux-wext.c",
    "chars": 3012,
    "preview": "/*\n * dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2009-2025 Roy Marples <roy@m"
  },
  {
    "path": "src/if-linux.c",
    "chars": 52375,
    "preview": "/*\n * Linux interface driver for dhcpcd\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples "
  },
  {
    "path": "src/if-options.c",
    "chars": 74493,
    "preview": "/*\n * dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@m"
  },
  {
    "path": "src/if-options.h",
    "chars": 10102,
    "preview": "/*\n * dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@m"
  },
  {
    "path": "src/if-sun.c",
    "chars": 39810,
    "preview": "/*\n * Solaris interface driver for dhcpcd\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2016-2025 Roy Marple"
  },
  {
    "path": "src/if.c",
    "chars": 23809,
    "preview": "/*\n * dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@m"
  },
  {
    "path": "src/if.h",
    "chars": 8825,
    "preview": "/*\n * dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@m"
  },
  {
    "path": "src/ipv4.c",
    "chars": 22781,
    "preview": "/*\n * dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@m"
  },
  {
    "path": "src/ipv4.h",
    "chars": 5276,
    "preview": "/*\n * dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@m"
  },
  {
    "path": "src/ipv4ll.c",
    "chars": 14217,
    "preview": "/*\n * dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@m"
  },
  {
    "path": "src/ipv4ll.h",
    "chars": 2859,
    "preview": "/*\n * dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@m"
  },
  {
    "path": "src/ipv6.c",
    "chars": 58642,
    "preview": "/*\n * dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@m"
  },
  {
    "path": "src/ipv6.h",
    "chars": 10840,
    "preview": "/*\n * dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@m"
  },
  {
    "path": "src/ipv6nd.c",
    "chars": 52671,
    "preview": "/*\n * dhcpcd - IPv6 ND handling\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@mar"
  },
  {
    "path": "src/ipv6nd.h",
    "chars": 4795,
    "preview": "/*\n * dhcpcd - IPv6 ND handling\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@mar"
  },
  {
    "path": "src/logerr.c",
    "chars": 11098,
    "preview": "/*\n * logerr: errx with logging\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@mar"
  },
  {
    "path": "src/logerr.h",
    "chars": 4059,
    "preview": "/*\n * logerr: errx with logging\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@mar"
  },
  {
    "path": "src/privsep-bpf.c",
    "chars": 9304,
    "preview": "/*\n * Privilege Separation BPF Initiator\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples"
  },
  {
    "path": "src/privsep-bpf.h",
    "chars": 2303,
    "preview": "/*\n * Privilege Separation for dhcpcd\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <r"
  },
  {
    "path": "src/privsep-bsd.c",
    "chars": 10278,
    "preview": "/*\n * Privilege Separation for dhcpcd, BSD driver\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Ro"
  },
  {
    "path": "src/privsep-control.c",
    "chars": 7734,
    "preview": "/*\n * Privilege Separation for dhcpcd, control proxy\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025"
  },
  {
    "path": "src/privsep-control.h",
    "chars": 1842,
    "preview": "/*\n * Privilege Separation for dhcpcd\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <r"
  },
  {
    "path": "src/privsep-inet.c",
    "chars": 15924,
    "preview": "/*\n * Privilege Separation for dhcpcd, network proxy\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025"
  },
  {
    "path": "src/privsep-inet.h",
    "chars": 2412,
    "preview": "/*\n * Privilege Separation for dhcpcd\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <r"
  },
  {
    "path": "src/privsep-linux.c",
    "chars": 15310,
    "preview": "/*\n * Privilege Separation for dhcpcd, Linux driver\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 "
  },
  {
    "path": "src/privsep-root.c",
    "chars": 27692,
    "preview": "/*\n * Privilege Separation for dhcpcd, privileged proxy\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2"
  },
  {
    "path": "src/privsep-root.h",
    "chars": 3514,
    "preview": "/*\n * Privilege Separation for dhcpcd\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <r"
  },
  {
    "path": "src/privsep-sun.c",
    "chars": 3249,
    "preview": "/*\n * Privilege Separation for dhcpcd, Solaris driver\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-202"
  },
  {
    "path": "src/privsep.c",
    "chars": 28120,
    "preview": "/*\n * Privilege Separation for dhcpcd\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <r"
  },
  {
    "path": "src/privsep.h",
    "chars": 7657,
    "preview": "/*\n * Privilege Separation for dhcpcd\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <r"
  },
  {
    "path": "src/queue.h",
    "chars": 532,
    "preview": "/*\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2025 Roy Marples <roy@marples.name>\n */\n\n/*\n * This stub ex"
  },
  {
    "path": "src/route.c",
    "chars": 21146,
    "preview": "/*\n * dhcpcd - route management\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@mar"
  },
  {
    "path": "src/route.h",
    "chars": 5170,
    "preview": "/*\n * dhcpcd - route management\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@mar"
  },
  {
    "path": "src/sa.c",
    "chars": 10243,
    "preview": "/*\n * Socket Address handling for dhcpcd\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2015-2025 Roy Marples"
  },
  {
    "path": "src/sa.h",
    "chars": 2830,
    "preview": "/*\n * Socket Address handling for dhcpcd\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2015-2025 Roy Marples"
  },
  {
    "path": "src/script.c",
    "chars": 17774,
    "preview": "/*\n * dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@m"
  },
  {
    "path": "src/script.h",
    "chars": 1878,
    "preview": "/*\n * dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2025 Roy Marples <roy@m"
  },
  {
    "path": "tests/Makefile",
    "chars": 513,
    "preview": "# SPDX-License-Identifier: BSD-2-Clause\n# Copyright (c) 2017-2019 Roy Marples <roy@marples.name>\n\nSUBDIRS=\tcrypt eloop-b"
  },
  {
    "path": "tests/crypt/.gitignore",
    "chars": 102,
    "preview": "# SPDX-License-Identifier: BSD-2-Clause\n# Copyright (c) 2017 Roy Marples <roy@marples.name>\n\nrun-test\n"
  },
  {
    "path": "tests/crypt/GNUmakefile",
    "chars": 287,
    "preview": "# SPDX-License-Identifier: BSD-2-Clause\n# Copyright (c) 2017 Roy Marples <roy@marples.name>\n\n# GNU Make does not automag"
  },
  {
    "path": "tests/crypt/Makefile",
    "chars": 748,
    "preview": "# SPDX-License-Identifier: BSD-2-Clause\n# Copyright (c) 2017-2023 Roy Marples <roy@marples.name>\n\nTOP=\t../..\ninclude ${T"
  },
  {
    "path": "tests/crypt/README.md",
    "chars": 405,
    "preview": "<!-- SPDX-License-Identifier: BSD-2-Clause -->\n<!-- Copyright (c) 2017 Roy Marples <roy@marples.name> -->\n\n# dhcpcd Test"
  },
  {
    "path": "tests/crypt/run-test.c",
    "chars": 1571,
    "preview": "/*\n * dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2018 Roy Marples <roy@m"
  },
  {
    "path": "tests/crypt/test.h",
    "chars": 1518,
    "preview": "/*\n * dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2018 Roy Marples <roy@m"
  },
  {
    "path": "tests/crypt/test_hmac_md5.c",
    "chars": 5422,
    "preview": "/*\n * dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2006-2018 Roy Marples <roy@m"
  },
  {
    "path": "tests/crypt/test_sha256.c",
    "chars": 3965,
    "preview": "/*\n * dhcpcd - DHCP client daemon\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright (c) 2023 Tobias Heider <tobias.h"
  },
  {
    "path": "vendor/README.md",
    "chars": 713,
    "preview": "<!-- SPDX-License-Identifier: BSD-2-Clause -->\n<!-- Copyright (c) 2025 Roy Marples <roy@marples.name> -->\n\nThis area is "
  },
  {
    "path": "vendor/queue.h",
    "chars": 22609,
    "preview": "/*\t$NetBSD: queue.h,v 1.77 2024/05/12 10:34:56 rillig Exp $\t*/\n\n/*\n * SPDX-License-Identifier: BSD-3-Clause\n * Copyright"
  },
  {
    "path": "vendor/rbtree.c",
    "chars": 40500,
    "preview": "/*\t$NetBSD: rbtree.c,v 1.2 2025/10/29 08:08:44 roy Exp $\t*/\n\n/*-\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright ("
  },
  {
    "path": "vendor/rbtree.h",
    "chars": 8113,
    "preview": "/*\t$NetBSD: rbtree.h,v 1.14 2025/10/29 08:08:44 roy Exp $\t*/\n\n/*-\n * SPDX-License-Identifier: BSD-2-Clause\n * Copyright "
  }
]

About this extraction

This page contains the full source code of the rsmarples/dhcpcd GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 158 files (1.5 MB), approximately 495.4k tokens, and a symbol index with 2109 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!