> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/man/man9/ether_gen_addr.9.md).

# ether\_gen\_addr.9

`ether_gen_addr` — 生成供使用的任意 MAC 地址

## 名称

`ether_gen_addr`

## 概要

```c
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if.h>
#include <net/if_var.h>
#include <net/ethernet.h>
```

```c
void
ether_gen_addr(struct ifnet *ifp, struct ether_addr *hwaddr)
```

## 描述

`ether_gen_addr` 函数为没有分配地址的以太网接口生成一个任意 MAC 地址供使用。

默认情况下，`ether_gen_addr` 尝试使用 `ifp` 被添加到的 jail 的 hostid 生成一个稳定的 MAC 地址。在启动早期，尚未填充 `/etc/hostid` 的机器或不使用 [loader(8)](/man/man8/loader.8.md) 的机器上，hostid 可能尚未设置。

由于内存分配失败或 hostid 尚未填充，`ether_gen_addr` 可能无法派生出 MAC 地址。在这些情况下，将随机生成一个本地管理的单播 MAC 地址并通过 `hwaddr` 参数返回。

如果 `ether_gen_addr` 成功，则通过 `hwaddr` 参数返回一个属于 FreeBSD Foundation OUI "58:9c:fc" 的 MAC 地址。

## 作者

本手册页由 Kyle Evans <kevans@FreeBSD.org> 编写。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://book.bsdcn.org/man/man9/ether_gen_addr.9.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
