1 /* $NetBSD: pvcsif.c,v 1.3 2001/05/07 14:00:23 kleink Exp $ */
5 * Sony Computer Science Laboratory Inc. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
16 * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * ALTQ Id: pvcsif.c,v 0.3 1999/05/19 11:31:11 kjc Exp
37 #include <sys/socket.h>
38 #include <sys/ioctl.h>
41 #include <net/if_atm.h>
43 void usage
__P((void));
44 void list_all
__P((void));
48 fprintf(stderr
, "usage: pvcsif -a\n");
49 fprintf(stderr
, " pvcsif interface [-s]\n");
54 main(int argc
, char **argv
)
63 if (strncmp(argv
[1], "-a", 2) == 0) {
68 ifr
.ifr_name
[IFNAMSIZ
-1] = '\0';
69 strncpy(ifr
.ifr_name
, argv
[1], IFNAMSIZ
-1);
72 while ((ch
= getopt(argc
, argv
, "s")) != -1) {
80 if ((s
= socket(AF_INET
, SOCK_DGRAM
, 0)) < 0)
81 err(1, "can't open socket");
83 if (ioctl(s
, SIOCSPVCSIF
, &ifr
) < 0)
84 err(1, "SIOCSPVCSIF");
89 printf("%s", ifr
.ifr_name
);
91 printf("created a pvc subinterface %s (bound to %s)\n",
92 ifr
.ifr_name
, argv
[1]);
100 struct if_nameindex
*ifn_list
, *ifnp
;
101 struct pvctxreq pvcreq
;
104 if ((ifn_list
= if_nameindex()) == NULL
)
105 err(1, "if_nameindex failed");
107 if ((s
= socket(AF_INET
, SOCK_DGRAM
, 0)) < 0)
108 err(1, "can't open socket");
110 for (ifnp
= ifn_list
; ifnp
->if_name
!= NULL
; ifnp
++) {
111 if (strncmp(ifnp
->if_name
, "pvc", 3) == 0) {
113 bzero(&pvcreq
, sizeof(pvcreq
));
114 strncpy(pvcreq
.pvc_ifname
, ifnp
->if_name
, IFNAMSIZ
-1);
115 if (ioctl(s
, SIOCGPVCTX
, &pvcreq
) < 0)
116 err(1, "SIOCSPVCTX");
121 pcr
= pvcreq
.pvc_pcr
;
122 printf(" %s (bound to %s): vci:[%d:%d] (",
123 ifnp
->if_name
, pvcreq
.pvc_ifname
,
124 ATM_PH_VPI(&pvcreq
.pvc_aph
),
125 ATM_PH_VCI(&pvcreq
.pvc_aph
));
126 if (ATM_PH_FLAGS(&pvcreq
.pvc_aph
) & ATM_PH_AAL5
)
128 if (ATM_PH_FLAGS(&pvcreq
.pvc_aph
) & ATM_PH_LLCSNAP
)
132 printf("(invalid)\n");
134 printf("pcr:%d(full speed)\n", pcr
);
136 printf("pcr:%d(%dbps)\n",
138 else if (pcr
< 1000000)
139 printf("pcr:%d(%dKbps)\n",
140 pcr
, pcr
* 48 * 8 / 1000);
142 printf("pcr:%d(%dMbps)\n",
143 pcr
, pcr
* 48 * 8 / 1000000);
148 if_freenameindex(ifn_list
);