int main(int argc, char **argv) { (void)argc; (void)argv; const uint32_t net = 0x0a0a0a00; char *password; setup_test("tcpr-test", "test-recover-peer-send"); password = get_password(htonl(net | 2), 8888, htonl(net | 3), 9999); setup_connection(net | 2, net | 4, net | 3, 8888, 9999, 0xdeadbeef, 0xcafebabe, test_options_size, test_options, peer_mss, peer_ws, password); recover_connection(net | 5, net | 2, net | 3, 9999, 8888, 0xfeedbead, 0xcafebabe, 0xdeadbeef, test_options_size, test_options, peer_mss, peer_ws, TCPR_HAVE_ACK | TCPR_HAVE_PEER_MSS | TCPR_HAVE_PEER_WS, password); fprintf(stderr, " Peer: \"baz\" (retransmit)\n"); send_segment(external_log, net | 2, net | 3, 8888, 9999, TH_ACK, 0xdeadbeef + 1, 0xcafebabe + 1, 0, NULL, 4, "baz", password); recv_segment(internal_log, net | 2, net | 5, 8888, 9999, TH_ACK, 0xdeadbeef + 1, 0xfeedbead + 1, 0, NULL, 4, "baz", password); fprintf(stderr, "Application: ACK\n"); send_segment(internal_log, net | 5, net | 2, 9999, 8888, TH_ACK, 0xfeedbead + 1, 0xdeadbeef + 5, 0, NULL, 0, NULL, password); fprintf(stderr, "Application: update\n"); send_update(net | 2, net | 5, 8888, 9999, 0xcafebabe + 1, 0xdeadbeef + 5, 0, 0, (0xfeedbead + 1) - (0xcafebabe + 1), TCPR_HAVE_ACK); fprintf(stderr, " Filter: ACK\n"); recv_segment(external_log, net | 3, net | 2, 9999, 8888, TH_ACK, 0xcafebabe + 1, 0xdeadbeef + 5, 0, NULL, 0, NULL, password); cleanup_connection(net | 2, net | 4, 8888, 9999, 0xcafebabe + 1, 0xdeadbeef + 1, (0xfeedbead + 1) - (0xcafebabe + 1)); cleanup_test(); return EXIT_SUCCESS; }
int main(int argc, char **argv) { int opt; while ((opt = getopt(argc, argv, "b:c:a:f:s:?")) != -1) switch (opt) { case 'b': split_address(optarg, &bind_host, &bind_port); break; case 'c': split_address(optarg, &connect_host, &connect_port); break; case 'a': split_address(optarg, &application_host, &application_port); break; case 'f': split_address(optarg, &filter_host, &filter_port); break; case 's': state_file = optarg; break; default: fprintf(stderr, "Usage: %s [OPTIONS]\n", argv[0]); fprintf(stderr, " -b HOST:[PORT] " "Bind to the specified address.\n"); fprintf(stderr, " -c HOST:[PORT] " "Connect to the specified address.\n"); fprintf(stderr, " -a HOST:[PORT] " "Receive updates at the specified address.\n"); fprintf(stderr, " -f HOST:[PORT] " "Send updates to the specified address.\n"); fprintf(stderr, " -s FILE " "Keep persistent state in FILE.\n"); fprintf(stderr, " -? " "Print this help message and exit.\n"); exit(EXIT_FAILURE); } if (!connect_port && connect_host) connect_port = "8888"; if (!bind_port && (bind_host || !connect_port)) bind_port = "8888"; if (filter_host || filter_port) { filtering = 1; if (!filter_port) filter_port = application_port ? application_port : "7777"; if (!application_port) application_port = filter_port; if (!application_host) application_host = bind_host; if (!state_file) state_file = "tcpr-application.dat"; setup_state(); setup_update_connection(); } if (recovering) recover_connection(); else setup_connection(); finish(); return EXIT_SUCCESS; }
int main(int argc, char **argv) { int opt; while ((opt = getopt(argc, argv, "b:c:a:f:s:p?")) != -1) switch (opt) { case 'b': split_address(optarg, &bind_host, &bind_port); break; case 'c': split_address(optarg, &connect_host, &connect_port); break; case 'a': application_path = optarg; break; case 'f': filter_path = optarg; break; case 's': state_file = optarg; break; case 'p': filtering = 0; break; default: fprintf(stderr, "Usage: %s [OPTIONS]\n", argv[0]); fprintf(stderr, " -b HOST:[PORT] " "Bind to HOST at PORT.\n"); fprintf(stderr, " -c HOST:[PORT] " "Connect to HOST at PORT.\n"); fprintf(stderr, " -a PATH " "Receive updates at the UNIX socket PATH.\n"); fprintf(stderr, " -f PATH " "Send updates to the UNIX socket PATH.\n"); fprintf(stderr, " -s FILE " "Keep persistent state in FILE.\n"); fprintf(stderr, " -p " "Act as the peer; i.e. ignore TCPR.\n"); fprintf(stderr, " -? " "Print this help message and exit.\n"); exit(EXIT_FAILURE); } if (!connect_port && connect_host) connect_port = "8888"; if (!bind_port && (bind_host || !connect_port)) bind_port = "8888"; if (filtering) { setup_state(); setup_update_connection(); } if (recovering) recover_connection(); else setup_connection(); finish(); return EXIT_SUCCESS; }