summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2020-08-05 20:55:01 +0200
committerAndreas Kling <kling@serenityos.org>2020-08-06 20:41:13 +0200
commitca799fe4ab77d338904c83c63b7cd682187764ad (patch)
tree2468fe5303ede78f3307dc334e75ae212e24858c
parent59942edcc04b429c8300811ff040e4fb5611d653 (diff)
downloadserenity-ca799fe4ab77d338904c83c63b7cd682187764ad.zip
Userland: Use Core::ArgsParser for 'ping'
-rw-r--r--Userland/ping.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/Userland/ping.cpp b/Userland/ping.cpp
index 79f954a3e1..9fb272b58c 100644
--- a/Userland/ping.cpp
+++ b/Userland/ping.cpp
@@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include <LibCore/ArgsParser.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
@@ -57,10 +58,11 @@ int main(int argc, char** argv)
return 1;
}
- if (argc != 2) {
- printf("usage: ping <host>\n");
- return 0;
- }
+ const char* host = nullptr;
+
+ Core::ArgsParser args_parser;
+ args_parser.add_positional_argument(host, "Host to ping", "host");
+ args_parser.parse(argc, argv);
int fd = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
if (fd < 0) {
@@ -87,9 +89,9 @@ int main(int argc, char** argv)
return 1;
}
- auto* hostent = gethostbyname(argv[1]);
+ auto* hostent = gethostbyname(host);
if (!hostent) {
- printf("Lookup failed for '%s'\n", argv[1]);
+ printf("Lookup failed for '%s'\n", host);
return 1;
}