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