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.
31 * User configuration and display program
32 * --------------------------------------
38 #include <sys/types.h>
39 #include <sys/param.h>
40 #include <sys/socket.h>
42 #include <netinet/in.h>
43 #include <netatm/port.h>
44 #include <netatm/atm.h>
45 #include <netatm/atm_if.h>
46 #include <netatm/atm_sap.h>
47 #include <netatm/atm_sys.h>
48 #include <netatm/atm_ioctl.h>
49 #include <arpa/inet.h>
60 __RCSID("@(#) $FreeBSD$");
65 * Table entry definition
74 * Table to translate vendor codes to ASCII
77 { VENDAPI_UNKNOWN, "Unknown" },
78 { VENDAPI_FORE_1, "Fore" },
79 { VENDAPI_ENI_1, "ENI" },
85 * Table to translate adapter codes to ASCII
87 tbl_ent adapter_types[] = {
88 { DEV_UNKNOWN, "Unknown" },
89 { DEV_FORE_SBA200E, "SBA-200E" },
90 { DEV_FORE_SBA200, "SBA-200" },
91 { DEV_FORE_PCA200E, "PCA-200E" },
92 { DEV_ENI_155P, "ENI-155p" },
97 * Table to translate medium types to ASCII
99 tbl_ent media_types[] = {
100 { MEDIA_UNKNOWN, "Unknown" },
101 { MEDIA_TAXI_100, "100 Mbps 4B/5B" },
102 { MEDIA_TAXI_140, "140 Mbps 4B/5B" },
103 { MEDIA_OC3C, "OC-3c" },
104 { MEDIA_OC12C, "OC-12c" },
105 { MEDIA_UTP155, "155 Mbps UTP" },
110 * Table to translate bus types to ASCII
112 tbl_ent bus_types[] = {
113 { BUS_UNKNOWN, "Unknown" },
114 { BUS_SBUS_B16, "SBus" },
115 { BUS_SBUS_B32, "SBus" },
122 * Get interface vendor name
124 * Return a character string with a vendor name, given a vendor code.
130 * char * pointer to a string with the vendor name
139 for(i=0; vendors[i].name; i++) {
140 if (vendors[i].type == vendor)
141 return(vendors[i].name);
155 * char * pointer to a string with the adapter type
164 for(i=0; adapter_types[i].name; i++) {
165 if (adapter_types[i].type == dev)
166 return(adapter_types[i].name);
174 * Get communication medium type
180 * char * pointer to a string with the name of the medium
184 get_media_type(media)
189 for(i=0; media_types[i].name; i++) {
190 if (media_types[i].type == media)
191 return(media_types[i].name);
205 * char * pointer to a string with the bus type
214 for(i=0; bus_types[i].name; i++) {
215 if (bus_types[i].type == bus)
216 return(bus_types[i].name);
226 * Get a string giving the adapter's vendor and type.
229 * intf interface name
232 * char * pointer to a string identifying the adapter
236 get_adapter_name(intf)
240 struct atminfreq air;
241 struct air_cfg_rsp *cfg;
242 static char name[256];
247 UM_ZERO(&air, sizeof(air));
248 UM_ZERO(name, sizeof(name));
251 * Get configuration information from the kernel
253 air.air_opcode = AIOCS_INF_CFG;
254 strcpy(air.air_cfg_intf, intf);
255 buf_len = do_info_ioctl(&air, sizeof(struct air_cfg_rsp));
256 if (buf_len < sizeof(struct air_cfg_rsp))
258 cfg = (struct air_cfg_rsp *) air.air_buf_addr;
261 * Build a string describing the adapter
263 strcpy(name, get_vendor(cfg->acp_vendor));
265 strcat(name, get_adapter(cfg->acp_device));
274 * Format a MAC address into a string
277 * addr pointer to a MAC address
280 * the address of a string representing the MAC address
284 format_mac_addr(addr)
287 static char str[256];
290 * Check for null pointer
296 * Clear the returned string
298 UM_ZERO(str, sizeof(str));
303 sprintf(str, "%02x:%02x:%02x:%02x:%02x:%02x",
316 * Parse an IP prefix designation in the form nnn.nnn.nnn.nnn/mm
319 * cp pointer to prefix designation string
320 * op pointer to a pair of in_addrs for the result
324 * -1 prefix was invalid
328 parse_ip_prefix(cp, op)
334 struct in_addr ip_addr;
336 static u_long masks[33] = {
373 * Find the slash that marks the start of the mask
375 mp = strchr(cp, '/');
382 * Convert the IP-address part of the prefix
384 ip_addr.s_addr = inet_addr(cp);
385 if (ip_addr.s_addr == -1)
389 * Set the default mask length
391 if (IN_CLASSA(ntohl(ip_addr.s_addr)))
393 else if (IN_CLASSB(ntohl(ip_addr.s_addr)))
395 else if (IN_CLASSC(ntohl(ip_addr.s_addr)))
401 * Get the mask length
405 if (len < 1 || len > 32)
410 * Select the mask and copy the IP address into the
411 * result buffer, ANDing it with the mask
413 op[1].s_addr = htonl(masks[len]);
414 op[0].s_addr = ip_addr.s_addr & op[1].s_addr;
421 * Compress a list of IP network prefixes
424 * ipp pointer to list of IP address/mask pairs
428 * length of compressed list
432 compress_prefix_list(ipp, ilen)
437 struct in_addr *ip1, *ip2, *m1, *m2;
440 * Figure out how many pairs there are
442 n = ilen / (sizeof(struct in_addr) * 2);
445 * Check each pair of address/mask pairs to make sure
446 * none contains the other
448 for (i = 0; i < n; i++) {
453 * If we've already eliminated this address,
456 if (ip1->s_addr == 0)
460 * Try all possible second members of the pair
462 for (j = i + 1; j < n; j++) {
467 * If we've already eliminated the second
468 * address, just skip the checks
470 if (ip2->s_addr == 0)
474 * Compare the address/mask pairs
476 if (m1->s_addr == m2->s_addr) {
480 if (ip1->s_addr == ip2->s_addr) {
484 } else if (ntohl(m1->s_addr) <
489 if ((ip2->s_addr & m1->s_addr) ==
498 if ((ip1->s_addr & m2->s_addr) ==
509 * Now pull up the list, eliminating zeroed entries
511 for (i = 0, j = 0; i < n; i++) {
516 if (ip1->s_addr != 0) {
525 return(j * sizeof(struct in_addr) * 2);
530 * Make sure a user-supplied parameter is a valid network interface
533 * When a socket call fails, print an error message and exit
536 * nif pointer to network interface name
539 * none exits if name is not valid
543 check_netif_name(nif)
549 * Look up the name in the kernel
551 rc = verify_nif_name(nif);
561 } else if (rc == 0) {
565 fprintf(stderr, "%s: Invalid network interface name %s\n",
569 * Error performing IOCTL
571 fprintf(stderr, "%s: ", prog);
575 perror("Internal error");
578 fprintf(stderr, "%s is not an ATM device\n",
582 perror("ioctl (AIOCINFO)");
592 * Socket error handler
594 * When a socket call fails, print an error message and exit
597 * err an errno describing the error
607 fprintf(stderr, "%s: ", prog);
611 case EPROTONOSUPPORT:
612 fprintf(stderr, "ATM protocol support not loaded\n");