https://github.com/weskoerber/mac_address
A cross-platform library to retrieve the MAC address from your network interfaces without libc.
https://github.com/weskoerber/mac_address
tools zig zig-package
Last synced: 11 months ago
JSON representation
A cross-platform library to retrieve the MAC address from your network interfaces without libc.
- Host: GitHub
- URL: https://github.com/weskoerber/mac_address
- Owner: weskoerber
- License: mit
- Created: 2024-05-17T01:52:16.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-05-24T19:10:21.000Z (about 1 year ago)
- Last Synced: 2025-07-27T04:35:52.450Z (11 months ago)
- Topics: tools, zig, zig-package
- Language: Zig
- Homepage: https://weskoerber.github.io/mac_address/
- Size: 34.2 KB
- Stars: 4
- Watchers: 1
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/weskoerber/mac_address/actions/workflows/test.yaml)
[](https://github.com/weskoerber/mac_address/actions/workflows/docs.yaml)
# `mac_address`
A cross-platform library to retrieve the MAC address from your network
interfaces without `libc`.
## Requirements
- [Zig](https://github.com/ziglang/zig) compiler (`0.14.0` or newer)[^1]
- If using Zig `0.12` and `0.13`, use the [`zig-0.12`](https://github.com/weskoerber/mac_address/tree/zig-0.12) branch
## Install
First, add the dependency to your `build.zig.zon` using `zig fetch`:
```console
zig fetch --save git+https://github.com/weskoerber/mac_address#main
```
Then, import `mac_address` into your `build.zig`:
```zig
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const mac_address = b.dependency("mac_address", .{
.target = target,
.optimize = optimize,
}).module("mac_address");
const my_exe = b.addExecutable(.{
.name = "my_exe",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
my_exe.root_module.addImport(mac_address);
}
```
## Usage
See the `examples` directory for example usage. Example executables can be
built by setting the `examples` option to `true` (or `-Dexamples=true` on the
CLI):
```zig
const mac_address = b.dependency("mac_address", .{
.target = target,
.optimize = optimize,
.examples = true,
}).module("mac_address");
```
```console
zig build -Dexamples=true
```
## Cross-platform support
| `mac_address` API | Linux | Windows |
| ------------------ | ----- | ------- |
| `getAll` | ✅ | ✅ |
| `getAllNoLoopback` | ✅ | ✅ |
- ✅ = supported
- 📝 = planned
- ❌ = not supported
---
[^1]: Shameless plug: if you're using a unix-like operating system or WSL on
Windows, consider using a Zig compiler version manager I wrote called
[zvm](https://github.com/weskoerber/zvm). Once downloaded and in your
`PATH`, just run `zvm install 0.12.0` (or `zvm install master` to get the
latest nightly).