1 /* $NetBSD: pvctxctl.c,v 1.5 2007/01/16 17:32:05 hubertf 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: pvctxctl.c,v 0.4 1999/05/19 11:31:11 kjc Exp
38 #include <sys/socket.h>
39 #include <sys/ioctl.h>
42 #include <net/if_atm.h>
44 static int str2vc(char *str
, int *vpi
, int *vci
);
45 static void usage(void);
50 fprintf(stderr
, "usage: pvctxctl interface [vpi:]vci\n");
51 fprintf(stderr
, " [-p pcr] [-b pcr_in_bps] [-j [vpi:]vci\n");
52 fprintf(stderr
, " [-n] \n");
61 int llcsnap
= ATM_PH_LLCSNAP
;
67 main(int argc
, char **argv
)
69 struct pvctxreq pvcreq
;
78 if (argc
> 2 && isdigit((unsigned char)argv
[2][0]))
79 str2vc(argv
[2], &vpi
, &vci
);
82 while ((ch
= getopt(argc
, argv
, "p:b:j:snv")) != -1) {
85 pcr
= strtol(optarg
, NULL
, 0);
90 bandwidth
= strtol(optarg
, &cp
, 0);
92 if (*cp
== 'K' || *cp
== 'k')
94 if (*cp
== 'M' || *cp
== 'm')
97 pcr
= bandwidth
/ 8 / 48;
101 str2vc(optarg
, &joint_vpi
, &joint_vci
);
114 if ((s
= socket(AF_INET
, SOCK_DGRAM
, 0)) < 0)
115 err(1, "can't open socket");
117 pvcreq
.pvc_ifname
[IFNAMSIZ
-1] = '\0';
118 strncpy(pvcreq
.pvc_ifname
, if_name
, IFNAMSIZ
-1);
120 if (strncmp(if_name
, "pvc", 3) == 0)
121 /* pvc subinterface */
124 ATM_PH_FLAGS(&pvcreq
.pvc_aph
) = ATM_PH_AAL5
| llcsnap
;
125 ATM_PH_VPI(&pvcreq
.pvc_aph
) = vpi
;
126 ATM_PH_SETVCI(&pvcreq
.pvc_aph
, vci
);
128 ATM_PH_FLAGS(&pvcreq
.pvc_joint
) = 0;
129 ATM_PH_VPI(&pvcreq
.pvc_joint
) = joint_vpi
;
130 ATM_PH_SETVCI(&pvcreq
.pvc_joint
, joint_vci
);
132 pvcreq
.pvc_pcr
= pcr
;
135 if (ioctl(s
, SIOCGPVCTX
, &pvcreq
) < 0)
136 err(1, "SIOCSPVCTX");
140 printf("setting pvc tx: interface:%s vc:%d:%d ph=0x%x\n",
141 if_name
, vpi
, vci
, ATM_PH_FLAGS(&pvcreq
.pvc_aph
));
142 printf(" joint:%d:%d, setting pcr:%d\n",
143 joint_vpi
, joint_vci
, pcr
);
146 if (ioctl(s
, SIOCSPVCTX
, &pvcreq
) < 0)
147 err(1, "SIOCSPVCTX");
150 pcr
= pvcreq
.pvc_pcr
;
155 printf(" %s", if_name
);
157 printf(" (bound to %s)", pvcreq
.pvc_ifname
);
158 printf(": vci:[%d:%d] (",
159 ATM_PH_VPI(&pvcreq
.pvc_aph
), ATM_PH_VCI(&pvcreq
.pvc_aph
));
160 if (ATM_PH_FLAGS(&pvcreq
.pvc_aph
) & ATM_PH_AAL5
)
162 if (ATM_PH_FLAGS(&pvcreq
.pvc_aph
) & ATM_PH_LLCSNAP
)
166 printf("(invalid)\n");
168 printf("pcr:%d(full speed)\n", pcr
);
170 printf("pcr:%d(%dbps)\n", pcr
, pcr
* 48 * 8);
171 else if (pcr
< 1000000)
172 printf("pcr:%d(%dKbps)\n", pcr
, pcr
* 48 * 8 / 1000);
174 printf("pcr:%d(%dMbps)\n", pcr
, pcr
* 48 * 8 / 1000000);
178 if (getinfo
&& pcr
< 0) {
179 fprintf(stderr
, "can't get pvc info for vci:%d\n", vci
);
180 fprintf(stderr
, "to setup a vci, use -p or -b option\n");
187 str2vc(char *str
, int *vpip
, int *vcip
)
191 if ((c
= strchr(str
, ':')) != NULL
) {
193 *vpip
= strtol(str
, NULL
, 0);
199 *vcip
= strtol(str
, NULL
, 0);