commit e189168144bf26996dcbd7777d49323d9482eb0c Author: fuckwit Date: Mon May 22 20:13:21 2023 +0200 initial commit diff --git a/.direnv/devenv-profile-31817fb3b51d5f8cb230f24734ea32688ede0af9.rc b/.direnv/devenv-profile-31817fb3b51d5f8cb230f24734ea32688ede0af9.rc new file mode 100644 index 0000000..5805fcd --- /dev/null +++ b/.direnv/devenv-profile-31817fb3b51d5f8cb230f24734ea32688ede0af9.rc @@ -0,0 +1,118 @@ +unset shellHook +PATH=${PATH:-} +nix_saved_PATH="$PATH" +XDG_DATA_DIRS=${XDG_DATA_DIRS:-} +nix_saved_XDG_DATA_DIRS="$XDG_DATA_DIRS" +BASH='/noshell' +HOSTTYPE='x86_64' +IFS=' +' +IN_NIX_SHELL='impure' +export IN_NIX_SHELL +LINENO='76' +MACHTYPE='x86_64-pc-linux-gnu' +NIX_BUILD_CORES='0' +export NIX_BUILD_CORES +NIX_STORE='/nix/store' +export NIX_STORE +OLDPWD='' +export OLDPWD +OPTERR='1' +OSTYPE='linux-gnu' +PATH='/path-not-set' +export PATH +PS4='+ ' +builder='/nix/store/kbcrs84s1x8yd5bp1nq6q6ihda8nd2lp-bash-interactive-5.2-p15/bin/bash' +export builder +dontAddDisableDepTrack='1' +export dontAddDisableDepTrack +name='devenv-shell' +export name +out='/home/patrick/Sandbox/dhcp/outputs/out' +export out +outputs='out' +shellHook=' +# Remove all the unnecessary noise that is set by the build env +unset NIX_BUILD_TOP NIX_BUILD_CORES NIX_STORE +unset TEMP TEMPDIR TMP TMPDIR +# $name variable is preserved to keep it compatible with pure shell https://github.com/sindresorhus/pure/blob/47c0c881f0e7cfdb5eaccd335f52ad17b897c060/pure.zsh#L235 +unset builder out shellHook stdenv system +# Flakes stuff +unset dontAddDisableDepTrack outputs + +# For `nix develop`. We get /noshell on Linux and /sbin/nologin on macOS. +if [[ "$SHELL" == "/noshell" || "$SHELL" == "/sbin/nologin" ]]; then + export SHELL=/nix/store/kbcrs84s1x8yd5bp1nq6q6ihda8nd2lp-bash-interactive-5.2-p15/bin/bash +fi + +# https://github.com/numtide/devshell/issues/158 +PATH=${PATH#/path-not-set:} + +export DEVENV_PROFILE=/nix/store/93qx8jlgc6hpcqr3jcsr7by6lzipah3g-devenv-profile + +# add installed packages to PATH +export PATH="$DEVENV_PROFILE/bin:$PATH" + +# prepend common compilation lookup paths +export PKG_CONFIG_PATH="$DEVENV_PROFILE/lib/pkgconfig:${PKG_CONFIG_PATH-}" +export LD_LIBRARY_PATH="$DEVENV_PROFILE/lib:${LD_LIBRARY_PATH-}" +export LIBRARY_PATH="$DEVENV_PROFILE/lib:${LIBRARY_PATH-}" +export C_INCLUDE_PATH="$DEVENV_PROFILE/include:${C_INCLUDE_PATH-}" + +# these provide shell completions / default config options +export XDG_DATA_DIRS="$DEVENV_PROFILE/share:${XDG_DATA_DIRS-}" +export XDG_CONFIG_DIRS="$DEVENV_PROFILE/etc/xdg:${XDG_CONFIG_DIRS-}" + +export DEVENV_DOTFILE='\''/home/patrick/Sandbox/dhcp/.devenv'\'' +export DEVENV_PROFILE='\''/nix/store/93qx8jlgc6hpcqr3jcsr7by6lzipah3g-devenv-profile'\'' +export DEVENV_ROOT='\''/home/patrick/Sandbox/dhcp'\'' +export DEVENV_STATE='\''/home/patrick/Sandbox/dhcp/.devenv/state'\'' +export GREET='\''devenv'\'' + + +hello +git --version + +export PS1="\[\e[0;34m\](devenv)\[\e[0m\] ${PS1-}" + +# set path to locales on non-NixOS Linux hosts +if [ -z "${LOCALE_ARCHIVE-}" ]; then + export LOCALE_ARCHIVE=/nix/store/nm00g2nm2wsyh30jvkgi168kh6yvw4sl-glibc-locales-2.37-8/lib/locale/locale-archive +fi + + +# note what environments are active, but make sure we don'\''t repeat them +if [[ ! "${DIRENV_ACTIVE-}" =~ (^|:)"$PWD"(:|$) ]]; then + export DIRENV_ACTIVE="$PWD:${DIRENV_ACTIVE-}" +fi + +# devenv helper +if [ ! type -p direnv &>/dev/null && -f .envrc ]; then + echo "You have .envrc but direnv command is not installed." + echo "Please install direnv: https://direnv.net/docs/installation.html" +fi + +mkdir -p .devenv +rm -f .devenv/profile +ln -s /nix/store/93qx8jlgc6hpcqr3jcsr7by6lzipah3g-devenv-profile .devenv/profile + +' +export shellHook +stdenv='/nix/store/fi1k3vh3a70g8cpwmrnc553vvccrny54-naked-stdenv' +export stdenv +system='x86_64-linux' +export system +runHook () +{ + + eval "$shellHook"; + unset runHook +} +PATH="$PATH:$nix_saved_PATH" +XDG_DATA_DIRS="$XDG_DATA_DIRS:$nix_saved_XDG_DATA_DIRS" +export NIX_BUILD_TOP="$(mktemp -d -t nix-shell.XXXXXX)" +export TMP="$NIX_BUILD_TOP" +export TMPDIR="$NIX_BUILD_TOP" +export TEMP="$NIX_BUILD_TOP" +export TEMPDIR="$NIX_BUILD_TOP" +eval "$shellHook" diff --git a/.direnv/devenv-profile-4708295e575b498767fffc5ad34947de7a691088.rc b/.direnv/devenv-profile-4708295e575b498767fffc5ad34947de7a691088.rc new file mode 100644 index 0000000..653a24f --- /dev/null +++ b/.direnv/devenv-profile-4708295e575b498767fffc5ad34947de7a691088.rc @@ -0,0 +1,115 @@ +unset shellHook +PATH=${PATH:-} +nix_saved_PATH="$PATH" +XDG_DATA_DIRS=${XDG_DATA_DIRS:-} +nix_saved_XDG_DATA_DIRS="$XDG_DATA_DIRS" +BASH='/noshell' +HOSTTYPE='x86_64' +IFS=' +' +IN_NIX_SHELL='impure' +export IN_NIX_SHELL +LINENO='76' +MACHTYPE='x86_64-pc-linux-gnu' +NIX_BUILD_CORES='0' +export NIX_BUILD_CORES +NIX_STORE='/nix/store' +export NIX_STORE +OLDPWD='' +export OLDPWD +OPTERR='1' +OSTYPE='linux-gnu' +PATH='/path-not-set' +export PATH +PS4='+ ' +builder='/nix/store/kbcrs84s1x8yd5bp1nq6q6ihda8nd2lp-bash-interactive-5.2-p15/bin/bash' +export builder +dontAddDisableDepTrack='1' +export dontAddDisableDepTrack +name='devenv-shell' +export name +out='/home/patrick/Sandbox/dhcp/outputs/out' +export out +outputs='out' +shellHook=' +# Remove all the unnecessary noise that is set by the build env +unset NIX_BUILD_TOP NIX_BUILD_CORES NIX_STORE +unset TEMP TEMPDIR TMP TMPDIR +# $name variable is preserved to keep it compatible with pure shell https://github.com/sindresorhus/pure/blob/47c0c881f0e7cfdb5eaccd335f52ad17b897c060/pure.zsh#L235 +unset builder out shellHook stdenv system +# Flakes stuff +unset dontAddDisableDepTrack outputs + +# For `nix develop`. We get /noshell on Linux and /sbin/nologin on macOS. +if [[ "$SHELL" == "/noshell" || "$SHELL" == "/sbin/nologin" ]]; then + export SHELL=/nix/store/kbcrs84s1x8yd5bp1nq6q6ihda8nd2lp-bash-interactive-5.2-p15/bin/bash +fi + +# https://github.com/numtide/devshell/issues/158 +PATH=${PATH#/path-not-set:} + +export DEVENV_PROFILE=/nix/store/fd3xw4ffw33w8c70nw5d768ss3sxg211-devenv-profile + +# add installed packages to PATH +export PATH="$DEVENV_PROFILE/bin:$PATH" + +# prepend common compilation lookup paths +export PKG_CONFIG_PATH="$DEVENV_PROFILE/lib/pkgconfig:${PKG_CONFIG_PATH-}" +export LD_LIBRARY_PATH="$DEVENV_PROFILE/lib:${LD_LIBRARY_PATH-}" +export LIBRARY_PATH="$DEVENV_PROFILE/lib:${LIBRARY_PATH-}" +export C_INCLUDE_PATH="$DEVENV_PROFILE/include:${C_INCLUDE_PATH-}" + +# these provide shell completions / default config options +export XDG_DATA_DIRS="$DEVENV_PROFILE/share:${XDG_DATA_DIRS-}" +export XDG_CONFIG_DIRS="$DEVENV_PROFILE/etc/xdg:${XDG_CONFIG_DIRS-}" + +export DEVENV_DOTFILE='\''/home/patrick/Sandbox/dhcp/.devenv'\'' +export DEVENV_PROFILE='\''/nix/store/fd3xw4ffw33w8c70nw5d768ss3sxg211-devenv-profile'\'' +export DEVENV_ROOT='\''/home/patrick/Sandbox/dhcp'\'' +export DEVENV_STATE='\''/home/patrick/Sandbox/dhcp/.devenv/state'\'' +export RUST_SRC_PATH='\''/nix/store/8n69a7ralcwkzfxhzm9va5nlj5risdz6-rust-src-stable-2023-04-20/lib/rustlib/src/rust/library'\'' + + +export PS1="\[\e[0;34m\](devenv)\[\e[0m\] ${PS1-}" + +# set path to locales on non-NixOS Linux hosts +if [ -z "${LOCALE_ARCHIVE-}" ]; then + export LOCALE_ARCHIVE=/nix/store/nm00g2nm2wsyh30jvkgi168kh6yvw4sl-glibc-locales-2.37-8/lib/locale/locale-archive +fi + + +# note what environments are active, but make sure we don'\''t repeat them +if [[ ! "${DIRENV_ACTIVE-}" =~ (^|:)"$PWD"(:|$) ]]; then + export DIRENV_ACTIVE="$PWD:${DIRENV_ACTIVE-}" +fi + +# devenv helper +if [ ! type -p direnv &>/dev/null && -f .envrc ]; then + echo "You have .envrc but direnv command is not installed." + echo "Please install direnv: https://direnv.net/docs/installation.html" +fi + +mkdir -p .devenv +rm -f .devenv/profile +ln -s /nix/store/fd3xw4ffw33w8c70nw5d768ss3sxg211-devenv-profile .devenv/profile + +' +export shellHook +stdenv='/nix/store/fi1k3vh3a70g8cpwmrnc553vvccrny54-naked-stdenv' +export stdenv +system='x86_64-linux' +export system +runHook () +{ + + eval "$shellHook"; + unset runHook +} +PATH="$PATH:$nix_saved_PATH" +XDG_DATA_DIRS="$XDG_DATA_DIRS:$nix_saved_XDG_DATA_DIRS" +export NIX_BUILD_TOP="$(mktemp -d -t nix-shell.XXXXXX)" +export TMP="$NIX_BUILD_TOP" +export TMPDIR="$NIX_BUILD_TOP" +export TEMP="$NIX_BUILD_TOP" +export TEMPDIR="$NIX_BUILD_TOP" +eval "$shellHook" diff --git a/.direnv/devenv-profile-b2e3948989e5900a6355bd6cb53151b4ac09417d.rc b/.direnv/devenv-profile-b2e3948989e5900a6355bd6cb53151b4ac09417d.rc new file mode 100644 index 0000000..653a24f --- /dev/null +++ b/.direnv/devenv-profile-b2e3948989e5900a6355bd6cb53151b4ac09417d.rc @@ -0,0 +1,115 @@ +unset shellHook +PATH=${PATH:-} +nix_saved_PATH="$PATH" +XDG_DATA_DIRS=${XDG_DATA_DIRS:-} +nix_saved_XDG_DATA_DIRS="$XDG_DATA_DIRS" +BASH='/noshell' +HOSTTYPE='x86_64' +IFS=' +' +IN_NIX_SHELL='impure' +export IN_NIX_SHELL +LINENO='76' +MACHTYPE='x86_64-pc-linux-gnu' +NIX_BUILD_CORES='0' +export NIX_BUILD_CORES +NIX_STORE='/nix/store' +export NIX_STORE +OLDPWD='' +export OLDPWD +OPTERR='1' +OSTYPE='linux-gnu' +PATH='/path-not-set' +export PATH +PS4='+ ' +builder='/nix/store/kbcrs84s1x8yd5bp1nq6q6ihda8nd2lp-bash-interactive-5.2-p15/bin/bash' +export builder +dontAddDisableDepTrack='1' +export dontAddDisableDepTrack +name='devenv-shell' +export name +out='/home/patrick/Sandbox/dhcp/outputs/out' +export out +outputs='out' +shellHook=' +# Remove all the unnecessary noise that is set by the build env +unset NIX_BUILD_TOP NIX_BUILD_CORES NIX_STORE +unset TEMP TEMPDIR TMP TMPDIR +# $name variable is preserved to keep it compatible with pure shell https://github.com/sindresorhus/pure/blob/47c0c881f0e7cfdb5eaccd335f52ad17b897c060/pure.zsh#L235 +unset builder out shellHook stdenv system +# Flakes stuff +unset dontAddDisableDepTrack outputs + +# For `nix develop`. We get /noshell on Linux and /sbin/nologin on macOS. +if [[ "$SHELL" == "/noshell" || "$SHELL" == "/sbin/nologin" ]]; then + export SHELL=/nix/store/kbcrs84s1x8yd5bp1nq6q6ihda8nd2lp-bash-interactive-5.2-p15/bin/bash +fi + +# https://github.com/numtide/devshell/issues/158 +PATH=${PATH#/path-not-set:} + +export DEVENV_PROFILE=/nix/store/fd3xw4ffw33w8c70nw5d768ss3sxg211-devenv-profile + +# add installed packages to PATH +export PATH="$DEVENV_PROFILE/bin:$PATH" + +# prepend common compilation lookup paths +export PKG_CONFIG_PATH="$DEVENV_PROFILE/lib/pkgconfig:${PKG_CONFIG_PATH-}" +export LD_LIBRARY_PATH="$DEVENV_PROFILE/lib:${LD_LIBRARY_PATH-}" +export LIBRARY_PATH="$DEVENV_PROFILE/lib:${LIBRARY_PATH-}" +export C_INCLUDE_PATH="$DEVENV_PROFILE/include:${C_INCLUDE_PATH-}" + +# these provide shell completions / default config options +export XDG_DATA_DIRS="$DEVENV_PROFILE/share:${XDG_DATA_DIRS-}" +export XDG_CONFIG_DIRS="$DEVENV_PROFILE/etc/xdg:${XDG_CONFIG_DIRS-}" + +export DEVENV_DOTFILE='\''/home/patrick/Sandbox/dhcp/.devenv'\'' +export DEVENV_PROFILE='\''/nix/store/fd3xw4ffw33w8c70nw5d768ss3sxg211-devenv-profile'\'' +export DEVENV_ROOT='\''/home/patrick/Sandbox/dhcp'\'' +export DEVENV_STATE='\''/home/patrick/Sandbox/dhcp/.devenv/state'\'' +export RUST_SRC_PATH='\''/nix/store/8n69a7ralcwkzfxhzm9va5nlj5risdz6-rust-src-stable-2023-04-20/lib/rustlib/src/rust/library'\'' + + +export PS1="\[\e[0;34m\](devenv)\[\e[0m\] ${PS1-}" + +# set path to locales on non-NixOS Linux hosts +if [ -z "${LOCALE_ARCHIVE-}" ]; then + export LOCALE_ARCHIVE=/nix/store/nm00g2nm2wsyh30jvkgi168kh6yvw4sl-glibc-locales-2.37-8/lib/locale/locale-archive +fi + + +# note what environments are active, but make sure we don'\''t repeat them +if [[ ! "${DIRENV_ACTIVE-}" =~ (^|:)"$PWD"(:|$) ]]; then + export DIRENV_ACTIVE="$PWD:${DIRENV_ACTIVE-}" +fi + +# devenv helper +if [ ! type -p direnv &>/dev/null && -f .envrc ]; then + echo "You have .envrc but direnv command is not installed." + echo "Please install direnv: https://direnv.net/docs/installation.html" +fi + +mkdir -p .devenv +rm -f .devenv/profile +ln -s /nix/store/fd3xw4ffw33w8c70nw5d768ss3sxg211-devenv-profile .devenv/profile + +' +export shellHook +stdenv='/nix/store/fi1k3vh3a70g8cpwmrnc553vvccrny54-naked-stdenv' +export stdenv +system='x86_64-linux' +export system +runHook () +{ + + eval "$shellHook"; + unset runHook +} +PATH="$PATH:$nix_saved_PATH" +XDG_DATA_DIRS="$XDG_DATA_DIRS:$nix_saved_XDG_DATA_DIRS" +export NIX_BUILD_TOP="$(mktemp -d -t nix-shell.XXXXXX)" +export TMP="$NIX_BUILD_TOP" +export TMPDIR="$NIX_BUILD_TOP" +export TEMP="$NIX_BUILD_TOP" +export TEMPDIR="$NIX_BUILD_TOP" +eval "$shellHook" diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..6de8a8a --- /dev/null +++ b/.envrc @@ -0,0 +1,3 @@ +source_url "https://raw.githubusercontent.com/cachix/devenv/d1f7b48e35e6dee421cfd0f51481d17f77586997/direnvrc" "sha256-YBzqskFZxmNb3kYVoKD9ZixoPXJh1C9ZvTLGFRkauZ0=" + +use devenv \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fa2da01 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +/target +/Cargo.lock + +# Devenv +.devenv* +devenv.local.nix + diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..e8f9d58 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "dhcp" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies.nom] +version = "7" +default-features = false diff --git a/devenv.lock b/devenv.lock new file mode 100644 index 0000000..c16b40a --- /dev/null +++ b/devenv.lock @@ -0,0 +1,177 @@ +{ + "nodes": { + "devenv": { + "locked": { + "dir": "src/modules", + "lastModified": 1684536222, + "narHash": "sha256-jbcTwWLSNZQPmf8+PKtw+3RgwMxbSarMlerIH8feGdw=", + "owner": "cachix", + "repo": "devenv", + "rev": "2f1d49aeee1378c44293ca2f61bf3a9004986fb7", + "type": "github" + }, + "original": { + "dir": "src/modules", + "owner": "cachix", + "repo": "devenv", + "type": "github" + } + }, + "fenix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1684736520, + "narHash": "sha256-8WjS3Mmr4DPBsSV2iPkYmxr0/YPpkhX10qT/0YybSsc=", + "owner": "nix-community", + "repo": "fenix", + "rev": "f435c0d000726dc5ccfabde567443c2495957706", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1660459072, + "narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "a20de23b925fd8264fd7fad6454652e142fd7f73", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1684668519, + "narHash": "sha256-KkVvlXTqdLLwko9Y0p1Xv6KQ9QTcQorrU098cGilb7c=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "85340996ba67cc02f01ba324e18b1306892ed6f5", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1678872516, + "narHash": "sha256-/E1YwtMtFAu2KUQKV/1+KFuReYPANM2Rzehk84VxVoc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9b8e5abb18324c7fe9f07cb100c3cd4a29cda8b8", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-22.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "gitignore": "gitignore", + "nixpkgs": [ + "nixpkgs" + ], + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1684195081, + "narHash": "sha256-IKnQUSBhQTChFERxW2AzuauVpY1HRgeVzAjNMAA4B6I=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "96eabec58248ed8f4b0ad59e7ce9398018684fdc", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, + "root": { + "inputs": { + "devenv": "devenv", + "fenix": "fenix", + "nixpkgs": "nixpkgs", + "pre-commit-hooks": "pre-commit-hooks" + } + }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1684672829, + "narHash": "sha256-xDUpgRcACQQREemfVQnft6AImqF2+dbxmHupw6gzSho=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "7ac161ce77dfa31dc39337c2543a1d777e70c16e", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/devenv.nix b/devenv.nix new file mode 100644 index 0000000..cc47d90 --- /dev/null +++ b/devenv.nix @@ -0,0 +1,8 @@ +{ pkgs, ... }: + +{ + languages.rust = { + enable = true; + version = "stable"; + }; +} diff --git a/devenv.yaml b/devenv.yaml new file mode 100644 index 0000000..62b5722 --- /dev/null +++ b/devenv.yaml @@ -0,0 +1,8 @@ +inputs: + nixpkgs: + url: github:NixOS/nixpkgs/nixpkgs-unstable + fenix: + url: github:nix-community/fenix + inputs: + nixpkgs: + follows: nixpkgs diff --git a/dhcp_discover.bin b/dhcp_discover.bin new file mode 100644 index 0000000..7f2bdfc Binary files /dev/null and b/dhcp_discover.bin differ diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..e5329c6 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,120 @@ +use std::{net::Ipv4Addr, path::Path}; + +use nom::{ + bytes::complete::take, + number::complete::{be_u16, be_u32, be_u8}, + IResult, +}; + +#[derive(Debug)] +struct DhcpMessage<'a> { + operation: Operation, + hardware_type: HardwareType, + hardware_address_length: u8, + hops: u8, + transaction_id: u32, + seconds: u16, + flags: u16, + client_address: Ipv4Addr, + server_address: Ipv4Addr, + gateway_address: Ipv4Addr, + client_hardware_address: &'a [u8], + server_hostname: &'a str, + boot_file_name: &'a Path, +} + +#[derive(Debug)] +enum Operation { + Request = 1, + Reply = 2, +} + +impl From for Operation { + fn from(value: u8) -> Self { + match value { + 1 => Operation::Request, + 2 => Operation::Reply, + _ => todo!(), + } + } +} + +#[derive(Debug)] +enum HardwareType { + Reserved(u8), + Unassigned(u8), + Ethernet, +} + +impl From for HardwareType { + fn from(value: u8) -> Self { + use HardwareType::*; + match value { + a @ 0 => Reserved(a), + 1 => Ethernet, + v => Unassigned(v), + } + } +} + +fn parse_dhcp_operation(i: &[u8]) -> IResult<&[u8], Operation> { + be_u8(i).map(|(i, v)| (i, v.into())) +} + +fn parse_dhcp_hardware_type(i: &[u8]) -> IResult<&[u8], HardwareType> { + be_u8(i).map(|(i, v)| (i, v.into())) +} + +fn parse_ipv4_address(i: &[u8]) -> IResult<&[u8], Ipv4Addr> { + let (i, val) = take(4usize)(i)?; + let ip = Ipv4Addr::new(val[0], val[1], val[2], val[3]); + Ok((i, ip)) +} + +fn parse_dhcp_packet(packet: &[u8]) -> IResult<&[u8], DhcpMessage> { + let (packet, operation) = parse_dhcp_operation(packet)?; + let (packet, hardware_type) = parse_dhcp_hardware_type(packet)?; + let (packet, hardware_address_length) = be_u8(packet)?; + let (packet, hops) = be_u8(packet)?; + let (packet, transaction_id) = be_u32(packet)?; + let (packet, seconds) = be_u16(packet)?; + let (packet, flags) = be_u16(packet)?; + let (packet, client_address) = parse_ipv4_address(packet)?; + let (packet, server_address) = parse_ipv4_address(packet)?; + let (packet, gateway_address) = parse_ipv4_address(packet)?; + let (packet, client_hardware_address) = take(6usize)(packet)?; + + Ok(( + packet, + DhcpMessage { + operation, + hardware_type, + hardware_address_length, + hops, + transaction_id, + seconds, + flags, + client_address, + server_address, + gateway_address, + client_hardware_address, + server_hostname: "", + boot_file_name: Path::new(""), + }, + )) +} + +#[cfg(test)] +mod tests { + static DHCP_PACKET: &'static [u8] = include_bytes!("../dhcp_discover.bin"); + static DHCP_PACKET2: &'static [u8] = &[ + 0x01, 0x01, 0x06, 0x05, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x7f, 0x00, 0x00, + 0x01, 0x7f, 0x00, 0x00, 0x01, 0x7f, 0x00, 0x00, 0x01, 0x54, 0x05, 0xdb, 0xa6, 0x96, 0xd0, + ]; + + #[test] + fn parses() { + let res = super::parse_dhcp_packet(DHCP_PACKET2).unwrap(); + dbg!(res); + } +}