Don't use .Xo/.Xc. Fix date format.
[netbsd-mini2440.git] / usr.sbin / pvcsif / pvcsif.c
blob53d0f00af06d9d5b30e941ccf3f94063765ff752
1 /* $NetBSD: pvcsif.c,v 1.3 2001/05/07 14:00:23 kleink Exp $ */
3 /*
4 * Copyright (C) 1998
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
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.
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
26 * SUCH DAMAGE.
28 * ALTQ Id: pvcsif.c,v 0.3 1999/05/19 11:31:11 kjc Exp
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <unistd.h>
34 #include <string.h>
35 #include <err.h>
37 #include <sys/socket.h>
38 #include <sys/ioctl.h>
39 #include <net/if.h>
41 #include <net/if_atm.h>
43 void usage __P((void));
44 void list_all __P((void));
46 void usage(void)
48 fprintf(stderr, "usage: pvcsif -a\n");
49 fprintf(stderr, " pvcsif interface [-s]\n");
50 exit(1);
53 int
54 main(int argc, char **argv)
56 struct ifreq ifr;
57 int shell_mode = 0;
58 int s, ch;
60 if (argc < 2)
61 usage();
63 if (strncmp(argv[1], "-a", 2) == 0) {
64 list_all();
65 return (0);
68 ifr.ifr_name[IFNAMSIZ-1] = '\0';
69 strncpy(ifr.ifr_name, argv[1], IFNAMSIZ-1);
71 optind = 2;
72 while ((ch = getopt(argc, argv, "s")) != -1) {
73 switch (ch) {
74 case 's':
75 shell_mode = 1;
76 break;
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");
86 close(s);
88 if (shell_mode)
89 printf("%s", ifr.ifr_name);
90 else
91 printf("created a pvc subinterface %s (bound to %s)\n",
92 ifr.ifr_name, argv[1]);
94 return (0);
97 void
98 list_all(void)
100 struct if_nameindex *ifn_list, *ifnp;
101 struct pvctxreq pvcreq;
102 int pcr, s;
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");
119 * print info
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)
127 printf("AAL5");
128 if (ATM_PH_FLAGS(&pvcreq.pvc_aph) & ATM_PH_LLCSNAP)
129 printf("/LLCSNAP");
130 printf(") ");
131 if (pcr < 0)
132 printf("(invalid)\n");
133 else if (pcr == 0)
134 printf("pcr:%d(full speed)\n", pcr);
135 else if (pcr < 1000)
136 printf("pcr:%d(%dbps)\n",
137 pcr, pcr * 48 * 8);
138 else if (pcr < 1000000)
139 printf("pcr:%d(%dKbps)\n",
140 pcr, pcr * 48 * 8 / 1000);
141 else
142 printf("pcr:%d(%dMbps)\n",
143 pcr, pcr * 48 * 8 / 1000000);
147 close(s);
148 if_freenameindex(ifn_list);