void EditFile() { FHeader(); for (;;) { set_color(WHITE, BLACK); show_str( 7,16,12, fdb.Name); show_str( 8,16,64, fdb.LName); show_int( 9,16, fdb.Size); mbse_mvprintw(10,16, (char *)"%s %s", StrDateDMY(fdb.FileDate), StrTimeHM(fdb.FileDate)); mbse_mvprintw(11,16, (char *)"%s %s", StrDateDMY(fdb.LastDL), StrTimeHM(fdb.LastDL)); mbse_mvprintw(12,16, (char *)"%s %s", StrDateDMY(fdb.UploadDate), StrTimeHM(fdb.UploadDate)); show_str(13,16,20, fdb.TicArea); show_str(14,16,20, fdb.Magic); show_str(15,16,36, fdb.Uploader); show_int(16,16, fdb.TimesDL); show_str(17,16,15, fdb.Password); show_bool(15,75, fdb.Deleted); show_bool(16,75, fdb.NoKill); show_bool(17,75, fdb.Announced); switch(select_menu(6)) { case 0: return; case 1: E_STR( 15,16,35, fdb.Uploader, "The ^uploader^ of this file") case 2: E_INT( 16,16, fdb.TimesDL, "The number of times file is sent with ^download^") case 3: E_STR( 17,16,15, fdb.Password, "The ^password^ to protect this file with") case 4: E_BOOL(15,75, fdb.Deleted, "Should this this file be ^deleted^") case 5: E_BOOL(16,75, fdb.NoKill, "File can't be ^killed^ automatic") case 6: E_BOOL(17,75, fdb.Announced, "File is ^announced^ as new file") } } }
void run_255() { printf("\nexersize 2.55: \n"); show_int(1); show_short(12345); show_int(12345); show_long(12345); show_double(12345); }
// private void vamp_generator::show() { show_int( x ); std::cout << " * "; show_int( y ); std::cout << " = "; show_int( x*y ); std::cout << " (base " << base << ')' << std::endl; }
int main() { int x = 1, y = 2; printf("Before swap:\n"); show_int(x); show_int(y); inplace_swap(&x, &y); printf("After swap:\n"); show_int(x); show_int(y); return 0; }
void float_eg() { int x = 3490593; float f = (float) x; printf("For x = %d\n", x); show_int(x); show_float(f); x = 3510593; f = (float) x; printf("For x = %d\n", x); show_int(x); show_float(f); }
int main(int argc, char const *argv[]) { int a = -1; // if (a == b) // { // printf("%d\n",a); // printf("%u\n",b); // } int b = -a; show_int(a); show_int(b); printf("%d\n", b); return 0; }
void FieldsM(void) { set_color(WHITE, BLACK); show_str( 7,16,20, getmagictype(magic.Attrib)); show_str( 8,16,14, magic.Mask); show_str( 9,16, 3, getboolean(magic.Active)); show_str(10,16, 3, getboolean(magic.Deleted)); show_str(11,16,20, magic.From); switch(magic.Attrib) { case MG_ADOPT: case MG_MOVE: show_str(12,16,20, magic.ToArea); break; case MG_EXEC: show_str(12,16,64, magic.Cmd); show_bool(13,16, magic.Compile); break; case MG_UNPACK: case MG_COPY: show_bool(13,16, magic.Compile); show_str(12,16,64, magic.Path); break; case MG_KEEPNUM: show_int(12,16, magic.KeepNum); break; } }
int main() { int intVariable = 10; float floatVariable = 2.5f; int* intPointer = &intVariable; int intValue = *intPointer; short shortVariable = 10; long longVariable = 65535; double doubleVariable = 0.000125f; printf("int:"); show_int(intVariable); printf("float:"); show_float(floatVariable); printf("pointer:"); show_pointer(intPointer); printf("short:"); show_short(shortVariable); printf("long:"); show_long(longVariable); printf("double:"); show_double(doubleVariable); }
void test_show_bytes(int val){ int ival = val; float fval = (float) ival; int* pval = &ival; show_int(ival); show_float(fval); show_pointer(pval); }
int main(void) { int data = 0x12345678; float data_f = 0.12345; show_int(data); show_float(data_f); return 0; }
void main(int argc, char *argv[]) { if (argc == 2) { show_int(atoi(argv[1])); } else { printf("Provide exactly one argument!\n"); } return; }
int main() { int i = 240; float f = 22.2; show_int(i); show_float(f); show_pointer(&f); return 0; }
//unit test here int main() { int x = 10; int *ip = &x; show_int(x); printf("\n"); show_pointer(ip); return 0; }
void main() { int ival = 0x123456; float fval = (float) ival; int *pval = &ival; show_int(ival); show_float(fval); show_pointer(pval); }
int main(){ long int x; int y; float z; scanf( "%f",&z ); show_float( z ); scanf( "%d",&y ); show_int(y); return 0; }
int main(int argc, char *argv[]) { char carray[5] = {'a','b','c','d','e'}; int ix = 11111; float fx = -0.75; int idx; //validate the command line if( argc < 2 || !((strcasecmp(argv[1], "-all") == 0) || (strcasecmp(argv[1], "-char") == 0) || (strcasecmp(argv[1], "-int") == 0 ) || (strcasecmp(argv[1], "-fl") == 0 ))) { printf ("%s", "Invalid input: "); //display the command line input for (idx = 0; idx<argc; idx++) { printf ("argv[%d] = %s ", idx, argv[idx]); } printf ("\n"); printf ( "%s\n", "The input format: program -[all, char, int, fl] number\n"); } else { if (strcasecmp(argv[1], "-char") == 0) { print_format = PRINT_CHAR; printf("show_bytes...\n"); show_bytes(carray, 5); //show_pointer(carray); } if (strcasecmp(argv[1], "-int") == 0) { print_format = PRINT_INT; show_int(ix); show_pointer(&ix); } if (strcasecmp(argv[1], "-fl") == 0) { print_format = PRINT_FLOAT; show_float(fx); show_pointer(&fx); } } // printf("show_bytes...\n"); // show_bytes(carray, 5); // show_int(ix); // show_float(fx); }
int main() { int a = 10; float b = 11.5; double c = 13.33; void *d = &a; show_int(a); printf("\n"); show_float(b); printf("\n"); show_double(c); printf("\n"); show_pointer(d); getchar(); }
int main() { int val = 0x87654321; byte_pointer valp = (byte_pointer) &val; show_int(val); show_float((float) val); show_pointer(valp); show_bytes(valp, 1); show_bytes(valp, 2); show_bytes(valp, 3); return 0; }
int main() { if(is_big_endian()) printf("\nbig endian"); else printf("\nlittle endian"); show_char('C'); show_int(-535703600); show_double(1.7E+308); printf("\n"); return EXIT_SUCCESS; }
void test_show_bytes(int val) { int ival = val; float fval = (float) ival; int *pval = &ival; short sval = (short) ival; long lval = (long) ival; double dval = (double) ival; show_int(ival); show_float(fval); show_pointer(pval); show_short(sval); show_long(lval); show_double(dval); printf("\n"); }
int main(int argc, char *argv[]) { char carray[5]={'a', 'b', 'c', 'd', 'e'}; int ix = 11111; float fx = 1.5; int idx; if (argc == 1 ) { printf ( "help info: %s\n", "the input format is"); } else { for (idx = 0; idx<argc; idx++) { printf ("argv[%d] = %s ", idx, argv[idx]); } if (strcasecmp(argv[1], "-c") == 0) { print_format = PRINT_CHAR; printf("argv show_bytes...\n"); show_bytes(carray, 5); } if (strcasecmp(argv[1], "-i") == 0) { print_format = PRINT_INT; show_int(ix); } if (strcasecmp(argv[1], "-f") == 0) { print_format = PRINT_FLOAT; show_float(fx); } } // printf("show_bytes...\n"); // show_bytes(carray, 5); // show_int(ix); // show_float(fx); }
static int xbt_log_layout_format_doit(xbt_log_layout_t l, xbt_log_event_t ev, const char *msg_fmt) { char *p = ev->buffer; int rem_size = ev->buffer_size; int precision = -1; int length = -1; char *q; for (q = l->data ; *q != '\0' ; q++) { if (*q == '%') { q++; handle_modifier: switch (*q) { case '\0': fprintf(stderr, "Layout format (%s) ending with %%\n", (char *)l->data); xbt_abort(); case '%': *p = '%'; check_overflow(1); break; case 'n': /* platform-dependant line separator; LOG4J compliant */ *p = '\n'; check_overflow(1); break; case 'e': /* plain space; SimGrid extension */ *p = ' '; check_overflow(1); break; case '.': /* precision specifier */ precision = strtol(q + 1, &q, 10); goto handle_modifier; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': /* length modifier */ length = strtol(q, &q, 10); goto handle_modifier; case 'c': /* category name; LOG4J compliant should accept a precision postfix to show the hierarchy */ show_string(ev->cat->name); break; case 'p': /* priority name; LOG4J compliant */ show_string(xbt_log_priority_names[ev->priority]); break; case 'h': /* host name; SimGrid extension */ show_string(SIMIX_host_self_get_name()); break; case 't': /* thread name; LOG4J compliant */ show_string(SIMIX_process_self_get_name()); break; case 'P': /* process name; SimGrid extension */ show_string(xbt_procname()); break; case 'i': /* process PID name; SimGrid extension */ show_int(xbt_getpid()); break; case 'F': /* file name; LOG4J compliant */ show_string(ev->fileName); break; case 'l': { /* location; LOG4J compliant */ int len, sz; set_sz_from_precision(); len = snprintf(p, sz, "%s:%d", ev->fileName, ev->lineNum); check_overflow(MIN(sz, len)); break; } case 'L': /* line number; LOG4J compliant */ show_int(ev->lineNum); break; case 'M': /* method (ie, function) name; LOG4J compliant */ show_string(ev->functionName); break; case 'b': /* backtrace; called %throwable in LOG4J */ case 'B': /* short backtrace; called %throwable{short} in LOG4J */ // TODO, backtrace #if 0 && HAVE_BACKTRACE && HAVE_EXECINFO_H && HAVE_POPEN && defined(ADDR2LINE) { xbt_ex_t e(""); e.used = backtrace((void **) e.bt, XBT_BACKTRACE_SIZE); e.bt_strings = NULL; xbt_ex_setup_backtrace(&e); if (*q == 'B') { show_string(e.bt_strings[1] + 8); } else { xbt_strbuff_t buff = xbt_strbuff_new(); int i; xbt_strbuff_append(buff, e.bt_strings[1] + 8); for (i = 2; i < e.used; i++) { xbt_strbuff_append(buff, "\n"); xbt_strbuff_append(buff, e.bt_strings[i] + 8); } show_string(buff->data); xbt_strbuff_free(buff); } } #else show_string("(no backtrace on this arch)"); #endif break; case 'd': /* date; LOG4J compliant */ show_double(surf_get_clock()); break; case 'r': /* application age; LOG4J compliant */ show_double(surf_get_clock() - format_begin_of_time); break; case 'm': { /* user-provided message; LOG4J compliant */ int len, sz; set_sz_from_precision(); len = vsnprintf(p, sz, msg_fmt, ev->ap); check_overflow(MIN(sz, len)); break; } default: fprintf(stderr, ERRMSG, *q, (char *)l->data); xbt_abort(); } } else { *p = *q; check_overflow(1); } } *p = '\0'; return 1; }
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); }
static void xbt_log_layout_format_doit(xbt_log_layout_t l, xbt_log_event_t ev, const char *msg_fmt, xbt_log_appender_t app) { char *p, *q; char tmpfmt[50]; int precision = -1; int length = -1; p = ev->buffer; q = l->data; while (*q != '\0') { if (*q == '%') { q++; handle_modifier: switch (*q) { case '\0': fprintf(stderr, "Layout format (%s) ending with %%\n", (char *) l->data); abort(); case '%': *p++ = '%'; break; case 'n': /* platform-dependant line separator (LOG4J compliant) */ p += snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "\n"); check_overflow; break; case 'e': /* plain space (SimGrid extension) */ p += snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), " "); check_overflow; break; case '.': /* precision specifyier */ q++; sscanf(q, "%d", &precision); q += (precision>9?2:1); goto handle_modifier; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': /* length modifier */ sscanf(q, "%d", &length); q += (length>9?2:1); goto handle_modifier; case 'c': /* category name; LOG4J compliant should accept a precision postfix to show the hierarchy */ show_string(ev->cat->name); break; case 'p': /* priority name; LOG4J compliant */ show_string(xbt_log_priority_names[ev->priority]); break; case 'h': /* host name; SimGrid extension */ show_string(gras_os_myname()); break; case 't': /* thread name; LOG4J compliant */ show_string(xbt_thread_self_name()); break; case 'P': /* process name; SimGrid extension */ show_string(xbt_procname()); break; case 'i': /* process PID name; SimGrid extension */ show_int((*xbt_getpid) ()); break; case 'F': /* file name; LOG4J compliant */ show_string(ev->fileName); break; case 'l': /* location; LOG4J compliant */ if (precision == -1) { p += snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%s:%d", ev->fileName, ev->lineNum); check_overflow; } else { p += snprintf(p, (int) MIN(XBT_LOG_BUFF_SIZE - (p - ev->buffer), precision), "%s:%d", ev->fileName, ev->lineNum); check_overflow; precision = -1; } break; case 'L': /* line number; LOG4J compliant */ show_int(ev->lineNum); break; case 'M': /* method (ie, function) name; LOG4J compliant */ show_string(ev->functionName); break; case 'b': /* backtrace; called %throwable in LOG4J */ case 'B': /* short backtrace; called %throwable{short} in LOG4J */ #if defined(HAVE_EXECINFO_H) && defined(HAVE_POPEN) && defined(ADDR2LINE) { xbt_ex_t e; int i; e.used = backtrace((void **) e.bt, XBT_BACKTRACE_SIZE); e.bt_strings = NULL; e.msg = NULL; e.remote = 0; xbt_backtrace_current(&e); if (*q == 'B') { show_string(e.bt_strings[2] + 8); } else { for (i = 2; i < e.used; i++) if (precision == -1) { p += snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%s\n", e.bt_strings[i] + 8); check_overflow; } else { p += sprintf(p, "%.*s\n", (int) MIN(XBT_LOG_BUFF_SIZE - (p - ev->buffer), precision), e.bt_strings[i] + 8); check_overflow; precision = -1; } } xbt_ex_free(e); } #else p += snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "(no backtrace on this arch)"); check_overflow; #endif break; case 'd': /* date; LOG4J compliant */ show_double(gras_os_time()); break; case 'r': /* application age; LOG4J compliant */ show_double(gras_os_time() - format_begin_of_time); break; case 'm': /* user-provided message; LOG4J compliant */ if (precision == -1) { p += vsnprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), msg_fmt, ev->ap); check_overflow; } else { p += vsnprintf(p, (int) MIN(XBT_LOG_BUFF_SIZE - (p - ev->buffer), precision), msg_fmt, ev->ap); check_overflow; precision = -1; } break; default: fprintf(stderr, ERRMSG, *q, (char *) l->data); abort(); } q++; } else { *(p++) = *(q++); check_overflow; } } *p = '\0'; app->do_append(app, ev->buffer); }
int main(){ show_int(3510593); show_float(3510593.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); }
/* * Edit one record, return -1 if there are errors, 0 if ok. */ int EditMGrpRec(int Area) { FILE *fil; static char mfile[PATH_MAX], temp[13]; static int offset; static int i, j, tmp; unsigned int crc, crc1; int oldgrp, newgrp; clr_index(); working(1, 0, 0); IsDoing("Edit MessageGroup"); snprintf(mfile, PATH_MAX, "%s/etc/mgroups.temp", getenv("MBSE_ROOT")); if ((fil = fopen(mfile, "r")) == NULL) { working(2, 0, 0); return -1; } offset = sizeof(mgrouphdr) + ((Area -1) * sizeof(mgroup)); if (fseek(fil, offset, 0) != 0) { working(2, 0, 0); return -1; } fread(&mgroup, sizeof(mgroup), 1, fil); fclose(fil); crc = 0xffffffff; crc = upd_crc32((char *)&mgroup, crc, sizeof(mgroup)); MgScreen(); for (;;) { set_color(WHITE, BLACK); show_str( 7,16,12, mgroup.Name); show_str( 8,16,55, mgroup.Comment); show_str( 9,16,64, mgroup.BasePath); show_sec( 10,16, mgroup.RDSec); show_sec( 11,16, mgroup.WRSec); show_sec( 12,16, mgroup.SYSec); mbse_mvprintw( 13,22, getflag(mgroup.LinkSec.flags, mgroup.LinkSec.notflags)); show_int( 14,16, mgroup.StartArea); show_int( 15,16, mgroup.NetReply); show_bool(16,16, mgroup.UsrDelete); show_bool(17,16, mgroup.Aliases); show_bool(18,16, mgroup.Quotes); show_bool(19,16, mgroup.Active); show_bool(14,42, mgroup.Deleted); show_bool(15,42, mgroup.AutoChange); show_bool(16,42, mgroup.UserChange); show_aka( 17,42, mgroup.UseAka); show_aka( 18,42, mgroup.UpLink); show_str( 19,42,12, mgroup.AreaFile); show_charset(14,70, mgroup.Charset); snprintf(temp, 5, "#%03d", mgroup.GoldEDgroup); show_str( 15,70, 5, temp); j = select_menu(21); switch(j) { case 0: if (!mgroup.StartArea && strlen(mgroup.AreaFile)) { errmsg("Areas file defined but no BBS start area"); break; } crc1 = 0xffffffff; crc1 = upd_crc32((char *)&mgroup, crc1, sizeof(mgroup)); if (crc != crc1) { if (yes_no((char *)"Record is changed, save") == 1) { working(1, 0, 0); if ((fil = fopen(mfile, "r+")) == NULL) { WriteError("$Can't reopen %s", mfile); working(2, 0, 0); return -1; } fseek(fil, offset, 0); fwrite(&mgroup, sizeof(mgroup), 1, fil); fclose(fil); MGrpUpdated = 1; working(6, 0, 0); } } IsDoing("Browsing Menu"); return 0; case 1: if (CheckMgroup()) break; strcpy(mgroup.Name, edit_str(7,16,12, mgroup.Name, (char *)"The ^name^ for this message group")); if (strlen(mgroup.BasePath) == 0) { memset(&temp, 0, sizeof(temp)); strcpy(temp, mgroup.Name); for (i = 0; i < strlen(temp); i++) { if (temp[i] == '.') temp[i] = '/'; if (isupper(temp[i])) temp[i] = tolower(temp[i]); } snprintf(mgroup.BasePath, 65, "%s/var/mail/%s", getenv("MBSE_ROOT"), temp); } break; case 2: E_STR( 8,16,55, mgroup.Comment, "The ^desription^ for this message group") case 3: E_PTH( 9,16,64, mgroup.BasePath, "The ^Base path^ where new JAM areas are created", 0770) case 4: E_SEC( 10,16, mgroup.RDSec, "9.1.4 MESSAGE GROUP READ SECURITY", MgScreen) case 5: E_SEC( 11,16, mgroup.WRSec, "9.1.5 MESSAGE GROUP WRITE SECURITY", MgScreen) case 6: E_SEC( 12,16, mgroup.SYSec, "9.1.6 MESSAGE GROUP SYSOP SECURITY", MgScreen) case 7: mgroup.LinkSec = edit_asec(mgroup.LinkSec, (char *)"9.1.7 DEFAULT SECURITY FOR NEW AREAS"); MgScreen(); break; case 8: E_INT( 14,16, mgroup.StartArea, "The ^Start area number^ from where to add areas") case 9: E_INT( 15,16, mgroup.NetReply, "The ^Area Number^ for netmail replies") case 10:E_BOOL(16,16, mgroup.UsrDelete, "Allow users to ^Delete^ their messages") case 11:E_BOOL(17,16, mgroup.Aliases, "Allow ^Aliases^ or real names only") case 12:E_BOOL(18,16, mgroup.Quotes, "Allow random ^quotes^ to new messages") case 13:if (mgroup.Active && CheckMgroup()) break; E_BOOL(19,16, mgroup.Active, "Is this message group ^active^") case 14:if (CheckMgroup()) break; E_BOOL(14,42, mgroup.Deleted, "Is this group ^Deleted^") case 15:E_BOOL(15,42, mgroup.AutoChange, "^Auto change^ areas from new areas lists") case 16:tmp = edit_bool(16,42, mgroup.UserChange, (char *)"^Auto add/delete^ areas from downlinks requests"); if (tmp && !mgroup.UpLink.zone) errmsg("It looks like you are the toplevel, no Uplink defined"); else mgroup.UserChange = tmp; break; case 17:tmp = PickAka((char *)"9.1.17", TRUE); if (tmp != -1) memcpy(&mgroup.UseAka, &CFG.aka[tmp], sizeof(fidoaddr)); MgScreen(); break; case 18:mgroup.UpLink = PullUplink((char *)"9.1.18"); MgScreen(); break; case 19:E_STR( 19,42,12, mgroup.AreaFile, "The name of the ^Areas File^ from the uplink (case sensitive)") case 20:mgroup.Charset = edit_charset(14, 70, mgroup.Charset); break; case 21:oldgrp = mgroup.GoldEDgroup; newgrp = edit_int(15, 70, oldgrp, (char *)"The new groupnumber for the ^GoldED groups^ (1..999)"); if ((newgrp < 1) || (newgrp > 999)) { errmsg("Groupnumber must be between 1 and 999"); } else if (newgrp && (newgrp != oldgrp)) { if (gedgrps[newgrp] == 1) { errmsg("This groupnumber is already in use"); } else { gedgrps[oldgrp] = 0; gedgrps[newgrp] = 1; mgroup.GoldEDgroup = newgrp; } } break; } } return 0; }
void show (char *command_line) { unsigned int i,l,len,temp_int; unsigned long offset=0,temp_long; unsigned char temp_char,*ch_ptr; void *ptr; if (device_handle==NULL) return; show_pad_info.line=0; if (current_type==NULL) { wmove (show_pad,0,0); ch_ptr=type_data.u.buffer; for (l=0;l<file_system_info.block_size/16;l++) { wprintw (show_pad,"%08ld : ",offset); for (i=0;i<16;i++) { if (type_data.offset_in_block==offset+i) wattrset (show_pad,A_REVERSE); if (ch_ptr [i]>=' ' && ch_ptr [i]<='z') wprintw (show_pad,"%c",ch_ptr [i]); else wprintw (show_pad,"."); if (type_data.offset_in_block==offset+i) wattrset (show_pad,A_NORMAL); } wprintw (show_pad," "); for (i=0;i<16;i++) { if (type_data.offset_in_block==offset+i) wattrset (show_pad,A_REVERSE); wprintw (show_pad,"%02x",ch_ptr [i]); if (type_data.offset_in_block==offset+i) { wattrset (show_pad,A_NORMAL); show_pad_info.line=l-l % show_pad_info.display_lines; } wprintw (show_pad," "); } wprintw (show_pad,"\n"); offset+=16; ch_ptr+=16; } show_pad_info.max_line=l-1;show_pad_info.max_col=COLS-1; refresh_show_pad ();show_info (); } else { wmove (show_pad,0,0);l=0; for (i=0;i<current_type->fields_num;i++) { wprintw (show_pad,"%-20s = ",current_type->field_names [i]); ptr=type_data.u.buffer+offset; len = current_type->field_lengths[i]; switch (current_type->field_types[i]) { case FIELD_TYPE_INT: show_int(len, ptr); break; case FIELD_TYPE_UINT: show_uint(len, ptr); break; case FIELD_TYPE_CHAR: show_char(len, ptr); break; default: wprintw (show_pad, "unimplemented\n"); break; } offset+=len; l++; } current_type->length=offset; show_pad_info.max_line=l-1; refresh_show_pad ();show_info (); } }
int main() { show_int(0x12345678); show(float, 1.0); return 0; }
/* * Edit one record, return -1 if there are errors, 0 if ok. */ int EditFidoRec(int Area) { FILE *fil; char mfile[PATH_MAX], *temp; int offset; int i, j = 0; unsigned int crc, crc1; clr_index(); working(1, 0, 0); IsDoing("Edit Fidonet"); snprintf(mfile, PATH_MAX, "%s/etc/fidonet.temp", getenv("MBSE_ROOT")); if ((fil = fopen(mfile, "r")) == NULL) { working(2, 0, 0); return -1; } offset = sizeof(fidonethdr) + ((Area -1) * sizeof(fidonet)); if (fseek(fil, offset, 0) != 0) { working(2, 0, 0); return -1; } fread(&fidonet, sizeof(fidonet), 1, fil); fclose(fil); crc = 0xffffffff; crc = upd_crc32((char *)&fidonet, crc, sizeof(fidonet)); set_color(WHITE, BLACK); mbse_mvprintw( 5, 6, "2. EDIT FIDONET NETWORK"); set_color(CYAN, BLACK); mbse_mvprintw( 7, 6, "1. Comment"); mbse_mvprintw( 8, 6, "2. Domain name"); mbse_mvprintw( 9, 6, "3. Available"); mbse_mvprintw(10, 6, "4. Deleted"); mbse_mvprintw(11, 6, "5. Main Nodelist"); mbse_mvprintw(12, 6, "6. Merge list #1"); mbse_mvprintw(13, 6, "7. Merge list #2"); mbse_mvprintw(14, 6, "8. Merge list #3"); mbse_mvprintw(15, 6, "9. Merge list #4"); mbse_mvprintw(16, 6, "10. Merge list #5"); mbse_mvprintw(17, 6, "11. Merge list #6"); mbse_mvprintw(12,55, "12. Primary zone"); mbse_mvprintw(13,55, "13. Zone number #2"); mbse_mvprintw(14,55, "14. Zone number #3"); mbse_mvprintw(15,55, "15. Zone number #4"); mbse_mvprintw(16,55, "16. Zone number #5"); mbse_mvprintw(17,55, "17. Zone number #6"); temp = calloc(18, sizeof(char)); for (;;) { set_color(WHITE, BLACK); show_str( 7,26,40, fidonet.comment); show_str( 8,26,8, fidonet.domain); show_bool(9,26, fidonet.available); show_bool(10,26, fidonet.deleted); show_str(11,26,8, fidonet.nodelist); for (i = 0; i < 6; i++) { if ((fidonet.seclist[i].zone) || strlen(fidonet.seclist[i].nodelist)) { show_str(i + 12,26,8, fidonet.seclist[i].nodelist); snprintf(temp, 18, "%d:%d/%d", fidonet.seclist[i].zone, fidonet.seclist[i].net, fidonet.seclist[i].node); show_str(i + 12, 36,17, temp); } else show_str(i + 12,26,27, (char *)" "); show_int(i + 12,74, fidonet.zone[i]); } j = select_menu(17); switch(j) { case 0: if (fidonet.available && fidonet.deleted) fidonet.available = FALSE; if (fidonet.available && (strlen(fidonet.domain) == 0)) { errmsg("You must fill in a valid domain name"); break; } if (fidonet.available && (fidonet.zone[0] == 0)) { errmsg("The network must have a main zone number"); break; } if (fidonet.available && (strlen(fidonet.nodelist) == 0)) { errmsg("You must fill in a nodelist for this network"); break; } crc1 = 0xffffffff; crc1 = upd_crc32((char *)&fidonet, crc1, sizeof(fidonet)); if (crc != crc1) { if (yes_no((char *)"Record is changed, save") == 1) { working(1, 0, 0); if ((fil = fopen(mfile, "r+")) == NULL) { working(2, 0, 0); free(temp); return -1; } fseek(fil, offset, 0); fwrite(&fidonet, sizeof(fidonet), 1, fil); fclose(fil); FidoUpdated = 1; working(6, 0, 0); } } IsDoing("Browsing Menu"); free(temp); return 0; case 1: E_STR(7,26,40, fidonet.comment, "The ^Comment^ for this network name") case 2: E_STR(8, 26,8, fidonet.domain, "The ^Name^ of the network without dots") case 3: E_BOOL(9,26, fidonet.available, "Is this network ^Available^ for use") case 4: E_BOOL(10,26, fidonet.deleted, "Is this netword ^Deleted^") case 5: E_STR(11,26,8, fidonet.nodelist, "The name of the ^Primary Nodelist^ for this network") case 6: case 7: case 8: case 9: case 10: case 11: strcpy(fidonet.seclist[j-6].nodelist, edit_str(j+6,26,8, fidonet.seclist[j-6].nodelist, (char *)"The secondary ^nodelist^ or ^pointlist^ name for this domain")); if (strlen(fidonet.seclist[j-6].nodelist)) { do { snprintf(temp, 18, "%d:%d/%d", fidonet.seclist[j-6].zone, fidonet.seclist[j-6].net, fidonet.seclist[j-6].node); strcpy(temp, edit_str(j+6,36,17, temp, (char *)"The top ^fidonet aka^ for this nodelist (zone:net/node)")); if ((strstr(temp, ":") == NULL) || (strstr(temp, "/") == NULL)) { working(2, 0, 0); } } while ((strstr(temp, ":") == NULL) || (strstr(temp, "/") == NULL)); fidonet.seclist[j-6].zone = atoi(strtok(temp, ":")); fidonet.seclist[j-6].net = atoi(strtok(NULL, "/")); fidonet.seclist[j-6].node = atoi(strtok(NULL, "")); } else { fidonet.seclist[j-6].zone = 0; fidonet.seclist[j-6].net = 0; fidonet.seclist[j-6].node = 0; } break; case 12: case 13: case 14: case 15: case 16: case 17:E_IRC(j,74, fidonet.zone[j-12], 0, 32767, "A ^Zone number^ which belongs to this domain (1..32767)") } } return 0; }