static void printit(const struct ifmibdata *ifmd, const char *dname) { printf("Interface %.*s", IFNAMSIZ, ifmd->ifmd_name); if (dname != NULL) printf(" (%s)", dname); printf(":\n"); printf("\tflags: %x\n", ifmd->ifmd_flags); printf("\tpromiscuous listeners: %d\n", ifmd->ifmd_pcount); printf("\tsend queue length: %d\n", ifmd->ifmd_snd_len); printf("\tsend queue max length: %d\n", ifmd->ifmd_snd_maxlen); printf("\tsend queue drops: %d\n", ifmd->ifmd_snd_drops); printf("\ttype: %s\n", iftype(ifmd->ifmd_data.ifi_type)); printf("\tphysical: %s\n", ifphys(ifmd->ifmd_data.ifi_type, ifmd->ifmd_data.ifi_physical)); printf("\taddress length: %d\n", ifmd->ifmd_data.ifi_addrlen); printf("\theader length: %d\n", ifmd->ifmd_data.ifi_hdrlen); printf("\tlink state: %u\n", ifmd->ifmd_data.ifi_link_state); printf("\tvhid: %u\n", ifmd->ifmd_data.ifi_vhid); printf("\tdatalen: %u\n", ifmd->ifmd_data.ifi_datalen); printf("\tmtu: %lu\n", ifmd->ifmd_data.ifi_mtu); printf("\tmetric: %lu\n", ifmd->ifmd_data.ifi_metric); printf("\tline rate: %lu bit/s\n", ifmd->ifmd_data.ifi_baudrate); printf("\tpackets received: %lu\n", ifmd->ifmd_data.ifi_ipackets); printf("\tinput errors: %lu\n", ifmd->ifmd_data.ifi_ierrors); printf("\tpackets transmitted: %lu\n", ifmd->ifmd_data.ifi_opackets); printf("\toutput errors: %lu\n", ifmd->ifmd_data.ifi_oerrors); printf("\tcollisions: %lu\n", ifmd->ifmd_data.ifi_collisions); printf("\tbytes received: %lu\n", ifmd->ifmd_data.ifi_ibytes); printf("\tbytes transmitted: %lu\n", ifmd->ifmd_data.ifi_obytes); printf("\tmulticasts received: %lu\n", ifmd->ifmd_data.ifi_imcasts); printf("\tmulticasts transmitted: %lu\n", ifmd->ifmd_data.ifi_omcasts); printf("\tinput queue drops: %lu\n", ifmd->ifmd_data.ifi_iqdrops); printf("\tpackets for unknown protocol: %lu\n", ifmd->ifmd_data.ifi_noproto); printf("\tHW offload capabilities: 0x%lx\n", ifmd->ifmd_data.ifi_hwassist); printf("\tuptime at attach or stat reset: %lu\n", ifmd->ifmd_data.ifi_epoch); #ifdef notdef printf("\treceive timing: %lu usec\n", ifmd->ifmd_data.ifi_recvtiming); printf("\ttransmit timing: %lu usec\n", ifmd->ifmd_data.ifi_xmittiming); #endif }
void DllExport gettme ( char *fname, TInt4 *itype, double *timdef, TInt4 *maxdef, TInt4 *pardep, TInt4 *locdep, TInt4 *maxlst, double *timlst, TInt4 *timtyp, TInt4 *nrlst, TInt4 *ierror, char *option) /*************************************************************************/ /* */ /* Arguments: */ /* */ /* Name Size I/O Description */ /* ------ -------- --- ------------------------------------ */ /* fname - I Full filename, including extension */ /* ierror - O Errorcode, see errors.inc for definitio */ /* itype - I/O Filetype, see types.inc for definitions */ /* len. - I UNIX only: length of CHARACTER variable */ /* locdep - I location dependency of times. */ /* maxdef - I Max. nr of times wanted. */ /* maxlst - I Max. nr of times to return. */ /* nrlst - O Nr of times returned. */ /* option - I/O option (reserved for future extensions) */ /* pardep - I parameter dependency of timesteps */ /* timdef 2,maxdef I List of times wanted. */ /* timtyp maxlst O list of time types. */ /* timlst maxlst O List of times found. */ /* */ /*************************************************************************/ { int i, inum , length ; char *fn; *ierror = IEOK; /* strip trailing blanks and add terminating 0 to all strings, just to make sure: */ for (inum = 0 ; inum < ODS_FNAME_DIM ; inum++) { fn = &fname[inum*ODS_FILNAMLEN] ; fn[ODS_FILNAMLEN-1] = '\0' ; length = strlen( fn ) ; for ( i = length-1 ; i >= 0 ; i -- ) { if ( fn[i] == ' ') { fn[i] = '\0' ; } else { break ; } } } *nrlst = 0 ; /* Get filetype, if we don't know, first check extension: */ if ( *itype == ITUNDE) *itype = iftype ( fname) ; /* Now proceed: */ switch ( *itype) { case ITUNDE : /* Unable to determine filetype */ *ierror = IEUNDE ; break ; #if 0 case ITDBF3 : case ITDBF4 : /* DBASE 3/4 filetype */ ODSGetTmeDbf3 ( fname , timdef, *maxdef, timlst, *maxlst, nrlst , ierror) ; break ; #endif case ODS_DELWAQ_MAP_BIN : case ODS_DELWAQ_HIS_BIN : case ODS_DELWAQ_BAL_BIN : case ODS_DELPAR_PLO_BIN : /* DELWAQ 3 MAP/HIS file, DELPAR PLO file */ ODSGetTmeDlwq ( fname, itype, timdef, *maxdef, *pardep, timlst, *maxlst, nrlst , ierror) ; break ; case ODS_DELWAQ_HIS_NEFIS : case ODS_DELWAQ_MAP_NEFIS : case ODS_DELPAR_HIS_NEFIS : case ODS_DELPAR_MAP_NEFIS : case ODS_DELPAR_PLO_NEFIS : /* DELWAQ/DELPAR NEFIS filetype */ DlwGetNefisTme ( fname, itype, timdef, maxdef, timlst, maxlst, nrlst, ierror, option ); break ; case ITWAS : /* WASPRO WAS file */ ODSGetTmeWas ( fname , timdef, *maxdef, timlst, *maxlst, nrlst , ierror) ; break ; case ITWS1 : /* WASPRO WS1 file */ ODSGetTmeWs1 ( fname , timdef, *maxdef, timlst, *maxlst, nrlst , ierror) ; break ; case ITMPX : /* MAPPIX file */ ODSGetTmeMPX ( fname , timdef, *maxdef, timlst, *maxlst, nrlst , ierror) ; break ; case ODS_TRISULA_HIS_NEFIS : /* Trisula Nefis history file */ GNF_GetTme( fname, itype, timdef, maxdef, pardep, locdep, maxlst, timlst, timtyp, nrlst, ierror, option ) ; break ; case ODS_TRISULA_MAP_NEFIS : /* Trisula Nefis map file */ GNF_GetTme( fname, itype, timdef, maxdef, pardep, locdep, maxlst, timlst, timtyp, nrlst, ierror, option ) ; break ; case ODS_TRISULA_DRO_NEFIS : case ODS_DELPAR_TRK_NEFIS : /* Trisula Nefis drogues file */ TriDroGetTme( fname, itype, timdef, maxdef, pardep, locdep, maxlst, timlst, timtyp, nrlst, ierror, option ) ; break ; case ODS_SAMPLES_2D : case ODS_SAMPLES_TABLE : case ODS_SAMPLES_TIME : /* Samples file (2D or table) */ SamplesGetTme( fname, itype, timdef, maxdef, pardep, locdep, maxlst, timlst, timtyp, nrlst, ierror, option ) ; break ; case ODS_MORSYS_MAP_NEFIS : /* Morsys Nefis com file */ GNF_GetTme( fname, itype, timdef, maxdef, pardep, locdep, maxlst, timlst, timtyp, nrlst, ierror, option ) ; break ; case ODS_MORSYS_TRAM_NEFIS : /* Morsys Nefis tram file */ GNF_GetTme( fname, itype, timdef, maxdef, pardep, locdep, maxlst, timlst, timtyp, nrlst, ierror, option ) ; break ; case ODS_MORSYS_HWBOD : /* Morsys Nefis com file */ ODS_MORSYS_NEFIS_COMTME( fname, 256, 3, *itype, (TReal8 *) timdef, *maxdef, *pardep, *locdep, *maxlst, (TReal8 *) timlst, (TInt4 *) timtyp, (TInt4 *) nrlst, (TInt4 *) ierror, option ); break ; case ODS_MORSYS_HWGXY : /* Morsys Nefis com file */ ODS_MORSYS_NEFIS_COMTME( fname, 256, 3, *itype, (TReal8 *) timdef, *maxdef, *pardep, *locdep, *maxlst, (TReal8 *) timlst, (TInt4 *) timtyp, (TInt4 *) nrlst, (TInt4 *) ierror, option ); break ; case ODS_MORSYS_SWAN_NEFIS : GNF_GetTme( fname, itype, timdef, maxdef, pardep, locdep, maxlst, timlst, timtyp, nrlst, ierror, option ) ; break ; case ODS_MORSYS_TRAH_NEFIS : GNF_GetTme( fname, itype, timdef, maxdef, pardep, locdep, maxlst, timlst, timtyp, nrlst, ierror, option ) ; break ; case ODS_MORSYS_BAGR_NEFIS : /* Morsys Nefis BAGR file (dredging) */ MorOdsGetTme ( fname, itype, timdef, maxdef, timlst, maxlst, nrlst, ierror, option ); break ; case ODS_ANY_TEKAL_ASCII_1D : case ODS_ANY_TEKAL_ASCII_1DE : /* TEKAL ASCII 1D files */ ODSGetTmeAnyTekAscHis ( fname , itype, timdef, *maxdef, *pardep, *locdep, timlst, *maxlst, nrlst, ierror, option ) ; break ; case ODS_ANY_TEKAL_ASCII_2D : case ODS_ANY_TEKAL_ASCII_VEC : /* TEKAL ASCII 2D files ( scalar and vector ) */ ODSGetTmeAnyTekAscMap ( fname , itype, timdef, *maxdef, *pardep, *locdep, timlst, *maxlst, nrlst, ierror, option ) ; break ; case ODS_ANY_TEKAL_ASCII_ANNO : /* TEKAL ASCII Annotation files (text at specified location) */ ODSGetTmeTekAnno ( fname , itype, timdef, *maxdef, *pardep, *locdep, timlst, *maxlst, nrlst, ierror, option ) ; break ; case ODS_ANY_JSPOST : /* JSPost files */ ODSGetTmeJSP ( fname, timdef, *maxdef, timlst, *maxlst, nrlst, timtyp, ierror, option ) ; break ; case ODS_DELWAQ_GRID_UNF : case ODS_DELWAQ_TELEMAC : /* DELWAQ/DELPAR grid files (List will have length zero) */ ODSGetTmeDlwg ( fname, itype, *timdef, *maxdef, *pardep, *locdep, timlst, *maxlst, nrlst , ierror, option ) ; break ; case ODS_SHYFEM_GRID : /* SHYFEM grid files (List will have length zero) */ ODSGetTmeShyf ( fname, (TInt4 *) itype, *timdef, *maxdef, *pardep, *locdep, timlst, *maxlst, (TInt4 *) nrlst , (TInt4 *) ierror, option ) ; break ; case ODS_PHAROS_MAP_NEFIS : case ODS_PHAROS_AMP_NEFIS : /* Pharos Nefis admin file */ ODSGetTmePharAmp( fname, (TInt4 *) itype, timdef, *maxdef, *pardep, *locdep, timlst, *maxlst, (TInt4 *) nrlst, (TInt4 *) ierror, option ) ; break ; case ODS_PHIDIAS_MAP : case ODS_PHIDIAS_HISTORY : /* Phidias Nefis map file */ ODSGetTmePhiMap( fname, 256, 3, *itype, (TReal8 *) timdef, *maxdef, *pardep, *locdep, *maxlst, (TReal8 *) timlst, (TInt4 *) timtyp, (TInt4 *) nrlst, (TInt4 *) ierror, option ); break ; case ODS_PHIDIAS_SPECTRAL: /* Phidias Nefis spectral file */ ODSGetTmePhiSpec( fname, 256, 3, *itype, (TReal8 *) timdef, *maxdef, *pardep, *locdep, *maxlst, (TReal8 *) timlst, (TInt4 *) timtyp, (TInt4 *) nrlst, (TInt4 *) ierror, option ); break ; case ODS_GEOGR_BNA: case ODS_GEOGR_DXF: case ODS_GEOGR_TEKAL: /* BNA, DXF and TEKAL landboundary files */ ODS_BNA_gettme( fname, itype, timdef, maxdef, pardep, locdep, maxlst, timlst, timtyp, nrlst, ierror, option ) ; break ; default : /* Filetype not implemented: */ *ierror = IEUNKN ; } if ( *ierror == IEPMNY) *ierror = IETMNY ; return ; }
int show_int(int argc, char **argv) { struct ifaddrs *ifap, *ifa; struct if_nameindex *ifn_list, *ifnp; struct ifreq ifr, ifrdesc; struct if_data if_data; struct sockaddr_in sin, sin2, sin3; struct timeval tv; struct vlanreq vreq; short tmp; int ifs, br, flags, days, hours, mins, pntd; int ippntd = 0; time_t c; char *type, *lladdr, *ifname = NULL; const char *carp; char tmp_str[512], tmp_str2[512], ifdescr[IFDESCRSIZE]; if (argc == 3) ifname = argv[2]; /* * Show all interfaces when no ifname specified. */ if (ifname == NULL) { if ((ifn_list = if_nameindex()) == NULL) { printf("%% show_int: if_nameindex failed\n"); return 1; } for (ifnp = ifn_list; ifnp->if_name != NULL; ifnp++) { char *args[] = { NULL, NULL, ifnp->if_name }; show_int(3, args); } if_freenameindex(ifn_list); return(0); } else if (!is_valid_ifname(ifname)) { printf("%% interface %s not found\n", ifname); return(1); } if ((ifs = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { printf("%% show_int: %s\n", strerror(errno)); return(1); } if (!(br = is_bridge(ifs, (char *)ifname))) br = 0; strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); /* * Show up/down status and last change time */ flags = get_ifflags(ifname, ifs); ifr.ifr_data = (caddr_t)&if_data; if (ioctl(ifs, SIOCGIFDATA, (caddr_t)&ifr) < 0) { printf("%% show_int: SIOCGIFDATA: %s\n", strerror(errno)); close(ifs); return(1); } printf("%% %s", ifname); /* description */ memset(&ifrdesc, 0, sizeof(ifrdesc)); strlcpy(ifrdesc.ifr_name, ifname, sizeof(ifrdesc.ifr_name)); ifrdesc.ifr_data = (caddr_t)&ifdescr; if (ioctl(ifs, SIOCGIFDESCR, &ifrdesc) == 0 && strlen(ifrdesc.ifr_data)) printf(" (%s)", ifrdesc.ifr_data); putchar('\n'); printf(" %s is %s", br ? "Bridge" : "Interface", flags & IFF_UP ? "up" : "down"); if (if_lastchange.tv_sec) { gettimeofday(&tv, (struct timezone *)0); c = difftime(tv.tv_sec, if_lastchange.tv_sec); days = c / SECSPERDAY; c %= SECSPERDAY; hours = c / SECSPERHOUR; c %= SECSPERHOUR; mins = c / SECSPERMIN; c %= SECSPERMIN; printf(" (last change "); if (days) printf("%id ", days); printf("%02i:%02i:%02i)", hours, mins, c); } printf(", protocol is %s", flags & IFF_RUNNING ? "up" : "down"); printf("\n"); type = iftype(if_type); printf(" Interface type %s", type); if (flags & IFF_BROADCAST) printf(" (Broadcast)"); else if (flags & IFF_POINTOPOINT) printf(" (PointToPoint)"); if ((lladdr = get_hwdaddr(ifname)) != NULL) printf(", hardware address %s", lladdr); printf("\n"); media_status(ifs, ifname, " Media type "); /* * Print interface IP address, and broadcast or * destination if available. But, don't print broadcast * if it is what we would expect given the ip and netmask! */ if (getifaddrs(&ifap) != 0) { printf("%% show_int: getifaddrs failed: %s\n", strerror(errno)); return(1); } /* * Cycle through getifaddrs for interfaces with our * desired name that sport AF_INET, print the IP and * related information. */ for (ifa = ifap; ifa; ifa = ifa->ifa_next) { if (strncmp(ifname, ifa->ifa_name, IFNAMSIZ)) continue; if (ifa->ifa_addr->sa_family != AF_INET) continue; memcpy(&sin, ifa->ifa_addr, sizeof(struct sockaddr_in)); memcpy(&sin2, ifa->ifa_netmask, sizeof(struct sockaddr_in)); if (sin.sin_addr.s_addr == 0 || sin2.sin_addr.s_addr == 0) continue; if (!ippntd) printf(" Internet address"); printf("%s %s", ippntd ? "," : "", netname4(sin.sin_addr.s_addr, &sin2)); ippntd = 1; if (flags & IFF_POINTOPOINT) { memcpy(&sin3, ifa->ifa_dstaddr, sizeof(struct sockaddr_in)); printf(" (Destination %s)", inet_ntoa(sin3.sin_addr)); } else if (flags & IFF_BROADCAST) { memcpy(&sin3, ifa->ifa_broadaddr, sizeof(struct sockaddr_in)); /* * no reason to show the broadcast addr * if it is standard (this should always * be true unless someone has messed up their * network or they are playing around...) */ if (ntohl(sin3.sin_addr.s_addr) != in4_brdaddr(sin.sin_addr.s_addr, sin2.sin_addr.s_addr)) printf(" (Broadcast %s)", inet_ntoa(sin3.sin_addr)); } } if (ippntd) { ippntd = 0; printf("\n"); } freeifaddrs(ifap); if (!br) { if (phys_status(ifs, ifname, tmp_str, tmp_str2, sizeof(tmp_str), sizeof(tmp_str2)) > 0) printf(" Tunnel source %s destination %s\n", tmp_str, tmp_str2); if ((carp = carp_state(ifs, ifname)) != NULL) printf(" CARP state %s\n", carp); /* * Display MTU, line rate, and ALTQ token rate info * (if available) */ printf(" MTU %u bytes", if_mtu); if (if_baudrate) printf(", Line Rate %qu %s\n", MBPS(if_baudrate) ? MBPS(if_baudrate) : if_baudrate / 1000, MBPS(if_baudrate) ? "Mbps" : "Kbps"); else printf("\n"); memset(&vreq, 0, sizeof(struct vlanreq)); ifr.ifr_data = (caddr_t)&vreq; if (ioctl(ifs, SIOCGETVLAN, (caddr_t)&ifr) != -1) if(vreq.vlr_tag || (vreq.vlr_parent[0] != '\0')) printf(" 802.1Q vlan tag %d, parent %s\n", vreq.vlr_tag, vreq.vlr_parent[0] == '\0' ? "<none>" : vreq.vlr_parent); } if (get_nwinfo(ifname, tmp_str, sizeof(tmp_str), NWID) != NULL) { printf(" SSID %s", tmp_str); if(get_nwinfo(ifname, tmp_str, sizeof(tmp_str), NWKEY) != NULL) printf(", key %s", tmp_str); if ((tmp = get_nwinfo(ifname, tmp_str, sizeof(tmp_str), POWERSAVE) != NULL)) printf(", powersaving (%s ms)\n", tmp_str); printf("\n"); } /* * Display remaining info from if_data structure */ printf(" %qu packets input, %qu bytes, %qu errors, %qu drops\n", if_ipackets, if_ibytes, if_ierrors, if_iqdrops); printf(" %qu packets output, %qu bytes, %qu errors, %qu unsupported\n", if_opackets, if_obytes, if_oerrors, if_noproto); if (if_ibytes && if_ipackets && (if_ibytes / if_ipackets) >= ETHERMIN) { /* < ETHERMIN means byte counter probably rolled over */ printf(" %qu input", if_ibytes / if_ipackets); pntd = 1; } else pntd = 0; if (if_obytes && if_opackets && (if_obytes / if_opackets) >= ETHERMIN) { /* < ETHERMIN means byte counter probably rolled over */ printf("%s%qu output", pntd ? ", " : " ", if_obytes / if_opackets); pntd = 1; } if (pntd) printf(" (average bytes/packet)\n"); switch(if_type) { /* * These appear to be the only interface types to increase collision * count in the OpenBSD 3.2 kernel. */ case IFT_ETHER: case IFT_SLIP: case IFT_PROPVIRTUAL: case IFT_IEEE80211: printf(" %qu collisions\n", if_collisions); break; default: break; } if(verbose) { if (flags) { printf(" Flags:\n "); bprintf(stdout, flags, ifnetflags); printf("\n"); } if (br) { if ((tmp = bridge_list(ifs, ifname, " ", tmp_str, sizeof(tmp_str), SHOW_STPSTATE))) { printf(" STP member state%s:\n", tmp > 1 ? "s" : ""); printf("%s", tmp_str); } bridge_addrs(ifs, ifname, " ", " "); } media_supported(ifs, ifname, " ", " "); } close(ifs); return(0); }
int show_int(int argc, char **argv) { struct ifaddrs *ifap, *ifa; struct if_nameindex *ifn_list, *ifnp; struct ifreq ifr, ifrdesc; struct if_data if_data; struct sockaddr_in *sin = NULL, *sinmask = NULL, *sindest; struct sockaddr_in6 *sin6 = NULL, *sin6mask = NULL, *sin6dest; struct timeval tv; short tmp; int ifs, br, flags, days, hours, mins, pntd; int ippntd = 0; int physrt, physttl; time_t c; char *type, *lladdr, *ifname = NULL; char tmp_str[512], tmp_str2[512], ifdescr[IFDESCRSIZE]; if (argc == 3) ifname = argv[2]; /* * Show all interfaces when no ifname specified. */ if (ifname == NULL) { if ((ifn_list = if_nameindex()) == NULL) { printf("%% show_int: if_nameindex failed\n"); return 0; } for (ifnp = ifn_list; ifnp->if_name != NULL; ifnp++) { char *args[] = { NULL, NULL, ifnp->if_name }; show_int(3, args); } if_freenameindex(ifn_list); return(0); } else if (!is_valid_ifname(ifname)) { printf("%% interface %s not found\n", ifname); return(1); } if ((ifs = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { printf("%% show_int: %s\n", strerror(errno)); return(1); } if (!(br = is_bridge(ifs, (char *)ifname))) br = 0; strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); /* * Show up/down status and last change time */ flags = get_ifflags(ifname, ifs); ifr.ifr_data = (caddr_t)&if_data; if (ioctl(ifs, SIOCGIFDATA, (caddr_t)&ifr) < 0) { printf("%% show_int: SIOCGIFDATA: %s\n", strerror(errno)); close(ifs); return(1); } printf("%% %s", ifname); /* description */ memset(&ifrdesc, 0, sizeof(ifrdesc)); strlcpy(ifrdesc.ifr_name, ifname, sizeof(ifrdesc.ifr_name)); ifrdesc.ifr_data = (caddr_t)&ifdescr; if (ioctl(ifs, SIOCGIFDESCR, &ifrdesc) == 0 && strlen(ifrdesc.ifr_data)) printf(" (%s)", ifrdesc.ifr_data); putchar('\n'); printf(" %s is %s", br ? "Bridge" : "Interface", flags & IFF_UP ? "up" : "down"); if (if_data.ifi_lastchange.tv_sec) { gettimeofday(&tv, (struct timezone *)0); c = difftime(tv.tv_sec, if_data.ifi_lastchange.tv_sec); days = c / (24 * 60 * 60); c %= (24 * 60 * 60); hours = c / (60 * 60); c %= (60 * 60); mins = c / 60; c %= 60; printf(" (last change "); if (days) printf("%id ", days); printf("%02i:%02i:%02i)", hours, mins, (int)c); } printf(", protocol is %s", flags & IFF_RUNNING ? "up" : "down"); printf("\n"); type = iftype(if_data.ifi_type); printf(" Interface type %s", type); if (flags & IFF_BROADCAST) printf(" (Broadcast)"); else if (flags & IFF_POINTOPOINT) printf(" (PointToPoint)"); if ((lladdr = get_hwdaddr(ifname)) != NULL) printf(", hardware address %s", lladdr); printf("\n"); show_trunk(ifs, ifname); media_status(ifs, ifname, " Media type "); /* * Print interface IP address, and broadcast or * destination if available. But, don't print broadcast * if it is what we would expect given the ip and netmask! */ if (getifaddrs(&ifap) != 0) { printf("%% show_int: getifaddrs failed: %s\n", strerror(errno)); return(1); } /* * Cycle through getifaddrs for interfaces with our * desired name that sport AF_INET, print the IP and * related information. */ for (ifa = ifap; ifa; ifa = ifa->ifa_next) { if (strncmp(ifname, ifa->ifa_name, IFNAMSIZ)) continue; switch (ifa->ifa_addr->sa_family) { case AF_INET: sin = (struct sockaddr_in *)ifa->ifa_addr; sinmask = (struct sockaddr_in *)ifa->ifa_netmask; if (sin->sin_addr.s_addr == INADDR_ANY) continue; break; case AF_INET6: sin6 = (struct sockaddr_in6 *)ifa->ifa_addr; sin6mask = (struct sockaddr_in6 *)ifa->ifa_netmask; if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) continue; in6_fillscopeid(sin6); break; default: continue; } if (!ippntd) printf(" Internet address"); printf("%s %s", ippntd ? "," : "", ifa->ifa_addr->sa_family == AF_INET ? netname4(sin->sin_addr.s_addr, sinmask) : netname6(sin6, sin6mask)); ippntd = 1; switch (ifa->ifa_addr->sa_family) { case AF_INET: if (flags & IFF_POINTOPOINT) { sindest = (struct sockaddr_in *) ifa->ifa_dstaddr; printf(" (Destination %s)", routename4(sindest->sin_addr.s_addr)); } else if (flags & IFF_BROADCAST) { sindest = (struct sockaddr_in *) ifa->ifa_broadaddr; /* * no reason to show the broadcast addr * if it is standard (this should always * be true unless someone has messed up their * network or they are playing around...) */ if (ntohl(sindest->sin_addr.s_addr) != in4_brdaddr(sin->sin_addr.s_addr, sinmask->sin_addr.s_addr) && ntohl(sindest->sin_addr.s_addr) != INADDR_ANY) printf(" (Broadcast %s)", inet_ntoa(sindest->sin_addr)); } break; case AF_INET6: if (flags & IFF_POINTOPOINT) { sin6dest = (struct sockaddr_in6 *) ifa->ifa_dstaddr; in6_fillscopeid(sin6dest); printf(" (Destination %s)", routename6(sin6dest)); } break; default: printf(" unknown"); break; } } if (ippntd) { printf("\n"); } freeifaddrs(ifap); if (!br) { if (phys_status(ifs, ifname, tmp_str, tmp_str2, sizeof(tmp_str), sizeof(tmp_str2)) > 0) { printf(" Tunnel source %s destination %s", tmp_str, tmp_str2); if (((physrt = get_physrtable(ifs, ifname)) != 0)) printf(" destination rdomain %i", physrt); if (((physttl = get_physttl(ifs, ifname)) != 0)) printf(" ttl %i", physttl); printf("\n"); } carp_state(ifs, ifname); printf(" "); show_vnet_parent(ifs, ifname); if (ioctl(ifs, SIOCGIFRDOMAIN, (caddr_t)&ifr) != -1) printf(" rdomain %d,", ifr.ifr_rdomainid); /* * Display MTU, line rate */ printf(" MTU %u bytes", if_data.ifi_mtu); if (ioctl(ifs, SIOCGIFHARDMTU, (caddr_t)&ifr) != -1) { if (ifr.ifr_hardmtu) printf(" (hardmtu %u)", ifr.ifr_hardmtu); } if (if_data.ifi_baudrate) printf(", Line Rate %qu %s", MBPS(if_data.ifi_baudrate) ? MBPS(if_data.ifi_baudrate) : if_data.ifi_baudrate / 1000, MBPS(if_data.ifi_baudrate) ? "Mbps" : "Kbps"); printf("\n"); } if (get_nwinfo(ifname, tmp_str, sizeof(tmp_str), NWID) != 0) { printf(" SSID %s", tmp_str); if(get_nwinfo(ifname, tmp_str, sizeof(tmp_str), NWKEY) != 0) printf(", key %s", tmp_str); if ((tmp = get_nwinfo(ifname, tmp_str, sizeof(tmp_str), POWERSAVE)) != 0) printf(", powersaving (%s ms)\n", tmp_str); printf("\n"); } /* * Display remaining info from if_data structure */ printf(" %qu packets input, %qu bytes, %qu errors, %qu drops\n", if_data.ifi_ipackets, if_data.ifi_ibytes, if_data.ifi_ierrors, if_data.ifi_iqdrops); printf(" %qu packets output, %qu bytes, %qu errors, %qu unsupported\n", if_data.ifi_opackets, if_data.ifi_obytes, if_data.ifi_oerrors, if_data.ifi_noproto); if (if_data.ifi_ibytes && if_data.ifi_ipackets && (if_data.ifi_ibytes / if_data.ifi_ipackets) >= ETHERMIN) { /* < ETHERMIN means byte counter probably rolled over */ printf(" %qu input", if_data.ifi_ibytes / if_data.ifi_ipackets); pntd = 1; } else pntd = 0; if (if_data.ifi_obytes && if_data.ifi_opackets && (if_data.ifi_obytes / if_data.ifi_opackets) >= ETHERMIN) { /* < ETHERMIN means byte counter probably rolled over */ printf("%s%qu output", pntd ? ", " : " ", if_data.ifi_obytes / if_data.ifi_opackets); pntd = 1; } if (pntd) printf(" (average bytes/packet)\n"); switch(if_data.ifi_type) { /* * These appear to be the only interface types to increase collision * count in the OpenBSD 3.2 kernel. */ case IFT_ETHER: case IFT_SLIP: case IFT_PROPVIRTUAL: case IFT_IEEE80211: printf(" %qu collisions\n", if_data.ifi_collisions); break; default: break; } if(verbose) { if (flags) { printf(" Flags:\n "); bprintf(stdout, flags, ifnetflags); printf("\n"); } printifhwfeatures(ifs, ifname); if (br) { if ((tmp = bridge_list(ifs, ifname, " ", tmp_str, sizeof(tmp_str), SHOW_STPSTATE))) { printf(" STP member state%s:\n", tmp > 1 ? "s" : ""); printf("%s", tmp_str); } bridge_addrs(ifs, ifname, " ", " "); } media_supported(ifs, ifname, " ", " "); } close(ifs); return(0); }
void DllExport getdim ( char *fname, TInt4 *itype, char *dim, TInt4 *pardep, TInt4 *timdep, TInt4 *locdep, TInt4 *ndim, TInt4 *ierror, char *option) /*************************************************************************/ /* */ /* Arguments: */ /* */ /* Name Size I/O Description */ /* ------ -------- --- ------------------------------------ */ /* dim - I Dimension required. */ /* fname 3 I Full filename, including extension */ /* ierror - O Errorcode, see errors.inc for definitio */ /* itype - I/O Filetype, see types.inc for definitions */ /* len_.. - I UNIX only: length of CHARACTER variable */ /* locdep - I location dependency of dimension */ /* ndim - O dimension. */ /* option - I/O option (reserved for future extensions) */ /* pardep - I parameter dependency of dimension */ /* timdep - I time dependency of dimension */ /* */ /*************************************************************************/ { int i, inum, length ; char *fn; char dim_copy[4]; #define DEBUG 0 #if DEBUG FILE *dbgout; #endif strncpy( dim_copy, dim, 3 ); dim_copy[3] = '\0'; *ierror = IEOK; /* strip trailing blanks and add terminating 0 to all strings, just to make sure: */ for (inum = 0 ; inum < ODS_FNAME_DIM ; inum++) { fn = &fname[inum*ODS_FILNAMLEN] ; fn[ODS_FILNAMLEN-1] = '\0' ; length = strlen( fn ) ; for ( i = length-1 ; i >= 0 ; i -- ) { if ( fn[i] == ' ') { fn[i] = '\0' ; } else { break ; } } } #if DEBUG dbgout = fopen( "ods_debug.txt", "a" ) ; fprintf( dbgout, "File name: %s\n", fname ); fflush( dbgout ); fprintf( dbgout, "File type: %d\n", *itype ); fflush( dbgout ); fprintf( dbgout, "Dimension pointer: %p\n", dim ); fflush( dbgout ); fprintf( dbgout, "Dimension: %s\n", dim ); fflush( dbgout ); fprintf( dbgout, "Parameter: %d\n", *pardep); fflush( dbgout ); fclose( dbgout ) ; #endif /* Get filetype, if we don't know, first check extension: */ if (*itype == ITUNDE) *itype = iftype ( fname) ; /* Now proceed: */ switch ( *itype) { case ITUNDE : /* Unable to determine filetype */ *ierror = IEUNDE ; break ; case ODS_DELWAQ_HIS_NEFIS : case ODS_DELWAQ_MAP_NEFIS : case ODS_DELPAR_HIS_NEFIS : case ODS_DELPAR_MAP_NEFIS : case ODS_DELPAR_PLO_NEFIS : /* DELWAQ/DELPAR NEFIS filetype */ DlwGetNefisDim ( fname, itype, dim, pardep, timdep, locdep, ndim, ierror, option ); break ; #ifdef PC case ITDBF3 : /* DBASE 3 filetype */ break ; case ITDBF4 : /* DBASE 4 filetype */ break ; #endif case ODS_DELWAQ_MAP_BIN: case ODS_DELWAQ_HIS_BIN: case ODS_DELPAR_PLO_BIN: case ODS_DELWAQ_BAL_BIN: /* DELWAQ MAP file */ /*ODSGetDimDlwm ( fname, itype, dim, ndim, ierror) ;*/ ODSGetDimDlwq ( fname, itype, dim, pardep, ndim, ierror) ; break ; /*case ODS_DELWAQ_HIS_BIN:*/ /* DELWAQ HIS file */ /* ODSGetDimDlwh ( fname, itype, dim, ndim, ierror) ; break ; */ case ITWAS : /* WASPRO WAS file */ break ; case ITWS1 : /* WASPRO WS1 file */ break ; case ITMPX : /* MAPPIX file */ break ; case ODS_TRISULA_HIS_NEFIS : /* TRISULA NEFIS HIS file */ GNF_GetDim( fname, itype, dim, pardep, timdep, locdep, ndim, ierror, option ) ; break ; case ODS_TRISULA_MAP_NEFIS : /* TRISULA NEFIS MAP file */ GNF_GetDim( fname, itype, dim, pardep, timdep, locdep, ndim, ierror, option ) ; break ; case ODS_TRISULA_DRO_NEFIS : case ODS_DELPAR_TRK_NEFIS : /* TRISULA NEFIS drogues file */ TriDroGetDim( fname, itype, dim, pardep, timdep, locdep, (TInt4 *) ndim, (TInt4 *) ierror, option ); break ; case ODS_SAMPLES_2D : case ODS_SAMPLES_TABLE : case ODS_SAMPLES_TIME : /* Samples file (2D or table) */ SamplesGetDim( fname, itype, dim, pardep, timdep, locdep, (TInt4 *) ndim, (TInt4 *) ierror, option ); break ; case ODS_MORSYS_MAP_NEFIS : /* MORSYS NEFIS COM file */ GNF_GetDim( fname, itype, dim, pardep, timdep, locdep, ndim, ierror, option ) ; break ; case ODS_MORSYS_TRAM_NEFIS : /* MORSYS NEFIS TRAM file */ GNF_GetDim( fname, itype, dim, pardep, timdep, locdep, ndim, ierror, option ) ; break ; case ODS_MORSYS_SWAN_NEFIS : /* MORSYS NEFIS SWAN file */ GNF_GetDim( fname, itype, dim, pardep, timdep, locdep, ndim, ierror, option ) ; break ; case ODS_MORSYS_HWBOD : /* MORSYS NEFIS COM file */ ODS_MORSYS_NEFIS_COMDIM( fname, 256, 3, *itype, dim, *pardep, *timdep, *locdep, (TInt4 *) ndim, (TInt4 *) ierror, option ); break ; case ODS_MORSYS_HWGXY : /* MORSYS NEFIS COM file */ ODS_MORSYS_NEFIS_COMDIM( fname, 256, 3, *itype, dim, *pardep, *timdep, *locdep, (TInt4 *) ndim, (TInt4 *) ierror, option ); break ; case ODS_MORSYS_TRAH_NEFIS : /* MORSYS NEFIS HIS files */ GNF_GetDim( fname, itype, dim, pardep, timdep, locdep, ndim, ierror, option ) ; break ; case ODS_MORSYS_BAGR_NEFIS : /* MORSYS NEFIS BAGR file (dredging) */ MorOdsGetDim ( fname, itype, dim, pardep, timdep, locdep, ndim, ierror, option ); break ; case ODS_ANY_TEKAL_ASCII_1D : case ODS_ANY_TEKAL_ASCII_1DE : /* TEKAL ASCII 1D files */ ODSGetDimAnyTekAscHis ( fname , itype, dim, *pardep,*timdep, *locdep, ndim, ierror, option ) ; break ; case ODS_ANY_TEKAL_ASCII_2D : case ODS_ANY_TEKAL_ASCII_VEC : /* TEKAL ASCII 2D files (scalar and vector) */ ODSGetDimAnyTekAscMap ( fname , itype, dim, *pardep,*timdep, *locdep, ndim, ierror, option ) ; break ; case ODS_ANY_TEKAL_ASCII_ANNO : /* TEKAL ASCII Annotation files (text at specified location) */ ODSGetDimTekAnno ( fname , itype, dim, *pardep,*timdep, *locdep, ndim, ierror, option ) ; break ; case ODS_ANY_JSPOST: /* JSPost files */ ODSGetDimJSP( fname, itype, dim, *pardep, *timdep, *locdep, ndim, ierror, option ) ; break ; case ODS_DELWAQ_GRID_UNF : case ODS_DELWAQ_TELEMAC : /* DELWAQ/DELPAR grid files */ ODSGetDimDlwg( fname , itype, dim, *pardep,*timdep, *locdep, ndim, ierror , option ) ; break ; case ODS_SHYFEM_GRID : /* SHYFEM grid files */ ODSGetDimShyf( fname , (TInt4 *) itype, dim, *pardep, *timdep, *locdep, (TInt4 *) ndim, (TInt4 *) ierror, option ) ; break ; case ODS_PHAROS_AMP_NEFIS: /* PHAROS admin file (seiches amplifications) */ ODSGetDimPharAmp( fname, (TInt4 *) itype, dim, *pardep, *timdep, *locdep, (TInt4 *) ndim, (TInt4 *) ierror, option ) ; break ; case ODS_PHAROS_MAP_NEFIS: /* PHAROS NEFIS file */ ODSGetDimPharMap( fname, (TInt4 *) itype, dim, *pardep, *timdep, *locdep, (TInt4 *) ndim, (TInt4 *) ierror, option ) ; break ; case ODS_PHIDIAS_HISTORY: case ODS_PHIDIAS_MAP: /* PHIDIAS NEFIS map file */ ODSGetDimPhiMap( fname, 256, 3, *itype, dim, *pardep, *timdep, *locdep, (TInt4 *) ndim, (TInt4 *) ierror, option ); break; case ODS_PHIDIAS_SPECTRAL: /* PHIDIAS NEFIS spectrum file */ ODSGetDimPhiSpec( fname, 256, 3, *itype, dim, *pardep, *timdep, *locdep, (TInt4 *) ndim, (TInt4 *) ierror, option ); break; case ODS_GEOGR_BNA: case ODS_GEOGR_DXF: case ODS_GEOGR_TEKAL: /* BNA, DXF and TEKAL landboundary files */ ODS_BNA_getdim( fname, itype, dim, pardep, timdep, locdep, ndim, ierror, option ) ; break ; default : /* Filetype not implemented: */ *ierror = IEUNKN; } #if DEBUG dbgout = fopen( "ods_debug.txt", "a" ) ; fprintf( dbgout, "Result (dimensions): %d %d %d %d\n", ndim[0], ndim[1], ndim[2], ndim[3] ); fclose( dbgout ); #endif }