Deleted Added
full compact
af_link.c (138593) af_link.c (139494)
1/*
2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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 * 4. 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.
16 *
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
27 * SUCH DAMAGE.
28 */
29
30#ifndef lint
31static const char rcsid[] =
1/*
2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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 * 4. 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.
16 *
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
27 * SUCH DAMAGE.
28 */
29
30#ifndef lint
31static const char rcsid[] =
32 "$FreeBSD: head/sbin/ifconfig/af_link.c 138593 2004-12-08 19:18:07Z sam $";
32 "$FreeBSD: head/sbin/ifconfig/af_link.c 139494 2004-12-31 19:46:27Z sam $";
33#endif /* not lint */
34
35#include <sys/types.h>
36#include <sys/ioctl.h>
37#include <sys/socket.h>
38#include <net/if.h>
33#endif /* not lint */
34
35#include <sys/types.h>
36#include <sys/ioctl.h>
37#include <sys/socket.h>
38#include <net/if.h>
39#include <net/route.h> /* for RTX_IFA */
39
40#include <err.h>
41#include <stdio.h>
42#include <stdlib.h>
43#include <string.h>
44
45#include <net/if_dl.h>
46#include <net/if_types.h>
47#include <net/ethernet.h>
48
49#include "ifconfig.h"
50
51static struct ifreq link_ridreq;
52
53static void
54link_status(int s __unused, const struct rt_addrinfo *info)
55{
40
41#include <err.h>
42#include <stdio.h>
43#include <stdlib.h>
44#include <string.h>
45
46#include <net/if_dl.h>
47#include <net/if_types.h>
48#include <net/ethernet.h>
49
50#include "ifconfig.h"
51
52static struct ifreq link_ridreq;
53
54static void
55link_status(int s __unused, const struct rt_addrinfo *info)
56{
56 const struct sockaddr_dl *sdl = (const struct sockaddr_dl *)info;
57 const struct sockaddr_dl *sdl =
58 (const struct sockaddr_dl *) info->rti_info[RTAX_IFA];
57
59
58 if (sdl->sdl_alen > 0) {
60 if (sdl != NULL && sdl->sdl_alen > 0) {
59 if (sdl->sdl_type == IFT_ETHER &&
60 sdl->sdl_alen == ETHER_ADDR_LEN)
61 printf("\tether %s\n",
62 ether_ntoa((const struct ether_addr *)LLADDR(sdl)));
63 else {
64 int n = sdl->sdl_nlen > 0 ? sdl->sdl_nlen + 1 : 0;
65
66 printf("\tlladdr %s\n", link_ntoa(sdl) + n);
67 }
68 }
69}
70
71static void
72link_getaddr(const char *addr, int which)
73{
74 char *temp;
75 struct sockaddr_dl sdl;
76 struct sockaddr *sa = &link_ridreq.ifr_addr;
77
78 if (which != ADDR)
79 errx(1, "can't set link-level netmask or broadcast");
80 if ((temp = malloc(strlen(addr) + 1)) == NULL)
81 errx(1, "malloc failed");
82 temp[0] = ':';
83 strcpy(temp + 1, addr);
84 sdl.sdl_len = sizeof(sdl);
85 link_addr(temp, &sdl);
86 free(temp);
87 if (sdl.sdl_alen > sizeof(sa->sa_data))
88 errx(1, "malformed link-level address");
89 sa->sa_family = AF_LINK;
90 sa->sa_len = sdl.sdl_alen;
91 bcopy(LLADDR(&sdl), sa->sa_data, sdl.sdl_alen);
92}
93
94static struct afswtch af_link = {
95 .af_name = "link",
96 .af_af = AF_LINK,
97 .af_status = link_status,
98 .af_getaddr = link_getaddr,
99 .af_aifaddr = SIOCSIFLLADDR,
100 .af_addreq = &link_ridreq,
101};
102static struct afswtch af_ether = {
103 .af_name = "ether",
104 .af_af = AF_LINK,
105 .af_status = link_status,
106 .af_getaddr = link_getaddr,
107 .af_aifaddr = SIOCSIFLLADDR,
108 .af_addreq = &link_ridreq,
109};
110static struct afswtch af_lladdr = {
111 .af_name = "lladdr",
112 .af_af = AF_LINK,
113 .af_status = link_status,
114 .af_getaddr = link_getaddr,
115 .af_aifaddr = SIOCSIFLLADDR,
116 .af_addreq = &link_ridreq,
117};
118
119static __constructor void
120link_ctor(void)
121{
122 af_register(&af_link);
123 af_register(&af_ether);
124 af_register(&af_lladdr);
125}
61 if (sdl->sdl_type == IFT_ETHER &&
62 sdl->sdl_alen == ETHER_ADDR_LEN)
63 printf("\tether %s\n",
64 ether_ntoa((const struct ether_addr *)LLADDR(sdl)));
65 else {
66 int n = sdl->sdl_nlen > 0 ? sdl->sdl_nlen + 1 : 0;
67
68 printf("\tlladdr %s\n", link_ntoa(sdl) + n);
69 }
70 }
71}
72
73static void
74link_getaddr(const char *addr, int which)
75{
76 char *temp;
77 struct sockaddr_dl sdl;
78 struct sockaddr *sa = &link_ridreq.ifr_addr;
79
80 if (which != ADDR)
81 errx(1, "can't set link-level netmask or broadcast");
82 if ((temp = malloc(strlen(addr) + 1)) == NULL)
83 errx(1, "malloc failed");
84 temp[0] = ':';
85 strcpy(temp + 1, addr);
86 sdl.sdl_len = sizeof(sdl);
87 link_addr(temp, &sdl);
88 free(temp);
89 if (sdl.sdl_alen > sizeof(sa->sa_data))
90 errx(1, "malformed link-level address");
91 sa->sa_family = AF_LINK;
92 sa->sa_len = sdl.sdl_alen;
93 bcopy(LLADDR(&sdl), sa->sa_data, sdl.sdl_alen);
94}
95
96static struct afswtch af_link = {
97 .af_name = "link",
98 .af_af = AF_LINK,
99 .af_status = link_status,
100 .af_getaddr = link_getaddr,
101 .af_aifaddr = SIOCSIFLLADDR,
102 .af_addreq = &link_ridreq,
103};
104static struct afswtch af_ether = {
105 .af_name = "ether",
106 .af_af = AF_LINK,
107 .af_status = link_status,
108 .af_getaddr = link_getaddr,
109 .af_aifaddr = SIOCSIFLLADDR,
110 .af_addreq = &link_ridreq,
111};
112static struct afswtch af_lladdr = {
113 .af_name = "lladdr",
114 .af_af = AF_LINK,
115 .af_status = link_status,
116 .af_getaddr = link_getaddr,
117 .af_aifaddr = SIOCSIFLLADDR,
118 .af_addreq = &link_ridreq,
119};
120
121static __constructor void
122link_ctor(void)
123{
124 af_register(&af_link);
125 af_register(&af_ether);
126 af_register(&af_lladdr);
127}