mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 21:27:34 +00:00
TelnetServer: replace getopt with LibCore ArgsParser
This commit is contained in:
parent
9d4a0ec50a
commit
3e72fd68b0
1 changed files with 14 additions and 18 deletions
|
@ -31,11 +31,11 @@
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <LibCore/EventLoop.h>
|
#include <LibCore/EventLoop.h>
|
||||||
#include <LibCore/TCPServer.h>
|
#include <LibCore/TCPServer.h>
|
||||||
#include <LibCore/TCPSocket.h>
|
#include <LibCore/TCPSocket.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <getopt.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
@ -105,25 +105,21 @@ static void run_command(int ptm_fd, String command)
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
Core::EventLoop event_loop;
|
int port = 23;
|
||||||
auto server = Core::TCPServer::construct();
|
|
||||||
|
|
||||||
int opt;
|
|
||||||
u16 port = 23;
|
|
||||||
const char* command = "";
|
const char* command = "";
|
||||||
while ((opt = getopt(argc, argv, "p:c:")) != -1) {
|
|
||||||
switch (opt) {
|
Core::ArgsParser args_parser;
|
||||||
case 'p':
|
args_parser.add_option(port, "Port to listen on", nullptr, 'p', "port");
|
||||||
port = atoi(optarg);
|
args_parser.add_option(command, "Program to run on connection", nullptr, 'c', "command");
|
||||||
break;
|
args_parser.parse(argc, argv);
|
||||||
case 'c':
|
|
||||||
command = optarg;
|
if ((u16)port != port) {
|
||||||
break;
|
warnln("Invalid port number: {}", port);
|
||||||
default:
|
|
||||||
fprintf(stderr, "Usage: %s [-p port] [-c command]", argv[0]);
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
Core::EventLoop event_loop;
|
||||||
|
auto server = Core::TCPServer::construct();
|
||||||
|
|
||||||
if (!server->listen({}, port)) {
|
if (!server->listen({}, port)) {
|
||||||
warnln("Listening on 0.0.0.0:{} failed", port);
|
warnln("Listening on 0.0.0.0:{} failed", port);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue