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; }
/** * Get the title info from the snap. That is local address:port remote * address:port. * * For Web10G this also logs the start_time because this is expected * to be the first snap captured. * * @param snap A Web100/Web10G snap * @param agent A Web100 agent - ignored by Web10G should be NULL * @param group A Web100 group - ignored by Web10G should be NULL * @param title Upon return contains the string * "<localaddr>:<localport> --> <remoteaddr>" * @param remport Upon return contains the remote port as a string */ void get_title(tcp_stat_snap* snap, tcp_stat_agent* agent, tcp_stat_group* group, char* title, char* remport) { #if USE_WEB100 web100_var* var; char buf[128]; if ((web100_agent_find_var_and_group(agent, "LocalAddress", &group, &var)) != WEB100_ERR_SUCCESS) { web100_perror("web100_agent_find_var_and_group"); exit(EXIT_FAILURE); } if ((web100_snap_read(var, snap, buf)) != WEB100_ERR_SUCCESS) { web100_perror("web100_snap_read"); exit(EXIT_FAILURE); } strcpy(title, web100_value_to_text(web100_get_var_type(var), buf)); strncat(title, ":", 1); if ((web100_agent_find_var_and_group(agent, "LocalPort", &group, &var)) != WEB100_ERR_SUCCESS) { web100_perror("web100_agent_find_var_and_group"); exit(EXIT_FAILURE); } if ((web100_snap_read(var, snap, buf)) != WEB100_ERR_SUCCESS) { web100_perror("web100_snap_read"); exit(EXIT_FAILURE); } strcat(title, web100_value_to_text(web100_get_var_type(var), buf)); strncat(title, " --> ", 5); if ((web100_agent_find_var_and_group(agent, "RemAddress", &group, &var)) != WEB100_ERR_SUCCESS) { web100_perror("web100_agent_find_var_and_group"); exit(EXIT_FAILURE); } if ((web100_snap_read(var, snap, buf)) != WEB100_ERR_SUCCESS) { web100_perror("web100_snap_read"); exit(EXIT_FAILURE); } strcat(title, web100_value_to_text(web100_get_var_type(var), buf)); if ((web100_agent_find_var_and_group(agent, "RemPort", &group, &var)) != WEB100_ERR_SUCCESS) { web100_perror("web100_agent_find_var_and_group"); exit(EXIT_FAILURE); } if ((web100_snap_read(var, snap, buf)) != WEB100_ERR_SUCCESS) { web100_perror("web100_snap_read"); exit(EXIT_FAILURE); } strcpy(remport, web100_value_to_text(web100_get_var_type(var), buf)); /* printf("%s:%s\n", title, remport); */ #elif USE_WEB10G estats_error* err = NULL; struct estats_connection_tuple_ascii tuple_ascii; /* Quite a convenient little function we have */ if ((err = estats_connection_tuple_as_strings(&tuple_ascii, &snap->tuple)) != NULL) { /* If using the 3.5 kernel to make snaps it appears that the * address isn't filled in, so continue with unknown */ fprintf(stderr, "WARNING estats_connection_tuple_as_string has" " failed this could be due to using the 3.5 kernel patch which" " doesn't log this information!!!!"); estats_error_print(stderr, err); estats_error_free(&err); sprintf(title, "unknown:unknown --> unknown"); sprintf(remport, "unknown"); // exit(EXIT_FAILURE); } sprintf(title, "%s:%s --> %s", tuple_ascii.local_addr, tuple_ascii.local_port, tuple_ascii.rem_addr); sprintf(remport, "%s", tuple_ascii.rem_port); /* Notes the time fo this the first snap in the global start_time * because ElapsedTimeMicroSec is unimplemented in the kernel patch */ start_time = snap->tv.sec * 1000000 + snap->tv.usec; #endif }