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.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
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(struct atminfreq *req, size_t buf_len)
94 * Open a socket for the IOCTL
96 s = socket(AF_ATM, SOCK_DGRAM, 0);
102 * Get memory for returned information
105 buf = malloc(buf_len);
113 * Set the buffer address and length in the request
115 req->air_buf_addr = buf;
116 req->air_buf_len = buf_len;
121 rc = ioctl(s, AIOCINFO, (caddr_t)req);
124 if (errno == ENOSPC) {
125 buf_len = buf_len * 2;
132 * Set a pointer to the returned info in the request
133 * and return its length
135 req->air_buf_addr = buf;
136 return(req->air_buf_len);
141 * Get VCC information
144 * intf pointer to interface name (or null string)
145 * vccp pointer to a pointer to a struct air_vcc_rsp for the
146 * address of the returned VCC information
149 * int length of the retuned VCC information
153 get_vcc_info(const char *intf, struct air_vcc_rsp **vccp)
155 size_t buf_len = sizeof(struct air_vcc_rsp) * 100;
156 struct atminfreq air;
159 * Initialize IOCTL request
161 air.air_opcode = AIOCS_INF_VCC;
162 bzero(air.air_vcc_intf, sizeof(air.air_vcc_intf));
163 if (intf != NULL && strlen(intf) != 0)
164 strncpy(air.air_vcc_intf, intf, IFNAMSIZ - 1);
166 buf_len = do_info_ioctl(&air, buf_len);
169 * Return a pointer to the VCC info and its length
171 *vccp = (struct air_vcc_rsp *)(void *)air.air_buf_addr;
180 * intf pointer to an interface name
181 * mask pointer to a struct sockaddr_in to receive the mask
189 get_subnet_mask(const char *intf, struct sockaddr_in *mask)
193 struct sockaddr_in *ip_mask;
198 if (!intf || !mask ||
200 strlen(intf) > IFNAMSIZ-1)
204 * Open a socket for the IOCTL
206 s = socket(AF_INET, SOCK_DGRAM, 0);
211 * Set up and issue the IOCTL
213 bzero(&req, sizeof(req));
214 strcpy(req.ifr_name, intf);
215 rc = ioctl(s, SIOCGIFNETMASK, (caddr_t)&req);
221 * Give the answer back to the caller
223 ip_mask = (struct sockaddr_in *)(void *)&req.ifr_addr;
225 mask->sin_family = AF_INET;
232 * Get an interface's MTU
235 * intf pointer to an interface name
236 * mtu pointer to an int to receive the MTU
244 get_mtu(const char *intf)
252 if (!intf || strlen(intf) == 0 ||
253 strlen(intf) > IFNAMSIZ-1)
257 * Open a socket for the IOCTL
259 s = socket(AF_INET, SOCK_DGRAM, 0);
264 * Set up and issue the IOCTL
266 bzero(&req, sizeof(req));
267 strcpy(req.ifr_name, intf);
268 rc = ioctl(s, SIOCGIFMTU, (caddr_t)&req);
272 * Set the appropriate return value
284 * This routine issues an IOCTL to check whether the passed string is
285 * a valid network interface name.
288 * req pointer to an ATM information request IOCTL structure
291 * -1 error encountered
292 * FALSE (0) the string is not a NIF name
293 * TRUE (> 0) the string is a valid NIF name
297 verify_nif_name(const char *name)
300 struct atminfreq air;
301 struct air_netif_rsp *nif_info;
304 * Check whether name is of a valid length
306 if (strlen(name) > IFNAMSIZ - 1 ||
312 * Open a socket for the IOCTL
314 s = socket(AF_ATM, SOCK_DGRAM, 0);
320 * Get memory for returned information
322 nif_info = malloc(sizeof(struct air_netif_rsp));
323 if (nif_info == NULL) {
327 bzero(nif_info, sizeof(struct air_netif_rsp));
332 air.air_opcode = AIOCS_INF_NIF;
333 air.air_buf_addr = (caddr_t)nif_info;
334 air.air_buf_len = sizeof(struct air_netif_rsp);
335 bzero(air.air_netif_intf, sizeof(air.air_netif_intf));
336 strcpy(air.air_netif_intf, name);
341 rc = ioctl(s, AIOCINFO, (caddr_t)&air);
346 * Base return value on IOCTL return code
355 * Get Config information
358 * intf pointer to interface name (or null string)
359 * cfgp pointer to a pointer to a struct air_cfg_rsp for the
360 * address of the returned Config information
363 * int length of returned Config information
367 get_cfg_info(const char *intf, struct air_cfg_rsp **cfgp)
369 size_t buf_len = sizeof(struct air_cfg_rsp) * 4;
370 struct atminfreq air;
373 * Initialize IOCTL request
375 air.air_opcode = AIOCS_INF_CFG;
376 bzero ( air.air_cfg_intf, sizeof(air.air_cfg_intf));
377 if ( intf != NULL && strlen(intf) != 0 )
378 strncpy(air.air_cfg_intf, intf, IFNAMSIZ - 1);
380 buf_len = do_info_ioctl ( &air, buf_len );
383 * Return a pointer to the Config info and its length
385 *cfgp = (struct air_cfg_rsp *)(void *)air.air_buf_addr;
391 * Get Physical Interface information
394 * intf pointer to interface name (or null string)
395 * intp pointer to a pointer to a struct air_cfg_rsp for the
396 * address of the returned Config information
399 * int length of returned Config information
403 get_intf_info(const char *intf, struct air_int_rsp **intp)
405 size_t buf_len = sizeof(struct air_int_rsp) * 4;
406 struct atminfreq air;
409 * Initialize IOCTL request
411 air.air_opcode = AIOCS_INF_INT;
412 bzero ( air.air_int_intf, sizeof(air.air_int_intf));
413 if ( intf != NULL && strlen(intf) != 0 )
414 strncpy(air.air_int_intf, intf, IFNAMSIZ - 1);
416 buf_len = do_info_ioctl ( &air, buf_len );
419 * Return a pointer to the Physical Interface info and its length
421 *intp = (struct air_int_rsp *)(void *)air.air_buf_addr;
428 * Get Netif information
431 * intf pointer to interface name (or null string)
432 * netp pointer to a pointer to a struct air_netif_rsp for the
433 * address of the returned Netif information
436 * int length of returned Netif information
440 get_netif_info(const char *intf, struct air_netif_rsp **netp)
442 size_t buf_len = sizeof(struct air_netif_rsp) * 10;
443 struct atminfreq air;
446 * Initialize IOCTL request
448 air.air_opcode = AIOCS_INF_NIF;
449 bzero ( air.air_int_intf, sizeof(air.air_int_intf) );
450 if ( intf != NULL && strlen(intf) != 0 )
451 strncpy(air.air_int_intf, intf, IFNAMSIZ - 1);
453 buf_len = do_info_ioctl ( &air, buf_len );
456 * Return a pointer to the Netif info and its length
458 *netp = (struct air_netif_rsp *) air.air_buf_addr;