ether.c revision 1.2.4.2 1 1.2.4.2 yamt /* $NetBSD: ether.c,v 1.2.4.2 2013/01/16 05:32:33 yamt Exp $ */
2 1.2.4.2 yamt
3 1.2.4.2 yamt /*
4 1.2.4.2 yamt * Copyright (c) 1983, 1993
5 1.2.4.2 yamt * The Regents of the University of California. All rights reserved.
6 1.2.4.2 yamt *
7 1.2.4.2 yamt * Redistribution and use in source and binary forms, with or without
8 1.2.4.2 yamt * modification, are permitted provided that the following conditions
9 1.2.4.2 yamt * are met:
10 1.2.4.2 yamt * 1. Redistributions of source code must retain the above copyright
11 1.2.4.2 yamt * notice, this list of conditions and the following disclaimer.
12 1.2.4.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
13 1.2.4.2 yamt * notice, this list of conditions and the following disclaimer in the
14 1.2.4.2 yamt * documentation and/or other materials provided with the distribution.
15 1.2.4.2 yamt * 3. Neither the name of the University nor the names of its contributors
16 1.2.4.2 yamt * may be used to endorse or promote products derived from this software
17 1.2.4.2 yamt * without specific prior written permission.
18 1.2.4.2 yamt *
19 1.2.4.2 yamt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 1.2.4.2 yamt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 1.2.4.2 yamt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 1.2.4.2 yamt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 1.2.4.2 yamt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 1.2.4.2 yamt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 1.2.4.2 yamt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.2.4.2 yamt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.2.4.2 yamt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.2.4.2 yamt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.2.4.2 yamt * SUCH DAMAGE.
30 1.2.4.2 yamt */
31 1.2.4.2 yamt
32 1.2.4.2 yamt #include <sys/cdefs.h>
33 1.2.4.2 yamt #ifndef lint
34 1.2.4.2 yamt __RCSID("$NetBSD: ether.c,v 1.2.4.2 2013/01/16 05:32:33 yamt Exp $");
35 1.2.4.2 yamt #endif /* not lint */
36 1.2.4.2 yamt
37 1.2.4.2 yamt #include <sys/param.h>
38 1.2.4.2 yamt #include <sys/ioctl.h>
39 1.2.4.2 yamt
40 1.2.4.2 yamt #include <net/if.h>
41 1.2.4.2 yamt #include <net/if_ether.h>
42 1.2.4.2 yamt
43 1.2.4.2 yamt #include <ctype.h>
44 1.2.4.2 yamt #include <err.h>
45 1.2.4.2 yamt #include <errno.h>
46 1.2.4.2 yamt #include <string.h>
47 1.2.4.2 yamt #include <stdlib.h>
48 1.2.4.2 yamt #include <stdio.h>
49 1.2.4.2 yamt #include <util.h>
50 1.2.4.2 yamt
51 1.2.4.2 yamt #include "env.h"
52 1.2.4.2 yamt #include "parse.h"
53 1.2.4.2 yamt #include "extern.h"
54 1.2.4.2 yamt #include "prog_ops.h"
55 1.2.4.2 yamt
56 1.2.4.2 yamt static void ether_status(prop_dictionary_t, prop_dictionary_t);
57 1.2.4.2 yamt static void ether_constructor(void) __attribute__((constructor));
58 1.2.4.2 yamt
59 1.2.4.2 yamt static status_func_t status;
60 1.2.4.2 yamt
61 1.2.4.2 yamt #define MAX_PRINT_LEN 55
62 1.2.4.2 yamt
63 1.2.4.2 yamt void
64 1.2.4.2 yamt ether_status(prop_dictionary_t env, prop_dictionary_t oenv)
65 1.2.4.2 yamt {
66 1.2.4.2 yamt struct eccapreq eccr;
67 1.2.4.2 yamt char fbuf[BUFSIZ];
68 1.2.4.2 yamt char *bp;
69 1.2.4.2 yamt
70 1.2.4.2 yamt memset(&eccr, 0, sizeof(eccr));
71 1.2.4.2 yamt
72 1.2.4.2 yamt if (direct_ioctl(env, SIOCGETHERCAP, &eccr) == -1)
73 1.2.4.2 yamt return;
74 1.2.4.2 yamt
75 1.2.4.2 yamt if (eccr.eccr_capabilities != 0) {
76 1.2.4.2 yamt (void)snprintb_m(fbuf, sizeof(fbuf), ECCAPBITS,
77 1.2.4.2 yamt eccr.eccr_capabilities, MAX_PRINT_LEN);
78 1.2.4.2 yamt bp = fbuf;
79 1.2.4.2 yamt while (*bp != '\0') {
80 1.2.4.2 yamt printf("\tec_capabilities=%s\n", &bp[2]);
81 1.2.4.2 yamt bp += strlen(bp) + 1;
82 1.2.4.2 yamt }
83 1.2.4.2 yamt (void)snprintb_m(fbuf, sizeof(fbuf), ECCAPBITS,
84 1.2.4.2 yamt eccr.eccr_capenable, MAX_PRINT_LEN);
85 1.2.4.2 yamt bp = fbuf;
86 1.2.4.2 yamt while (*bp != '\0') {
87 1.2.4.2 yamt printf("\tec_enabled=%s\n", &bp[2]);
88 1.2.4.2 yamt bp += strlen(bp) + 1;
89 1.2.4.2 yamt }
90 1.2.4.2 yamt }
91 1.2.4.2 yamt }
92 1.2.4.2 yamt
93 1.2.4.2 yamt static void
94 1.2.4.2 yamt ether_constructor(void)
95 1.2.4.2 yamt {
96 1.2.4.2 yamt
97 1.2.4.2 yamt status_func_init(&status, ether_status);
98 1.2.4.2 yamt register_status(&status);
99 1.2.4.2 yamt }
100