xref: /f-stack/tools/compat/include/net/if_dl.h (revision d4a07e70)
1df6ad731Slogwang /*-
2*d4a07e70Sfengbojiang  * SPDX-License-Identifier: BSD-3-Clause
3*d4a07e70Sfengbojiang  *
4df6ad731Slogwang  * Copyright (c) 1990, 1993
5df6ad731Slogwang  *	The Regents of the University of California.  All rights reserved.
6df6ad731Slogwang  *
7df6ad731Slogwang  * Redistribution and use in source and binary forms, with or without
8df6ad731Slogwang  * modification, are permitted provided that the following conditions
9df6ad731Slogwang  * are met:
10df6ad731Slogwang  * 1. Redistributions of source code must retain the above copyright
11df6ad731Slogwang  *    notice, this list of conditions and the following disclaimer.
12df6ad731Slogwang  * 2. Redistributions in binary form must reproduce the above copyright
13df6ad731Slogwang  *    notice, this list of conditions and the following disclaimer in the
14df6ad731Slogwang  *    documentation and/or other materials provided with the distribution.
15*d4a07e70Sfengbojiang  * 3. Neither the name of the University nor the names of its contributors
16df6ad731Slogwang  *    may be used to endorse or promote products derived from this software
17df6ad731Slogwang  *    without specific prior written permission.
18df6ad731Slogwang  *
19df6ad731Slogwang  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20df6ad731Slogwang  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21df6ad731Slogwang  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22df6ad731Slogwang  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23df6ad731Slogwang  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24df6ad731Slogwang  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25df6ad731Slogwang  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26df6ad731Slogwang  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27df6ad731Slogwang  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28df6ad731Slogwang  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29df6ad731Slogwang  * SUCH DAMAGE.
30df6ad731Slogwang  *
31df6ad731Slogwang  *	@(#)if_dl.h	8.1 (Berkeley) 6/10/93
32df6ad731Slogwang  * $FreeBSD$
33df6ad731Slogwang  */
34df6ad731Slogwang 
35df6ad731Slogwang #ifndef _NET_IF_DL_H_
36df6ad731Slogwang #define _NET_IF_DL_H_
37df6ad731Slogwang 
38df6ad731Slogwang /*
39df6ad731Slogwang  * A Link-Level Sockaddr may specify the interface in one of two
40df6ad731Slogwang  * ways: either by means of a system-provided index number (computed
41df6ad731Slogwang  * anew and possibly differently on every reboot), or by a human-readable
42df6ad731Slogwang  * string such as "il0" (for managerial convenience).
43df6ad731Slogwang  *
44df6ad731Slogwang  * Census taking actions, such as something akin to SIOCGCONF would return
45df6ad731Slogwang  * both the index and the human name.
46df6ad731Slogwang  *
47df6ad731Slogwang  * High volume transactions (such as giving a link-level ``from'' address
48df6ad731Slogwang  * in a recvfrom or recvmsg call) may be likely only to provide the indexed
49df6ad731Slogwang  * form, (which requires fewer copy operations and less space).
50df6ad731Slogwang  *
51df6ad731Slogwang  * The form and interpretation  of the link-level address is purely a matter
52df6ad731Slogwang  * of convention between the device driver and its consumers; however, it is
53df6ad731Slogwang  * expected that all drivers for an interface of a given if_type will agree.
54df6ad731Slogwang  */
55df6ad731Slogwang 
56df6ad731Slogwang /*
57df6ad731Slogwang  * Structure of a Link-Level sockaddr:
58df6ad731Slogwang  */
59df6ad731Slogwang struct sockaddr_dl {
60df6ad731Slogwang 	u_char	sdl_len;	/* Total length of sockaddr */
61df6ad731Slogwang 	u_char	sdl_family;	/* AF_LINK */
62df6ad731Slogwang 	u_short	sdl_index;	/* if != 0, system given index for interface */
63df6ad731Slogwang 	u_char	sdl_type;	/* interface type */
64df6ad731Slogwang 	u_char	sdl_nlen;	/* interface name length, no trailing 0 reqd. */
65df6ad731Slogwang 	u_char	sdl_alen;	/* link level address length */
66df6ad731Slogwang 	u_char	sdl_slen;	/* link layer selector length */
67df6ad731Slogwang 	char	sdl_data[46];	/* minimum work area, can be larger;
68df6ad731Slogwang 				   contains both if name and ll address */
69df6ad731Slogwang };
70df6ad731Slogwang 
71df6ad731Slogwang #define LLADDR(s) ((caddr_t)((s)->sdl_data + (s)->sdl_nlen))
72df6ad731Slogwang #define CLLADDR(s) ((c_caddr_t)((s)->sdl_data + (s)->sdl_nlen))
73df6ad731Slogwang #define LLINDEX(s) ((s)->sdl_index)
74df6ad731Slogwang 
75df6ad731Slogwang struct ifnet;
76df6ad731Slogwang struct sockaddr_dl *link_alloc_sdl(size_t, int);
77df6ad731Slogwang void link_free_sdl(struct sockaddr *sa);
78df6ad731Slogwang struct sockaddr_dl *link_init_sdl(struct ifnet *, struct sockaddr *, u_char);
79df6ad731Slogwang 
80df6ad731Slogwang void	link_addr(const char *, struct sockaddr_dl *);
81df6ad731Slogwang char	*link_ntoa(const struct sockaddr_dl *);
82df6ad731Slogwang 
83df6ad731Slogwang #endif
84