2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * $FreeBSD: src/sbin/ifconfig/af_link.c,v 1.2 2004/12/31 19:46:27 sam Exp $
32 #include <sys/types.h>
33 #include <sys/ioctl.h>
34 #include <sys/socket.h>
36 #include <net/route.h> /* for RTX_IFA */
43 #include <net/if_dl.h>
44 #include <net/if_types.h>
45 #include <net/ethernet.h>
49 static struct ifreq link_ridreq
;
52 link_status(int s __unused
, const struct rt_addrinfo
*info
)
54 const struct sockaddr_dl
*sdl
=
55 (const struct sockaddr_dl
*) info
->rti_info
[RTAX_IFA
];
57 if (sdl
!= NULL
&& sdl
->sdl_alen
> 0) {
58 if (sdl
->sdl_type
== IFT_ETHER
&&
59 sdl
->sdl_alen
== ETHER_ADDR_LEN
)
60 printf("\tether %s\n",
61 ether_ntoa((const struct ether_addr
*)LLADDR(sdl
)));
63 int n
= sdl
->sdl_nlen
> 0 ? sdl
->sdl_nlen
+ 1 : 0;
65 printf("\tlladdr %s\n", link_ntoa(sdl
) + n
);
71 link_getaddr(const char *addr
, int which
)
74 struct sockaddr_dl sdl
;
75 struct sockaddr
*sa
= &link_ridreq
.ifr_addr
;
78 errx(1, "can't set link-level netmask or broadcast");
79 if ((temp
= malloc(strlen(addr
) + 2)) == NULL
)
80 errx(1, "malloc failed");
82 strcpy(temp
+ 1, addr
);
83 sdl
.sdl_len
= sizeof(sdl
);
84 link_addr(temp
, &sdl
);
86 if (sdl
.sdl_alen
> sizeof(sa
->sa_data
))
87 errx(1, "malformed link-level address");
88 sa
->sa_family
= AF_LINK
;
89 sa
->sa_len
= sdl
.sdl_alen
;
90 bcopy(LLADDR(&sdl
), sa
->sa_data
, sdl
.sdl_alen
);
93 static struct afswtch af_link
= {
96 .af_status
= link_status
,
97 .af_getaddr
= link_getaddr
,
98 .af_aifaddr
= SIOCSIFLLADDR
,
99 .af_addreq
= &link_ridreq
,
101 static struct afswtch af_ether
= {
104 .af_status
= link_status
,
105 .af_getaddr
= link_getaddr
,
106 .af_aifaddr
= SIOCSIFLLADDR
,
107 .af_addreq
= &link_ridreq
,
109 static struct afswtch af_lladdr
= {
112 .af_status
= link_status
,
113 .af_getaddr
= link_getaddr
,
114 .af_aifaddr
= SIOCSIFLLADDR
,
115 .af_addreq
= &link_ridreq
,
118 static __constructor(101) void
121 af_register(&af_link
);
122 af_register(&af_ether
);
123 af_register(&af_lladdr
);