3 * ===================================
4 * HARP | Host ATM Research Platform
5 * ===================================
8 * This Host ATM Research Platform ("HARP") file (the "Software") is
9 * made available by Network Computing Services, Inc. ("NetworkCS")
10 * "AS IS". NetworkCS does not provide maintenance, improvements or
11 * support of any kind.
13 * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED,
14 * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
15 * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE
16 * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE.
17 * In no event shall NetworkCS be responsible for any damages, including
18 * but not limited to consequential damages, arising from or relating to
19 * any use of the Software or related support.
21 * Copyright 1994-1998 Network Computing Services, Inc.
23 * Copies of this Software may be made, however, the above copyright
24 * notice must be reproduced on all copies.
26 * $FreeBSD: src/lib/libatm/ioctl_subr.c,v 1.3.2.1 2001/09/28 16:52:10 dillon Exp $
27 * $DragonFly: src/lib/libatm/ioctl_subr.c,v 1.4 2004/09/23 23:39:08 geekgod Exp $
31 * User Space Library Functions
32 * ----------------------------
38 #include <sys/types.h>
39 #include <sys/param.h>
40 #include <sys/socket.h>
41 #include <sys/sockio.h>
43 #include <netinet/in.h>
44 #include <netatm/port.h>
45 #include <netatm/atm.h>
46 #include <netatm/atm_if.h>
47 #include <netatm/atm_sap.h>
48 #include <netatm/atm_sys.h>
49 #include <netatm/atm_ioctl.h>
70 * Issue an informational IOCTL
72 * The user fills out the opcode and any subtype information. This
73 * routine will allocate a buffer and issue the IOCTL. If the request
74 * fails because the buffer wasn't big enough, this routine will double
75 * the buffer size and retry the request repeatedly. The buffer must
76 * be freed by the caller.
79 * req pointer to an ATM information request IOCTL structure
80 * buf_len length of buffer to be allocated
83 * -1 error encountered (reason in errno)
84 * int length of the returned VCC information
88 do_info_ioctl(req
, buf_len
)
89 struct atminfreq
*req
;
96 * Open a socket for the IOCTL
98 s
= socket(AF_ATM
, SOCK_DGRAM
, 0);
104 * Get memory for returned information
107 buf
= (caddr_t
)UM_ALLOC(buf_len
);
114 * Set the buffer address and length in the request
116 req
->air_buf_addr
= buf
;
117 req
->air_buf_len
= buf_len
;
122 rc
= ioctl(s
, AIOCINFO
, (caddr_t
)req
);
125 if (errno
== ENOSPC
) {
126 buf_len
= buf_len
* 2;
133 * Set a pointer to the returned info in the request
134 * and return its length
136 req
->air_buf_addr
= buf
;
137 return(req
->air_buf_len
);
142 * Get VCC information
145 * intf pointer to interface name (or null string)
146 * vccp pointer to a pointer to a struct air_vcc_rsp for the
147 * address of the returned VCC information
150 * int length of the retuned VCC information
154 get_vcc_info(intf
, vccp
)
156 struct air_vcc_rsp
**vccp
;
158 int buf_len
= sizeof(struct air_vcc_rsp
) * 100;
159 struct atminfreq air
;
162 * Initialize IOCTL request
164 air
.air_opcode
= AIOCS_INF_VCC
;
165 UM_ZERO(air
.air_vcc_intf
, sizeof(air
.air_vcc_intf
));
166 if (intf
!= NULL
&& strlen(intf
) != 0)
167 strlcpy(air
.air_vcc_intf
, intf
, IFNAMSIZ
);
169 buf_len
= do_info_ioctl(&air
, buf_len
);
172 * Return a pointer to the VCC info and its length
174 *vccp
= (struct air_vcc_rsp
*) air
.air_buf_addr
;
183 * intf pointer to an interface name
184 * mask pointer to a struct sockaddr_in to receive the mask
192 get_subnet_mask(intf
, mask
)
194 struct sockaddr_in
*mask
;
198 struct sockaddr_in
*ip_mask
;
203 if (!intf
|| !mask
||
205 strlen(intf
) > IFNAMSIZ
-1)
209 * Open a socket for the IOCTL
211 s
= socket(AF_INET
, SOCK_DGRAM
, 0);
216 * Set up and issue the IOCTL
218 UM_ZERO(&req
, sizeof(req
));
219 strlcpy(req
.ifr_name
, intf
, sizeof(req
.ifr_name
));
220 rc
= ioctl(s
, SIOCGIFNETMASK
, (caddr_t
)&req
);
226 * Give the answer back to the caller
228 ip_mask
= (struct sockaddr_in
*)&req
.ifr_addr
;
230 mask
->sin_family
= AF_INET
;
237 * Get an interface's MTU
240 * intf pointer to an interface name
241 * mtu pointer to an int to receive the MTU
258 if (!intf
|| strlen(intf
) == 0 ||
259 strlen(intf
) > IFNAMSIZ
-1)
263 * Open a socket for the IOCTL
265 s
= socket(AF_INET
, SOCK_DGRAM
, 0);
270 * Set up and issue the IOCTL
272 UM_ZERO(&req
, sizeof(req
));
273 strlcpy(req
.ifr_name
, intf
, sizeof(req
.ifr_name
));
274 rc
= ioctl(s
, SIOCGIFMTU
, (caddr_t
)&req
);
278 * Set the appropriate return value
290 * This routine issues an IOCTL to check whether the passed string is
291 * a valid network interface name.
294 * req pointer to an ATM information request IOCTL structure
297 * -1 error encountered
298 * FALSE (0) the string is not a NIF name
299 * TRUE (> 0) the string is a valid NIF name
303 verify_nif_name(name
)
307 struct atminfreq air
;
308 struct air_netif_rsp
*nif_info
;
311 * Check whether name is of a valid length
313 if (strlen(name
) > IFNAMSIZ
- 1 ||
319 * Open a socket for the IOCTL
321 s
= socket(AF_ATM
, SOCK_DGRAM
, 0);
327 * Get memory for returned information
329 nif_info
= (struct air_netif_rsp
*)UM_ALLOC(
330 sizeof(struct air_netif_rsp
));
331 if (nif_info
== NULL
) {
339 air
.air_opcode
= AIOCS_INF_NIF
;
340 air
.air_buf_addr
= (caddr_t
)nif_info
;
341 air
.air_buf_len
= sizeof(struct air_netif_rsp
);
342 UM_ZERO(air
.air_netif_intf
, sizeof(air
.air_netif_intf
));
343 strlcpy(air
.air_netif_intf
, name
, sizeof(air
.air_netif_intf
));
348 rc
= ioctl(s
, AIOCINFO
, (caddr_t
)&air
);
353 * Base return value on IOCTL return code
362 * Get Config information
365 * intf pointer to interface name (or null string)
366 * cfgp pointer to a pointer to a struct air_cfg_rsp for the
367 * address of the returned Config information
370 * int length of returned Config information
374 get_cfg_info ( intf
, cfgp
)
376 struct air_cfg_rsp
**cfgp
;
378 int buf_len
= sizeof(struct air_cfg_rsp
) * 4;
379 struct atminfreq air
;
382 * Initialize IOCTL request
384 air
.air_opcode
= AIOCS_INF_CFG
;
385 UM_ZERO ( air
.air_cfg_intf
, sizeof(air
.air_cfg_intf
));
386 if ( intf
!= NULL
&& strlen(intf
) != 0 )
387 strlcpy ( air
.air_cfg_intf
, intf
, IFNAMSIZ
);
389 buf_len
= do_info_ioctl ( &air
, buf_len
);
392 * Return a pointer to the Config info and its length
394 *cfgp
= (struct air_cfg_rsp
*) air
.air_buf_addr
;
400 * Get Physical Interface information
403 * intf pointer to interface name (or null string)
404 * intp pointer to a pointer to a struct air_cfg_rsp for the
405 * address of the returned Config information
408 * int length of returned Config information
412 get_intf_info ( intf
, intp
)
414 struct air_int_rsp
**intp
;
416 int buf_len
= sizeof(struct air_int_rsp
) * 4;
417 struct atminfreq air
;
420 * Initialize IOCTL request
422 air
.air_opcode
= AIOCS_INF_INT
;
423 UM_ZERO ( air
.air_int_intf
, sizeof(air
.air_int_intf
));
424 if ( intf
!= NULL
&& strlen(intf
) != 0 )
425 strlcpy ( air
.air_int_intf
, intf
, IFNAMSIZ
);
427 buf_len
= do_info_ioctl ( &air
, buf_len
);
430 * Return a pointer to the Physical Interface info and its length
432 *intp
= (struct air_int_rsp
*) air
.air_buf_addr
;
439 * Get Netif information
442 * intf pointer to interface name (or null string)
443 * netp pointer to a pointer to a struct air_netif_rsp for the
444 * address of the returned Netif information
447 * int length of returned Netif information
451 get_netif_info ( intf
, netp
)
453 struct air_netif_rsp
**netp
;
455 int buf_len
= sizeof(struct air_netif_rsp
) * 10;
456 struct atminfreq air
;
459 * Initialize IOCTL request
461 air
.air_opcode
= AIOCS_INF_NIF
;
462 UM_ZERO ( air
.air_int_intf
, sizeof(air
.air_int_intf
) );
463 if ( intf
!= NULL
&& strlen(intf
) != 0 )
464 strlcpy ( air
.air_int_intf
, intf
, IFNAMSIZ
);
466 buf_len
= do_info_ioctl ( &air
, buf_len
);
469 * Return a pointer to the Netif info and its length
471 *netp
= (struct air_netif_rsp
*) air
.air_buf_addr
;