diff options
Diffstat (limited to 'mcping.c')
-rw-r--r-- | mcping.c | 18 |
1 files changed, 13 insertions, 5 deletions
@@ -7,6 +7,16 @@ #include "mctypes.h" #include "mcnetwork.h" + +void usage(const char *program_name){ + printf("Usage: %s [-p PROTOCOL]... ADDRESS[:PORT]\n\ + Pings a Minecraft server using the Server List Ping protocol.\n\n\ + -h display this help and exit\n\ + -p PROTOCOL uses specified protocol number.\n" + , program_name); +} + + int main(int argc, char *argv[]) { char *port_s, *address; @@ -16,8 +26,7 @@ int main(int argc, char *argv[]) while ((opt = getopt(argc, argv, "hp:")) != -1) { switch (opt) { case 'h': - printf - ("Usage: mcping [-p PROTOCOL] ADDRESS[:PORT]\nPings a Minecraft server using the PING protocol.\n\n -h\t\t\tdisplay this help and exit\n -p PROTOCOL\tUses specified protocol number.\n"); + usage(argv[0]); exit(EXIT_SUCCESS); case 'p': protocol_ver = atoi(optarg); @@ -28,8 +37,7 @@ int main(int argc, char *argv[]) } } if (optind >= argc) { - printf - ("Usage: mcping [-p PROTOCOL] ADDRESS[:PORT]\nPings a Minecraft server using the PING protocol.\n\n -h\t\tdisplay this help and exit\n -p PROTOCOL\tUses specified protocol number.\n"); + usage(argv[0]); exit(EXIT_FAILURE); } address = argv[optind]; @@ -47,7 +55,7 @@ int main(int argc, char *argv[]) if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) perror("bad socket\n"); - connect_mc_server(s, address, port); + connect_mc_server_ping(s, address, port); send_handshake(s, protocol_ver, address, port, 1); send_packet(s, 0x0, 0, NULL); // request packet (0x0 with no fields) |