/* * Print out protocol statistics or control blocks (per sflag). * If the interface was not specifically requested, and the symbol * is not in the namelist, ignore this one. */ static void printproto(struct protox *tp, const char *name) { void (*pr)(u_long, const char *, int, int); u_long off; if (sflag) { if (iflag) { if (tp->pr_istats) intpr(interval, nl[N_IFNET].n_value, tp->pr_istats); else if (pflag) printf("%s: no per-interface stats routine\n", tp->pr_name); return; } else { pr = tp->pr_stats; if (!pr) { if (pflag) printf("%s: no stats routine\n", tp->pr_name); return; } if (tp->pr_usesysctl && live) off = 0; else if (tp->pr_sindex < 0) { if (pflag) printf( "%s: stats routine doesn't work on cores\n", tp->pr_name); return; } else off = nl[tp->pr_sindex].n_value; } } else { pr = tp->pr_cblocks; if (!pr) { if (pflag) printf("%s: no PCB routine\n", tp->pr_name); return; } if (tp->pr_usesysctl && live) off = 0; else if (tp->pr_index < 0) { if (pflag) printf( "%s: PCB routine doesn't work on cores\n", tp->pr_name); return; } else off = nl[tp->pr_index].n_value; } if (pr != NULL && (off || (live && tp->pr_usesysctl) || af != AF_UNSPEC)) (*pr)(off, name, af, tp->pr_protocol); }
int main(int argc,char **argv) { --argc; ++argv; while (argc > 0) { if (strcmp(argv[0], "-a") == 0) { ++aflag; ++argv, --argc; continue; } if (strcmp(argv[0], "-v") == 0) { ++vflag; ++argv, --argc; continue; } if (strcmp(argv[0], "-r") == 0) { ++rflag; ++argv, --argc; continue; } if (strcmp(argv[0], "-c") == 0) { ++cflag; ++argv, --argc; continue; } if (strcmp(argv[0], "-i") == 0 && argv[1] && isdigit(argv[1][0])) { interval = atoi(argv[1]); if (interval < 0) usage(); ++argv, --argc; ++argv, --argc; continue; } if (isdigit(argv[0][0])) { unit = atoi(argv[0]); if (unit < 0) usage(); ++argv, --argc; continue; } usage(); } if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { perror("couldn't create IP socket"); exit(1); } intpr(); return(0); }
int main(int argc, char *argv[]) { struct ifreq ifr; int ch, unit; (void)strlcpy(interface, "sl0", sizeof(interface)); while ((ch = getopt(argc, argv, "i:v")) != -1) { switch (ch) { case 'i': interval = atoi(optarg); if (interval <= 0) usage(); break; case 'v': ++vflag; break; default: usage(); /* NOTREACHED */ } } argc -= optind; argv += optind; if (argc > 1) usage(); if (argc > 0) (void)strlcpy(interface, argv[0], sizeof(interface)); if (sscanf(interface, "sl%d", &unit) != 1 || unit < 0) errx(1, "invalid interface '%s' specified", interface); s = socket(AF_INET, SOCK_DGRAM, 0); if (s < 0) err(1, "couldn't create IP socket"); (void)strlcpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)); if (ioctl(s, SIOCGIFFLAGS, &ifr) < 0) errx(1, "nonexistent interface '%s' specified", interface); intpr(); exit(0); }
/* * Print out protocol statistics or control blocks (per sflag). * If the interface was not specifically requested, and the symbol * is not in the namelist, ignore this one. */ static void printproto(struct protox *tp, const char *name, u_long ncpusaddr) { void (*pr)(u_long, const char *, int); u_long off; if (sflag) { if (iflag) { if (tp->pr_istats) intpr(interval, nl[N_IFNET].n_value, tp->pr_istats, ncpusaddr); else if (pflag) printf("%s: no per-interface stats routine\n", tp->pr_name); return; } else { pr = tp->pr_stats; if (!pr) { if (pflag) printf("%s: no stats routine\n", tp->pr_name); return; } off = tp->pr_usesysctl ? tp->pr_usesysctl : nl[tp->pr_sindex].n_value; } } else { pr = tp->pr_cblocks; if (!pr) { if (pflag) printf("%s: no PCB routine\n", tp->pr_name); return; } off = tp->pr_usesysctl ? tp->pr_usesysctl : nl[tp->pr_index].n_value; } if (pr != NULL && (off || af != AF_UNSPEC)) (*pr)(off, name, af); }
int main(int argc, char **argv) { u_int interval; int clientOnly = -1; int serverOnly = -1; int newStats = 0; int ch; char *memf, *nlistf; int mntlen, i; char buf[1024]; struct statfs *mntbuf; struct nfscl_dumpmntopts dumpmntopts; interval = 0; memf = nlistf = NULL; argc = xo_parse_args(argc, argv); if (argc < 0) exit(1); xo_set_version(NFSSTAT_XO_VERSION); while ((ch = getopt(argc, argv, "cdEesWM:mN:w:zq")) != -1) switch(ch) { case 'M': memf = optarg; break; case 'm': /* Display mount options for NFS mount points. */ mntlen = getmntinfo(&mntbuf, MNT_NOWAIT); for (i = 0; i < mntlen; i++) { if (strcmp(mntbuf->f_fstypename, "nfs") == 0) { dumpmntopts.ndmnt_fname = mntbuf->f_mntonname; dumpmntopts.ndmnt_buf = buf; dumpmntopts.ndmnt_blen = sizeof(buf); if (nfssvc(NFSSVC_DUMPMNTOPTS, &dumpmntopts) >= 0) printf("%s on %s\n%s\n", mntbuf->f_mntfromname, mntbuf->f_mntonname, buf); else if (errno == EPERM) errx(1, "Only priviledged users" " can use the -m option"); } mntbuf++; } exit(0); case 'N': nlistf = optarg; break; case 'W': widemode = 1; break; case 'w': interval = atoi(optarg); break; case 'c': clientOnly = 1; if (serverOnly < 0) serverOnly = 0; break; case 'd': newStats = 1; if (interval == 0) interval = 1; break; case 's': serverOnly = 1; if (clientOnly < 0) clientOnly = 0; break; case 'z': zflag = 1; break; case 'E': if (extra_output != 0) xo_err(1, "-e and -E are mutually exclusive"); extra_output = 2; break; case 'e': if (extra_output != 0) xo_err(1, "-e and -E are mutually exclusive"); extra_output = 1; break; case 'q': printtitle = 0; break; case '?': default: usage(); } argc -= optind; argv += optind; #define BACKWARD_COMPATIBILITY #ifdef BACKWARD_COMPATIBILITY if (*argv) { interval = atoi(*argv); if (*++argv) { nlistf = *argv; if (*++argv) memf = *argv; } } #endif if (modfind("nfscommon") < 0) xo_err(1, "NFS client/server not loaded"); if (interval) { exp_sidewaysintpr(interval, clientOnly, serverOnly, newStats); } else { xo_open_container("nfsstat"); if (extra_output != 0) exp_intpr(clientOnly, serverOnly, extra_output - 1); else intpr(clientOnly, serverOnly); xo_close_container("nfsstat"); } xo_finish(); exit(0); }
int main(int argc, char *argv[]) { char *hostname = NULL; struct protoent *p; struct protox *tp = NULL; /* for printing cblocks & stats */ int allprotos = 1; char *community = NULL; char *argp; struct snmp_session session; int dest_port = SNMP_PORT; int timeout = SNMP_DEFAULT_TIMEOUT; int version = SNMP_VERSION_1; int arg; init_mib(); /* * Usage: snmpnetstatwalk -v 1 [-q] hostname community ... or: * Usage: snmpnetstat [-v 2 ] [-q] hostname noAuth ... */ for(arg = 1; arg < argc; arg++){ if (argv[arg][0] == '-'){ switch(argv[arg][1]){ case 'V': fprintf(stderr,"UCD-snmp version: %s\n", VersionInfo); exit(0); break; case 'h': usage(); exit(0); case 'd': snmp_set_dump_packet(1); break; case 'q': snmp_set_quick_print(1); break; case 'D': debug_register_tokens(&argv[arg][2]); snmp_set_do_debugging(1); break; case 'p': if (argv[arg][2] != 0) dest_port = atoi(argv[arg]+2); else if (++arg == argc) { usage(); exit(1); } else dest_port = atoi(argv[arg]); break; case 't': if (argv[arg][2] != 0) timeout = atoi(argv[arg]+2); else if (++arg == argc) { usage(); exit(1); } else timeout = atoi(argv[arg]); timeout *= 1000000; break; case 'c': if (argv[arg][2] != 0) community = argv[arg]+2; else if (++arg == argc) { usage(); exit(1); } else community = argv[arg]; break; case 'v': if (argv[arg][2] != 0) argp = argv[arg]+2; else if (arg == argc) { usage(); exit(1); } else argp = argv[arg]; if (!strcmp(argp,"1")) version = SNMP_VERSION_1; else if (!strcmp(argp,"2c")) version = SNMP_VERSION_2c; else { fprintf(stderr, "Invalid version: %s\n", argp); usage(); exit(1); } break; case 'a': aflag++; break; case 'i': iflag++; break; case 'o': oflag++; break; case 'n': nflag++; break; case 'r': rflag++; break; case 's': sflag++; break; case 'P': if (++arg == argc) { usage(); exit(1); } if ((tp = name2protox(argv [arg])) == NULLPROTOX) { fprintf(stderr, "%s: unknown or uninstrumented protocol\n", argv [arg]); exit(1); } allprotos = 0; tp->pr_wanted = 1; break; case 'I': iflag++; if (*(intrface = argv[arg] + 2) == 0) { if (++arg == argc) { usage(); exit(1); } if ((intrface = argv[arg]) == 0) break; } break; default: printf("invalid option: -%c\n", argv[arg][1]); break; } continue; } if (hostname == NULL){ hostname = argv[arg]; } else if ((version == SNMP_VERSION_1 || version == SNMP_VERSION_2c) && community == NULL){ community = argv[arg]; } else if (isdigit(argv[arg][0])) { interval = atoi(argv[arg]); if (interval <= 0){ usage(); exit(1); } iflag++; } else { usage(); exit(1); } } if (!hostname || ((version == SNMP_VERSION_1 || version == SNMP_VERSION_2c) && !community)) { usage(); exit(1); } snmp_sess_init(&session); session.peername = hostname; session.remote_port = dest_port; session.timeout = timeout; if (version == SNMP_VERSION_1 || version == SNMP_VERSION_2c){ session.version = version; session.community = (u_char *)community; session.community_len = strlen((char *)community); } SOCK_STARTUP; /* open an SNMP session */ Session = snmp_open(&session); if (Session == NULL){ /* diagnose snmp_open errors with the input struct snmp_session pointer */ snmp_sess_perror("snmpnetstat", &session); SOCK_CLEANUP; exit(1); } /* * Keep file descriptors open to avoid overhead * of open/close on each call to get* routines. */ sethostent(1); setnetent(1); setprotoent(1); setservent(1); if (iflag) { intpr(interval); } if (oflag) { intpro(interval); } if (rflag) { if (sflag) rt_stats(); else routepr(); } if (iflag || rflag || oflag) ; else { while ((p = getprotoent46())) { for (tp = protox; tp->pr_name; tp++) { if (strcmp(tp->pr_name, p->p_name) == 0) break; } if (tp->pr_name == 0 || (tp->pr_wanted == 0 && allprotos == 0)) continue; if (sflag) { if (tp->pr_stats) (*tp->pr_stats)(); } else if (tp->pr_cblocks) (*tp->pr_cblocks)(tp->pr_name); } } /* ! iflag, rflag, oflag */ endprotoent(); endservent(); endnetent(); endhostent(); snmp_close(Session); SOCK_CLEANUP; return 0; }
int main(int argc, char *argv[]) { char *hostname = NULL; struct protoent *p; struct protox *tp = NULL; /* for printing cblocks & stats */ int allprotos = 1; char *community = NULL; char *argp; netsnmp_session session; int timeout = SNMP_DEFAULT_TIMEOUT; int version = SNMP_DEFAULT_VERSION; int arg; #ifndef DISABLE_MIB_LOADING init_mib(); #endif /* DISABLE_MIB_LOADING */ /* * Usage: snmpnetstatwalk -v 1 [-q] hostname community ... or: * Usage: snmpnetstat [-v 2 ] [-q] hostname noAuth ... */ while ((arg = getopt(argc, argv, "VhdqD:t:c:v:aionrsP:I:")) != EOF) { switch (arg) { case 'V': fprintf(stderr, "NET-SNMP version: %s\n", netsnmp_get_version()); exit(0); break; case 'h': usage(); exit(0); case 'd': snmp_set_dump_packet(1); break; case 'q': snmp_set_quick_print(1); break; case 'D': debug_register_tokens(optarg); snmp_set_do_debugging(1); break; case 't': timeout = atoi(optarg); timeout *= 1000000; break; case 'c': community = optarg; break; case 'v': argp = optarg; version = -1; #ifndef DISABLE_SNMPV1 if (!strcasecmp(argp, "1")) version = SNMP_VERSION_1; #endif #ifndef DISABLE_SNMPV2C if (!strcasecmp(argp, "2c")) version = SNMP_VERSION_2c; #endif if (version == -1) { fprintf(stderr, "Invalid version: %s\n", argp); usage(); exit(1); } break; case 'a': aflag++; break; case 'i': iflag++; break; case 'o': oflag++; break; case 'n': nflag++; break; case 'r': rflag++; break; case 's': sflag++; break; case 'P': if ((tp = name2protox(optarg)) == NULLPROTOX) { fprintf(stderr, "%s: unknown or uninstrumented protocol\n", optarg); exit(1); } allprotos = 0; tp->pr_wanted = 1; break; case 'I': iflag++; intrface = optarg; break; default: exit(1); break; } continue; } init_snmp("snmpapp"); snmp_enable_stderrlog(); if (version == SNMP_DEFAULT_VERSION) { version = netsnmp_ds_get_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_SNMPVERSION); if (!version) { switch (DEFAULT_SNMP_VERSION) { #ifndef DISABLE_SNMPV1 case 1: version = SNMP_VERSION_1; break; #endif #ifndef DISABLE_SNMPV2C case 2: version = SNMP_VERSION_2c; break; #endif case 3: version = SNMP_VERSION_3; break; } #ifndef DISABLE_SNMPV1 } else if (version == NETSNMP_DS_SNMP_VERSION_1) { /* Bogus value. version1 = 0 */ version = SNMP_VERSION_1; #endif } } if (optind < argc) { hostname = argv[optind++]; } else { fprintf(stderr, "Missing host name.\n"); exit(1); } if (community == NULL) { community = netsnmp_ds_get_string(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_COMMUNITY); } if (optind < argc && isdigit(argv[optind][0])) { interval = atoi(argv[optind++]); if (interval <= 0) { usage(); exit(1); } iflag++; } if (optind < argc) { usage(); exit(1); } snmp_sess_init(&session); session.peername = hostname; session.timeout = timeout; #if !defined(DISABLE_SNMPV1) || !defined(DISABLE_SNMPV2C) if (version != SNMP_VERSION_3) { if (!community) { fprintf(stderr, "Missing community name.\n"); exit(1); } session.version = version; session.community = (u_char *) community; session.community_len = strlen(community); } #endif SOCK_STARTUP; /* * open an SNMP session */ Session = snmp_open(&session); if (Session == NULL) { /* * diagnose snmp_open errors with the input netsnmp_session pointer */ snmp_sess_perror("snmpnetstat", &session); SOCK_CLEANUP; exit(1); } /* * Keep file descriptors open to avoid overhead * of open/close on each call to get* routines. */ sethostent(1); setnetent(1); setprotoent(1); setservent(1); if (iflag) { intpr(interval); } if (oflag) { intpro(interval); } if (rflag) { if (sflag) rt_stats(); else routepr(); } if (!(iflag || rflag || oflag)) { while ((p = getprotoent46())) { for (tp = protox; tp->pr_name; tp++) { if (strcmp(tp->pr_name, p->p_name) == 0) break; } if (tp->pr_name == 0 || (tp->pr_wanted == 0 && allprotos == 0)) continue; if (sflag) { if (tp->pr_stats) (*tp->pr_stats) (); } else if (tp->pr_cblocks) (*tp->pr_cblocks) (tp->pr_name); } } /* ! iflag, rflag, oflag */ endprotoent(); endservent(); endnetent(); endhostent(); snmp_close(Session); SOCK_CLEANUP; return 0; }
int main(int argc, char *argv[]) { struct protox *tp = NULL; /* for printing cblocks & stats */ int ch; af = AF_UNSPEC; #ifdef LISP while ((ch = getopt(argc, argv, "AaBbdf:ghI:iLlM:mN:np:rSstuWw:zX")) != -1) #else while ((ch = getopt(argc, argv, "AaBbdf:ghI:iLlM:mN:np:rSstuWw:z")) != -1) #endif /* LISP */ switch(ch) { case 'A': Aflag = 1; break; case 'a': aflag = 1; break; case 'B': Bflag = 1; break; case 'b': bflag = 1; break; case 'd': dflag = 1; break; case 'f': if (strcmp(optarg, "ipx") == 0) af = AF_IPX; else if (strcmp(optarg, "inet") == 0) af = AF_INET; #ifdef INET6 else if (strcmp(optarg, "inet6") == 0) af = AF_INET6; #endif #ifdef IPSEC else if (strcmp(optarg, "pfkey") == 0) af = PF_KEY; #endif else if (strcmp(optarg, "unix") == 0) af = AF_UNIX; else if (strcmp(optarg, "atalk") == 0) af = AF_APPLETALK; #ifdef NETGRAPH else if (strcmp(optarg, "ng") == 0 || strcmp(optarg, "netgraph") == 0) af = AF_NETGRAPH; #endif else if (strcmp(optarg, "link") == 0) af = AF_LINK; else { errx(1, "%s: unknown address family", optarg); } break; case 'g': gflag = 1; break; case 'h': hflag = 1; break; case 'I': { char *cp; iflag = 1; for (cp = interface = optarg; isalpha(*cp); cp++) continue; unit = atoi(cp); break; } case 'i': iflag = 1; break; case 'L': Lflag = 1; break; case 'M': memf = optarg; break; case 'm': mflag = 1; break; case 'N': nlistf = optarg; break; case 'n': numeric_addr = numeric_port = 1; break; case 'p': if ((tp = name2protox(optarg)) == NULL) { errx(1, "%s: unknown or uninstrumented protocol", optarg); } pflag = 1; break; case 'r': rflag = 1; break; #ifdef LISP case 'X': Xflag = 1; break; #endif /* LISP */ case 's': ++sflag; break; case 'S': numeric_addr = 1; break; case 't': tflag = 1; break; case 'u': af = AF_UNIX; break; case 'W': case 'l': Wflag = 1; break; case 'w': interval = atoi(optarg); iflag = 1; break; case 'z': zflag = 1; break; case '?': default: usage(); } argv += optind; argc -= optind; #define BACKWARD_COMPATIBILITY #ifdef BACKWARD_COMPATIBILITY if (*argv) { if (isdigit(**argv)) { interval = atoi(*argv); if (interval <= 0) usage(); ++argv; iflag = 1; } if (*argv) { nlistf = *argv; if (*++argv) memf = *argv; } } #endif /* * Discard setgid privileges if not the running kernel so that bad * guys can't print interesting stuff from kernel memory. */ live = (nlistf == NULL && memf == NULL); if (!live) setgid(getgid()); if (Bflag) { if (!live) usage(); bpf_stats(interface); exit(0); } if (mflag) { if (!live) { if (kread(0, NULL, 0) == 0) mbpr(kvmd, nl[N_MBSTAT].n_value); } else mbpr(NULL, 0); exit(0); } #if 0 /* * Keep file descriptors open to avoid overhead * of open/close on each call to get* routines. */ sethostent(1); setnetent(1); #else /* * This does not make sense any more with DNS being default over * the files. Doing a setXXXXent(1) causes a tcp connection to be * used for the queries, which is slower. */ #endif kread(0, NULL, 0); if (iflag && !sflag) { intpr(interval, nl[N_IFNET].n_value, NULL); exit(0); } if (rflag) { if (sflag) rt_stats(nl[N_RTSTAT].n_value, nl[N_RTTRASH].n_value); else routepr(nl[N_RTREE].n_value); exit(0); } #ifdef LISP if (Xflag) { if (sflag) { map_stats(); exit(0); } else { kread(0, 0, 0); mappr(nl[N_MAPTREE].n_value); exit(0); }; }; #endif /* LISP */ if (gflag) { if (sflag) { if (af == AF_INET || af == AF_UNSPEC) mrt_stats(nl[N_MRTSTAT].n_value); #ifdef INET6 if (af == AF_INET6 || af == AF_UNSPEC) mrt6_stats(nl[N_MRT6STAT].n_value); #endif } else { if (af == AF_INET || af == AF_UNSPEC) mroutepr(nl[N_MFCTABLE].n_value, nl[N_VIFTABLE].n_value); #ifdef INET6 if (af == AF_INET6 || af == AF_UNSPEC) mroute6pr(nl[N_MF6CTABLE].n_value, nl[N_MIF6TABLE].n_value); #endif } ifmalist_dump(); exit(0); } if (tp) { printproto(tp, tp->pr_name); exit(0); } if (af == AF_INET || af == AF_UNSPEC) for (tp = protox; tp->pr_name; tp++) printproto(tp, tp->pr_name); #ifdef INET6 if (af == AF_INET6 || af == AF_UNSPEC) for (tp = ip6protox; tp->pr_name; tp++) printproto(tp, tp->pr_name); #endif /*INET6*/ #ifdef IPSEC if (af == PF_KEY || af == AF_UNSPEC) for (tp = pfkeyprotox; tp->pr_name; tp++) printproto(tp, tp->pr_name); #endif /*IPSEC*/ #ifdef IPX if (af == AF_IPX || af == AF_UNSPEC) { for (tp = ipxprotox; tp->pr_name; tp++) printproto(tp, tp->pr_name); } #endif /* IPX */ if (af == AF_APPLETALK || af == AF_UNSPEC) for (tp = atalkprotox; tp->pr_name; tp++) printproto(tp, tp->pr_name); #ifdef NETGRAPH if (af == AF_NETGRAPH || af == AF_UNSPEC) for (tp = netgraphprotox; tp->pr_name; tp++) printproto(tp, tp->pr_name); #endif /* NETGRAPH */ if ((af == AF_UNIX || af == AF_UNSPEC) && !sflag) unixpr(nl[N_UNP_COUNT].n_value, nl[N_UNP_GENCNT].n_value, nl[N_UNP_DHEAD].n_value, nl[N_UNP_SHEAD].n_value); exit(0); }
int main(int argc, char *argv[]) { int c; #ifdef STREAMS char *dev; #endif interface = "ppp0"; if ((progname = strrchr(argv[0], '/')) == NULL) progname = argv[0]; else ++progname; while ((c = getopt(argc, argv, "advrzc:w:")) != -1) { switch (c) { case 'a': ++aflag; break; case 'd': ++dflag; break; case 'v': ++vflag; break; case 'r': ++rflag; break; case 'z': ++zflag; break; case 'c': count = atoi(optarg); if (count <= 0) usage(); break; case 'w': interval = atoi(optarg); if (interval <= 0) usage(); break; default: usage(); } } argc -= optind; argv += optind; if (!interval && count) interval = 5; if (interval && !count) infinite = 1; if (!interval && !count) count = 1; if (aflag) dflag = 0; if (argc > 1) usage(); if (argc > 0) interface = argv[0]; if (sscanf(interface, "ppp%d", &unit) != 1) { fprintf(stderr, "%s: invalid interface '%s' specified\n", progname, interface); } #ifndef STREAMS { struct ifreq ifr; s = socket(AF_INET, SOCK_DGRAM, 0); if (s < 0) { fprintf(stderr, "%s: ", progname); perror("couldn't create IP socket"); exit(1); } #ifdef _linux_ #undef ifr_name #define ifr_name ifr_ifrn.ifrn_name #endif strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)); if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&ifr) < 0) { fprintf(stderr, "%s: nonexistent interface '%s' specified\n", progname, interface); exit(1); } } #else /* STREAMS */ #ifdef __osf__ dev = "/dev/streams/ppp"; #else dev = "/dev/ppp"; #endif if ((s = open(dev, O_RDONLY)) < 0) { fprintf(stderr, "%s: couldn't open ", progname); perror(dev); exit(1); } if (strioctl(s, PPPIO_ATTACH, &unit, sizeof(int), 0) < 0) { fprintf(stderr, "%s: ppp%d is not available\n", progname, unit); exit(1); } #endif /* STREAMS */ intpr(); exit(0); }
int main(int argc, char *argv[]) { netsnmp_session session; struct protoent *p; char *cp; af = AF_UNSPEC; cp = strrchr( argv[0], '/' ); if (cp) progname = cp+1; else progname = argv[0]; switch (snmp_parse_args( argc, argv, &session, "C:iRs", optProc)) { case NETSNMP_PARSE_ARGS_ERROR: exit(1); case NETSNMP_PARSE_ARGS_SUCCESS_EXIT: exit(0); case NETSNMP_PARSE_ARGS_ERROR_USAGE: usage(); exit(1); default: break; } /* * Check argc vs optind ?? */ argv += optind; argc -= optind; /* * Open an SNMP session. */ SOCK_STARTUP; ss = snmp_open(&session); if (ss == NULL) { /* * diagnose snmp_open errors with the input netsnmp_session pointer */ snmp_sess_perror("snmpnetstat", &session); SOCK_CLEANUP; exit(1); } /* * Omitted: * Privilege handling * "Backward Compatibility" * Kernel namelis handling */ if (mflag) { /* mbpr(nl[N_MBSTAT].n_value, nl[N_MBPOOL].n_value, nl[N_MCLPOOL].n_value); */ exit(0); } if (pflag) { printproto(tp, tp->pr_name); exit(0); } /* * Keep file descriptors open to avoid overhead * of open/close on each call to get* routines. */ sethostent(1); setnetent(1); if (iflag) { intpr(interval); exit(0); } if (rflag) { /* if (sflag) rt_stats(); else */ if (Lflag || routexpr(af) == 0) { if (route4pr(af) == 0 && af == AF_INET) routepr(); route6pr(af); } exit(0); } /* if (gflag) { if (sflag) { if (af == AF_INET || af == AF_UNSPEC) mrt_stats(nl[N_MRTPROTO].n_value, nl[N_MRTSTAT].n_value); #ifdef NETSNMP_ENABLE_IPV6 if (af == AF_INET6 || af == AF_UNSPEC) mrt6_stats(nl[N_MRT6PROTO].n_value, nl[N_MRT6STAT].n_value); #endif } else { if (af == AF_INET || af == AF_UNSPEC) mroutepr(nl[N_MRTPROTO].n_value, nl[N_MFCHASHTBL].n_value, nl[N_MFCHASH].n_value, nl[N_VIFTABLE].n_value); #ifdef NETSNMP_ENABLE_IPV6 if (af == AF_INET6 || af == AF_UNSPEC) mroute6pr(nl[N_MRT6PROTO].n_value, nl[N_MF6CTABLE].n_value, nl[N_MIF6TABLE].n_value); #endif } exit(0); } */ setservent(1); if (af == AF_UNSPEC && Lflag) { setprotoent(1); /* ugh, this is O(MN) ... why do we do this? */ while ((p = getprotoent())) { for (tp = protox; tp->pr_name; tp++) if (strcmp(tp->pr_name, p->p_name) == 0) if (tp->pr_name && tp->pr_wanted) printproto(tp, p->p_name); } endprotoent(); } if (af == AF_UNSPEC && !Lflag) for (tp = ipxprotox; tp->pr_name; tp++) printproto(tp, tp->pr_name); if (af == AF_INET) for (tp = protox; tp->pr_name; tp++) printproto(tp, tp->pr_name); if (af == AF_INET6) for (tp = ip6protox; tp->pr_name; tp++) printproto(tp, tp->pr_name); /* if (af == AF_IPX || af == AF_UNSPEC) for (tp = ipxprotox; tp->pr_name; tp++) printproto(tp, tp->pr_name); if (af == AF_NS || af == AF_UNSPEC) for (tp = nsprotox; tp->pr_name; tp++) printproto(tp, tp->pr_name); if ((af == AF_UNIX || af == AF_UNSPEC) && !sflag) unixpr(nl[N_UNIXSW].n_value); if (af == AF_APPLETALK || af == AF_UNSPEC) for (tp = atalkprotox; tp->pr_name; tp++) printproto(tp, tp->pr_name); */ exit(0); }
int main(int argc, char *argv[]) { struct protox *tp = NULL; /* for printing cblocks & stats */ int ch; int fib = -1; char *endptr; af = AF_UNSPEC; while ((ch = getopt(argc, argv, "46AaBbdF:f:ghI:iLlM:mN:np:Qq:RrSTsuWw:xz")) != -1) switch(ch) { case '4': #ifdef INET af = AF_INET; #else errx(1, "IPv4 support is not compiled in"); #endif break; case '6': #ifdef INET6 af = AF_INET6; #else errx(1, "IPv6 support is not compiled in"); #endif break; case 'A': Aflag = 1; break; case 'a': aflag = 1; break; case 'B': Bflag = 1; break; case 'b': bflag = 1; break; case 'd': dflag = 1; break; case 'F': fib = strtol(optarg, &endptr, 0); if (*endptr != '\0' || (fib == 0 && (errno == EINVAL || errno == ERANGE))) errx(1, "%s: invalid fib", optarg); break; case 'f': if (strcmp(optarg, "inet") == 0) af = AF_INET; #ifdef INET6 else if (strcmp(optarg, "inet6") == 0) af = AF_INET6; #endif #ifdef IPSEC else if (strcmp(optarg, "pfkey") == 0) af = PF_KEY; #endif else if (strcmp(optarg, "unix") == 0) af = AF_UNIX; #ifdef NETGRAPH else if (strcmp(optarg, "ng") == 0 || strcmp(optarg, "netgraph") == 0) af = AF_NETGRAPH; #endif else if (strcmp(optarg, "link") == 0) af = AF_LINK; else { errx(1, "%s: unknown address family", optarg); } break; case 'g': gflag = 1; break; case 'h': hflag = 1; break; case 'I': { char *cp; iflag = 1; for (cp = interface = optarg; isalpha(*cp); cp++) continue; unit = atoi(cp); break; } case 'i': iflag = 1; break; case 'L': Lflag = 1; break; case 'M': memf = optarg; break; case 'm': mflag = 1; break; case 'N': nlistf = optarg; break; case 'n': numeric_addr = numeric_port = 1; break; case 'p': if ((tp = name2protox(optarg)) == NULL) { errx(1, "%s: unknown or uninstrumented protocol", optarg); } pflag = 1; break; case 'Q': Qflag = 1; break; case 'q': noutputs = atoi(optarg); if (noutputs != 0) noutputs++; break; case 'r': rflag = 1; break; case 'R': Rflag = 1; break; case 's': ++sflag; break; case 'S': numeric_addr = 1; break; case 'u': af = AF_UNIX; break; case 'W': case 'l': Wflag = 1; break; case 'w': interval = atoi(optarg); iflag = 1; break; case 'T': Tflag = 1; break; case 'x': xflag = 1; break; case 'z': zflag = 1; break; case '?': default: usage(); } argv += optind; argc -= optind; #define BACKWARD_COMPATIBILITY #ifdef BACKWARD_COMPATIBILITY if (*argv) { if (isdigit(**argv)) { interval = atoi(*argv); if (interval <= 0) usage(); ++argv; iflag = 1; } if (*argv) { nlistf = *argv; if (*++argv) memf = *argv; } } #endif /* * Discard setgid privileges if not the running kernel so that bad * guys can't print interesting stuff from kernel memory. */ live = (nlistf == NULL && memf == NULL); if (!live) setgid(getgid()); if (xflag && Tflag) errx(1, "-x and -T are incompatible, pick one."); if (Bflag) { if (!live) usage(); bpf_stats(interface); exit(0); } if (mflag) { if (!live) { if (kread(0, NULL, 0) == 0) mbpr(kvmd, nl[N_SFSTAT].n_value); } else mbpr(NULL, 0); exit(0); } if (Qflag) { if (!live) { if (kread(0, NULL, 0) == 0) netisr_stats(kvmd); } else netisr_stats(NULL); exit(0); } #if 0 /* * Keep file descriptors open to avoid overhead * of open/close on each call to get* routines. */ sethostent(1); setnetent(1); #else /* * This does not make sense any more with DNS being default over * the files. Doing a setXXXXent(1) causes a tcp connection to be * used for the queries, which is slower. */ #endif if (iflag && !sflag) { intpr(interval, NULL, af); exit(0); } if (rflag) { if (sflag) { rt_stats(); flowtable_stats(); } else routepr(fib, af); exit(0); } if (gflag) { if (sflag) { if (af == AF_INET || af == AF_UNSPEC) mrt_stats(); #ifdef INET6 if (af == AF_INET6 || af == AF_UNSPEC) mrt6_stats(); #endif } else { if (af == AF_INET || af == AF_UNSPEC) mroutepr(); #ifdef INET6 if (af == AF_INET6 || af == AF_UNSPEC) mroute6pr(); #endif } exit(0); } /* Load all necessary kvm symbols */ kresolve_list(nl); if (tp) { printproto(tp, tp->pr_name); exit(0); } if (af == AF_INET || af == AF_UNSPEC) for (tp = protox; tp->pr_name; tp++) printproto(tp, tp->pr_name); #ifdef INET6 if (af == AF_INET6 || af == AF_UNSPEC) for (tp = ip6protox; tp->pr_name; tp++) printproto(tp, tp->pr_name); #endif /*INET6*/ #ifdef IPSEC if (af == PF_KEY || af == AF_UNSPEC) for (tp = pfkeyprotox; tp->pr_name; tp++) printproto(tp, tp->pr_name); #endif /*IPSEC*/ #ifdef NETGRAPH if (af == AF_NETGRAPH || af == AF_UNSPEC) for (tp = netgraphprotox; tp->pr_name; tp++) printproto(tp, tp->pr_name); #endif /* NETGRAPH */ if ((af == AF_UNIX || af == AF_UNSPEC) && !sflag) unixpr(nl[N_UNP_COUNT].n_value, nl[N_UNP_GENCNT].n_value, nl[N_UNP_DHEAD].n_value, nl[N_UNP_SHEAD].n_value, nl[N_UNP_SPHEAD].n_value); exit(0); }
int main(int argc, char **argv) { struct protox *tp = NULL; /* for printing cblocks & stats */ int ch; int n; af = AF_UNSPEC; while ((ch = getopt(argc, argv, "Aabc:df:gI:iLlM:mN:nPp:rSsBtuWw:z")) != -1) switch(ch) { case 'A': Aflag = 1; break; case 'a': aflag = 1; break; case 'b': bflag = 1; break; case 'c': kread(0, 0, 0); kread(nl[N_NCPUS].n_value, (char *)&n, sizeof(n)); cpuflag = strtol(optarg, NULL, 0); if (cpuflag < 0 || cpuflag >= n) errx(1, "cpu %d does not exist", cpuflag); break; case 'd': dflag = 1; break; case 'f': if (strcmp(optarg, "ipx") == 0) af = AF_IPX; else if (strcmp(optarg, "inet") == 0) af = AF_INET; #ifdef INET6 else if (strcmp(optarg, "inet6") == 0) af = AF_INET6; #endif /*INET6*/ #ifdef INET6 else if (strcmp(optarg, "pfkey") == 0) af = PF_KEY; #endif /*INET6*/ else if (strcmp(optarg, "unix") == 0) af = AF_UNIX; else if (strcmp(optarg, "ng") == 0 || strcmp(optarg, "netgraph") == 0) af = AF_NETGRAPH; #ifdef ISO else if (strcmp(optarg, "iso") == 0) af = AF_ISO; #endif else if (strcmp(optarg, "link") == 0) af = AF_LINK; else if (strcmp(optarg, "mpls") == 0) af = AF_MPLS; else { errx(1, "%s: unknown address family", optarg); } break; case 'g': gflag = 1; break; case 'I': { char *cp; iflag = 1; for (cp = interface = optarg; isalpha(*cp); cp++) continue; unit = atoi(cp); break; } case 'i': iflag = 1; break; case 'L': Lflag = 1; break; case 'M': memf = optarg; break; case 'm': mflag = 1; break; case 'N': nlistf = optarg; break; case 'n': numeric_addr = numeric_port = 1; break; case 'P': Pflag = 1; break; case 'p': if ((tp = name2protox(optarg)) == NULL) { errx(1, "%s: unknown or uninstrumented protocol", optarg); } pflag = 1; break; case 'r': rflag = 1; break; case 's': ++sflag; break; case 'S': numeric_addr = 1; break; case 'B': Bflag = 1; break; case 't': tflag = 1; break; case 'u': af = AF_UNIX; break; case 'W': case 'l': Wflag = 1; break; case 'w': interval = atoi(optarg); iflag = 1; break; case 'z': zflag = 1; break; case '?': default: usage(); } argv += optind; argc -= optind; #define BACKWARD_COMPATIBILITY #ifdef BACKWARD_COMPATIBILITY if (*argv) { if (isdigit(**argv)) { interval = atoi(*argv); if (interval <= 0) usage(); ++argv; iflag = 1; } if (*argv) { nlistf = *argv; if (*++argv) memf = *argv; } } #endif /* * Discard setgid privileges if not the running kernel so that bad * guys can't print interesting stuff from kernel memory. */ if (nlistf != NULL || memf != NULL) setgid(getgid()); if (mflag) { if (memf != NULL) { if (kread(0, 0, 0) == 0) mbpr(nl[N_MBSTAT].n_value, nl[N_MBTYPES].n_value, nl[N_NMBCLUSTERS].n_value, nl[N_NMBJCLUSTERS].n_value, nl[N_NMBUFS].n_value, nl[N_NCPUS].n_value); } else { mbpr(0, 0, 0, 0, 0, 0); } exit(0); } #if 0 /* * Keep file descriptors open to avoid overhead * of open/close on each call to get* routines. */ sethostent(1); setnetent(1); #else /* * This does not make sense any more with DNS being default over * the files. Doing a setXXXXent(1) causes a tcp connection to be * used for the queries, which is slower. */ #endif if (iflag && !sflag) { kread(0, 0, 0); intpr(interval, nl[N_IFNET].n_value, NULL, nl[N_NCPUS].n_value); exit(0); } if (rflag) { kread(0, 0, 0); if (sflag) rt_stats(); else routepr(nl[N_RTREE].n_value); exit(0); } if (gflag) { kread(0, 0, 0); if (sflag) { if (af == AF_INET || af == AF_UNSPEC) mrt_stats(nl[N_MRTSTAT].n_value); #ifdef INET6 if (af == AF_INET6 || af == AF_UNSPEC) mrt6_stats(nl[N_MRT6STAT].n_value); #endif } else { if (af == AF_INET || af == AF_UNSPEC) mroutepr(nl[N_MFCTABLE].n_value, nl[N_VIFTABLE].n_value); #ifdef INET6 if (af == AF_INET6 || af == AF_UNSPEC) mroute6pr(nl[N_MF6CTABLE].n_value, nl[N_MIF6TABLE].n_value); #endif } exit(0); } kread(0, 0, 0); if (tp) { printproto(tp, tp->pr_name, nl[N_NCPUS].n_value); exit(0); } if (af == AF_INET || af == AF_UNSPEC) for (tp = protox; tp->pr_name; tp++) printproto(tp, tp->pr_name, nl[N_NCPUS].n_value); #ifdef INET6 if (af == AF_INET6 || af == AF_UNSPEC) for (tp = ip6protox; tp->pr_name; tp++) printproto(tp, tp->pr_name, nl[N_NCPUS].n_value); #endif /*INET6*/ #ifdef IPSEC if (af == PF_KEY || af == AF_UNSPEC) for (tp = pfkeyprotox; tp->pr_name; tp++) printproto(tp, tp->pr_name, nl[N_NCPUS].n_value); #endif /*IPSEC*/ if (af == AF_IPX || af == AF_UNSPEC) { kread(0, 0, 0); for (tp = ipxprotox; tp->pr_name; tp++) printproto(tp, tp->pr_name, nl[N_NCPUS].n_value); } if (af == AF_NETGRAPH || af == AF_UNSPEC) for (tp = netgraphprotox; tp->pr_name; tp++) printproto(tp, tp->pr_name, nl[N_NCPUS].n_value); #ifdef ISO if (af == AF_ISO || af == AF_UNSPEC) for (tp = isoprotox; tp->pr_name; tp++) printproto(tp, tp->pr_name, nl[N_NCPUS].n_value); #endif if ((af == AF_UNIX || af == AF_UNSPEC) && !Lflag && !sflag) unixpr(); exit(0); }
int main(const int argc, const char* argv[]) { const char* prgm_path = FCGX_GetParam("PROGRAM_PATH", environ); if(!prgm_path) { cerr << "Unable to find program, please ensure the 'PROGRAM_PATH' variable has been set correctly." << endl; exit(1); } // load program srand(time(NULL)); rand(); Loader loader(prgm_path); loader.Load(); // ignore web applications if(!loader.IsWeb()) { cerr << "Please recompile the code to be a web application." << endl; exit(1); } #ifdef _TIMING clock_t start = clock(); #endif // locate starting class and method StackMethod* mthd = loader.GetStartMethod(); if(!mthd) { cerr << "Unable to locate the 'Request(args)' function." << endl; exit(1); } #ifdef _DEBUG cerr << "### Loaded method: " << mthd->GetName() << " ###" << endl; #endif Runtime::StackInterpreter intpr(Loader::GetProgram()); // go into accept loop... FCGX_Stream*in; FCGX_Stream* out; FCGX_Stream* err; FCGX_ParamArray envp; while(mthd && (FCGX_Accept(&in, &out, &err, &envp) >= 0)) { // execute method long* op_stack = new long[CALC_STACK_SIZE]; long* stack_pos = new long; // create request long* req_obj = MemoryManager::Instance()->AllocateObject("FastCgi.Request", op_stack, *stack_pos, false); if(req_obj) { req_obj[0] = (long)in; req_obj[1] = (long)envp; // create response long* res_obj = MemoryManager::Instance()->AllocateObject("FastCgi.Response", op_stack, *stack_pos, false); if(res_obj) { res_obj[0] = (long)out; res_obj[1] = (long)err; // set calling parameters op_stack[0] = (long)req_obj; op_stack[1] = (long)res_obj; *stack_pos = 2; // execute method intpr.Execute((long*)op_stack, (long*)stack_pos, 0, mthd, NULL, false); } else { cerr << ">>> DLL call: Unable to allocate object FastCgi.Response <<" << endl; // TODO: error return 1; } } else { cerr << ">>> DLL call: Unable to allocate object FastCgi.Request <<<" << endl; // TODO: error return 1; } #ifdef _DEBUG cout << "# final stack: pos=" << (*stack_pos) << " #" << endl; if((*stack_pos) > 0) { for(int i = 0; i < (*stack_pos); i++) { cout << "dump: value=" << (void*)(*stack_pos) << endl; } } #endif // clean up delete[] op_stack; op_stack = NULL; delete stack_pos; stack_pos = NULL; #ifdef _DEBUG PrintEnv(out, "Request environment", envp); PrintEnv(out, "Initial environment", environ); #endif } return 0; }
int main(int argc, char **argv) { u_int interval; int clientOnly = -1; int serverOnly = -1; int ch; char *memf, *nlistf; char errbuf[_POSIX2_LINE_MAX]; interval = 0; memf = nlistf = NULL; while ((ch = getopt(argc, argv, "cesWM:N:ow:z")) != -1) switch(ch) { case 'M': memf = optarg; break; case 'N': nlistf = optarg; break; case 'W': widemode = 1; break; case 'w': interval = atoi(optarg); break; case 'c': clientOnly = 1; if (serverOnly < 0) serverOnly = 0; break; case 's': serverOnly = 1; if (clientOnly < 0) clientOnly = 0; break; case 'z': zflag = 1; break; case 'o': if (extra_output != 0) err(1, "-o incompatible with -e"); run_v4 = 0; break; case 'e': if (run_v4 == 0) err(1, "-e incompatible with -o"); extra_output = 1; break; case '?': default: usage(); } argc -= optind; argv += optind; #define BACKWARD_COMPATIBILITY #ifdef BACKWARD_COMPATIBILITY if (*argv) { interval = atoi(*argv); if (*++argv) { nlistf = *argv; if (*++argv) memf = *argv; } } #endif if (run_v4 != 0 && modfind("nfscommon") < 0) errx(1, "new client/server not loaded"); if (run_v4 == 0 && (nlistf != NULL || memf != NULL)) { deadkernel = 1; if ((kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, errbuf)) == 0) { errx(1, "kvm_openfiles: %s", errbuf); } if (kvm_nlist(kd, nl) != 0) { errx(1, "kvm_nlist: can't get names"); } } if (interval) { if (run_v4 > 0) exp_sidewaysintpr(interval, clientOnly, serverOnly); else sidewaysintpr(interval, clientOnly, serverOnly); } else { if (extra_output != 0) exp_intpr(clientOnly, serverOnly); else intpr(clientOnly, serverOnly); } exit(0); }
/* * Print out protocol statistics or control blocks (per sflag). * If the interface was not specifically requested, and the symbol * is not in the namelist, ignore this one. */ static void printproto(struct protox *tp, const char *name, bool *first) { void (*pr)(u_long, const char *, int, int); u_long off; bool doingdblocks = false; if (sflag) { if (iflag) { if (tp->pr_istats) intpr(tp->pr_istats, af); else if (pflag) xo_message("%s: no per-interface stats routine", tp->pr_name); return; } else { pr = tp->pr_stats; if (!pr) { if (pflag) xo_message("%s: no stats routine", tp->pr_name); return; } if (tp->pr_usesysctl && live) off = 0; else if (tp->pr_sindex < 0) { if (pflag) xo_message("%s: stats routine doesn't " "work on cores", tp->pr_name); return; } else off = nl[tp->pr_sindex].n_value; } } else { doingdblocks = true; pr = tp->pr_cblocks; if (!pr) { if (pflag) xo_message("%s: no PCB routine", tp->pr_name); return; } if (tp->pr_usesysctl && live) off = 0; else if (tp->pr_index < 0) { if (pflag) xo_message("%s: PCB routine doesn't work on " "cores", tp->pr_name); return; } else off = nl[tp->pr_index].n_value; } if (pr != NULL && (off || (live && tp->pr_usesysctl) || af != AF_UNSPEC)) { if (doingdblocks && *first) { xo_open_list("socket"); *first = false; } (*pr)(off, name, af, tp->pr_protocol); } }
int main(int argc, char **argv) { u_int interval; int clientOnly = -1; int serverOnly = -1; int ch; char *memf, *nlistf; char errbuf[_POSIX2_LINE_MAX]; interval = 0; memf = nlistf = NULL; while ((ch = getopt(argc, argv, "csWM:N:w:")) != -1) switch(ch) { case 'M': memf = optarg; break; case 'N': nlistf = optarg; break; case 'W': widemode = 1; break; case 'w': interval = atoi(optarg); break; case 'c': clientOnly = 1; if (serverOnly < 0) serverOnly = 0; break; case 's': serverOnly = 1; if (clientOnly < 0) clientOnly = 0; break; case '?': default: usage(); } argc -= optind; argv += optind; #define BACKWARD_COMPATIBILITY #ifdef BACKWARD_COMPATIBILITY if (*argv) { interval = atoi(*argv); if (*++argv) { nlistf = *argv; if (*++argv) memf = *argv; } } #endif if (nlistf != NULL || memf != NULL) { deadkernel = 1; if ((kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, errbuf)) == NULL) { errx(1, "kvm_openfiles: %s", errbuf); } if (kvm_nlist(kd, nl) != 0) { errx(1, "kvm_nlist: can't get names"); } } if (interval) sidewaysintpr(interval, clientOnly, serverOnly); else intpr(clientOnly, serverOnly); exit(0); }