int main(int argc, char **argv) { struct tcpe_error* err = NULL; struct tcpe_client* cl = NULL; Chk(tcpe_client_init(&cl)); printf("%-8s %-20s %-8s %-20s %-8s\n", "CID", "LocalAddr", "LocalPort", "RemAddr", "RemPort"); printf("-------- -------------------- -------- -------------------- --------\n"); printf("\n"); Chk(tcpe_list_conns(cl, connection_callback)); Cleanup: tcpe_client_destroy(&cl); if (err != NULL) { PRINT_AND_FREE(err); return EXIT_FAILURE; } return EXIT_SUCCESS; }
int main(int argc, char **argv) { estats_error* err = NULL; struct estats_nl_client* cl = NULL; estats_val_data* data = NULL; estats_record* record = NULL; estats_val val; char* str; int cid, i, j; struct estats_connection_tuple_ascii tuple_ascii; if (argc < 2) { usage(); exit(EXIT_FAILURE); } cid = atoi(argv[1]); Chk(estats_nl_client_init(&cl)); Chk(estats_val_data_new(&data)); Chk(estats_record_open(&record, "./test-record", "w")); Chk(estats_read_vars(data, cid, cl)); printf("Timestamp sec: %u, usec: %u\n", data->tv.sec, data->tv.usec); Chk(estats_connection_tuple_as_strings(&tuple_ascii, &data->tuple)); printf("Address: %s %s %s %s\n", tuple_ascii.local_addr, tuple_ascii.local_port, tuple_ascii.rem_addr, tuple_ascii.rem_port); for (i = 0; i < data->length; i++) { Chk(estats_val_as_string(&str, &data->val[i], estats_var_array[i].valtype)); printf("%s: %s\n", estats_var_array[i].name, str); free(str); } Chk(estats_record_write_data(record, data)); Cleanup: estats_val_data_free(&data); estats_record_close(&record); estats_nl_client_destroy(&cl); if (err != NULL) { PRINT_AND_FREE(err); return EXIT_FAILURE; } return EXIT_SUCCESS; }
int main(int argc, char **argv) { estats_error* err = NULL; struct estats_nl_client* cl = NULL; estats_val_data* data = NULL; int cid, i, j; int opt, option; char varname[24]; char *endptr, *str; uintmax_t val; if (argc < 4) { usage(); exit(EXIT_FAILURE); } while ((opt = getopt(argc, argv, "h")) != -1) { switch (opt) { case 'h': usage(); exit(EXIT_SUCCESS); break; default: exit(EXIT_FAILURE); break; } } cid = atoi(argv[1]); strncpy(varname, argv[2], 24); str = argv[3]; val = strtoumax(str, &endptr, 10); Chk(estats_nl_client_init(&cl)); Chk(estats_write_var(varname, (uint32_t)val, cid, cl)); Cleanup: estats_nl_client_destroy(&cl); if (err != NULL) { PRINT_AND_FREE(err); return EXIT_FAILURE; } return EXIT_SUCCESS; }
static int cert_verify(void *ud, int failures, const ne_ssl_certificate *c) { char *tmp, from[NE_SSL_VDATELEN], to[NE_SSL_VDATELEN]; const char *ident; ident = ne_ssl_cert_identity(c); if (ident) printf(_("WARNING: Untrusted server certificate presented for `%s':\n"), ident); else puts(_("WARNING: Untrusted server certificate presented:\n")); if (failures & NE_SSL_IDMISMATCH) { printf(_("Certificate was issued to hostname `%s' rather than `%s'\n"), ne_ssl_cert_identity(c), session.uri.host); printf(_("This connection could have been intercepted.\n")); } #define PRINT_AND_FREE(str, dn) \ tmp = ne_ssl_readable_dname(dn); printf(str, tmp); free(tmp) PRINT_AND_FREE(_("Issued to: %s\n"), ne_ssl_cert_subject(c)); PRINT_AND_FREE(_("Issued by: %s\n"), ne_ssl_cert_issuer(c)); ne_ssl_cert_validity(c, from, to); printf(_("Certificate is valid from %s to %s\n"), from, to); if (isatty(STDIN_FILENO)) { printf(_("Do you wish to accept the certificate? (y/n) ")); return !yesno(); } else { printf(_("Certificate rejected.\n")); return -1; } }
int main(int argc, char **argv) { estats_error* err = NULL; struct estats_nl_client* cl = NULL; estats_val_data* data = NULL; // TODO(aka) currently not used // The MIB is generated in the DLKM with the following code: /* hdr = genlmsg_put(msg, 0, 0, &genl_estats_family, 0, TCPE_CMD_INIT); if (nla_put_u32(msg, NLE_ATTR_NUM_TABLES, MAX_TABLE)) if (nla_put_u32(msg, NLE_ATTR_NUM_VARS, TOTAL_NUM_VARS)) for (tblnum = 0; tblnum < MAX_TABLE; tblnum++) { switch (tblnum) { case PERF_TABLE: nest[tblnum] = nla_nest_start(msg, NLE_ATTR_PERF_VARS | NLA_F_NESTED); break; case PATH_TABLE: nest[tblnum] = nla_nest_start(msg, NLE_ATTR_PATH_VARS | NLA_F_NESTED); break; case STACK_TABLE: nest[tblnum] = nla_nest_start(msg, NLE_ATTR_STACK_VARS | NLA_F_NESTED); break; case APP_TABLE: nest[tblnum] = nla_nest_start(msg, NLE_ATTR_APP_VARS | NLA_F_NESTED); break; case TUNE_TABLE: nest[tblnum] = nla_nest_start(msg, NLE_ATTR_TUNE_VARS | NLA_F_NESTED); break; case EXTRAS_TABLE: nest[tblnum] = nla_nest_start(msg, NLE_ATTR_EXTRAS_VARS | NLA_F_NESTED); break; } if (!nest[tblnum]) goto nla_put_failure; for (i=0; i < estats_max_index[tblnum]; i++) { entry_nest = nla_nest_start(msg, NLE_ATTR_VAR | NLA_F_NESTED); if (nla_put_string(msg, NEA_VAR_NAME, estats_var_array[tblnum][i].name)) goto nla_put_failure; if (nla_put_u32(msg, NEA_VAR_TYPE, estats_var_array[tblnum][i].vartype)) goto nla_put_failure; nla_nest_end(msg, entry_nest); } nla_nest_end(msg, nest[tblnum]); } genlmsg_end(msg, hdr); */ Chk(estats_nl_client_init(&cl)); Chk(estats_val_data_new(&data)); Chk(estats_get_mib(data, cl)); // the MIB is printed out in estats_get_mib() Cleanup: estats_val_data_free(&data); estats_nl_client_destroy(&cl); if (err != NULL) { PRINT_AND_FREE(err); return EXIT_FAILURE; } return EXIT_SUCCESS; }
int main(int argc, char **argv) { estats_error* err = NULL; estats_nl_client* cl = NULL; estats_val_data* data = NULL; int cid, i, j; int opt, option; int stdout_flag = 0; int header_flag = 0; int interval = 1000; char *strmask = NULL; const char delim = ','; uint64_t tmpmask; struct estats_mask mask; mask.masks[0] = DEFAULT_PERF_MASK; mask.masks[1] = DEFAULT_PATH_MASK; mask.masks[2] = DEFAULT_STACK_MASK; mask.masks[3] = DEFAULT_APP_MASK; mask.masks[4] = DEFAULT_TUNE_MASK; for (i = 0; i < MAX_TABLE; i++) { mask.if_mask[i] = 0; } if (argc < 2) { usage(); exit(EXIT_FAILURE); } while ((opt = getopt(argc, argv, "hm:si:")) != -1) { switch (opt) { case 'h': usage(); exit(EXIT_SUCCESS); break; case 'm': strmask = strdup(optarg); for (j = 0; j < 5; j++) { char *strtmp; strtmp = strsep(&strmask, &delim); if (strtmp && strlen(strtmp)) { char *str; str = (str = strchr(strtmp, 'x')) ? str+1 : strtmp; if (sscanf(str, "%"PRIx64, &tmpmask) == 1) { mask.masks[j] = tmpmask & mask.masks[j]; mask.if_mask[j] = 1; } } } option = opt; break; case 's': stdout_flag = 1; break; case 'i': interval = atoi(optarg); break; default: exit(EXIT_FAILURE); break; } } if ((option == 'm') && (optind+1 > argc)) { printf("Too few non-option args\n"); exit(EXIT_FAILURE); } cid = atoi(argv[optind]); Chk(estats_nl_client_init(&cl)); Chk(estats_nl_client_set_mask(cl, &mask)); Chk(estats_val_data_new(&data)); while (1) { Chk(estats_read_vars(data, cid, cl)); if ((stdout_flag) && (!header_flag)) { printf("sec,usec,"); for (j = 0; j < data->length; j++) { if (data->val[j].masked) continue; printf("%s\t", estats_var_array[j].name); } printf("\n"); header_flag = 1; } if (!stdout_flag) printf("Timestamp sec: %u, usec: %u\n", data->tv.sec, data->tv.usec); else printf("%u,%u,", data->tv.sec, data->tv.usec); for (j = 0; j < data->length; j++) { if (!stdout_flag) { if (j == 0) printf("\n\n Perf Table\n\n"); if (j == PERF_INDEX_MAX) printf("\n\n Path Table\n\n"); if (j == PERF_INDEX_MAX+PATH_INDEX_MAX) printf("\n\n Stack Table\n\n"); if (j == PERF_INDEX_MAX+PATH_INDEX_MAX+STACK_INDEX_MAX) printf("\n\n App Table\n\n"); if (j == PERF_INDEX_MAX+PATH_INDEX_MAX+STACK_INDEX_MAX+APP_INDEX_MAX) printf("\n\n Tune Table\n\n"); } if (data->val[j].masked) continue; /* I could have had an if in each case statement but that seems like * it would have been much more expensive - cjr */ if (!stdout_flag) { switch(estats_var_array[j].valtype) { case ESTATS_UNSIGNED64: printf("%s=%"PRIu64"\n", estats_var_array[j].name, data->val[j].uv64); break; case ESTATS_UNSIGNED32: printf("%s=%"PRIu32"\n", estats_var_array[j].name, data->val[j].uv32); break; case ESTATS_SIGNED32: printf("%s=%"PRId32"\n", estats_var_array[j].name, data->val[j].sv32); break; case ESTATS_UNSIGNED16: printf("%s=%"PRIu16"\n", estats_var_array[j].name, data->val[j].uv16); break; case ESTATS_UNSIGNED8: printf("%s=%"PRIu8"\n", estats_var_array[j].name, data->val[j].uv8); break; default: break; } } else { switch(estats_var_array[j].valtype) { case ESTATS_UNSIGNED64: printf("%"PRIu64",", data->val[j].uv64); break; case ESTATS_UNSIGNED32: printf("%"PRIu32",", data->val[j].uv32); break; case ESTATS_SIGNED32: printf("%"PRId32",", data->val[j].sv32); break; case ESTATS_UNSIGNED16: printf("%"PRIu16",", data->val[j].uv16); break; case ESTATS_UNSIGNED8: printf("%"PRIu8",", data->val[j].uv8); break; default: break; } } } usleep(interval * 1000); printf("\n"); if (!stdout_flag) printf("\n"); } Cleanup: estats_val_data_free(&data); estats_nl_client_destroy(&cl); if (err != NULL) { PRINT_AND_FREE(err); return EXIT_FAILURE; } return EXIT_SUCCESS; }