diff --git a/Makefile b/Makefile index 7aad152..d057374 100644 --- a/Makefile +++ b/Makefile @@ -4,10 +4,11 @@ LDFLAGS = -Wl,-z,now,-z,relro,-s,-pie OBJS = obj/main.o BIN = bin/stc +MAN = man1/stc.1.gz PREFIX = /usr -default: obj bin $(BIN) +default: obj bin $(BIN) $(MAN) obj: @mkdir obj @@ -21,17 +22,25 @@ $(BIN): $(OBJS) obj/%.o: src/%.c $(CC) -c -o $@ $^ $(CFLAGS) +man1/%.1.gz: man1/%.1 + gzip --keep --best -c $^ > $@ + clean: @[ -d obj ] && rm -rf obj @[ -d bin ] && rm -rf bin + @[ -f $(MAN) ] && rm -f $(MAN) format: @clang-format -i -style="{BasedOnStyle: mozilla, IndentWidth: 4}" src/*.c install: default install -Dm755 $(BIN) $(PREFIX)/bin/stc + install -Dm644 LICENSE $(PREFIX)/share/licenses/stc/LICENSE + install -Dm644 man1/stc.1.gz $(PREFIX)/share//man/man1/stc.1.gz uninstall: rm -f $(PREFIX)/bin/stc + rm -f $(PREFIX)/share/licenses/stc/LICENSE + rm -f $(PREFIX)/share/man/man1/stc.1.gz .PHONY: default clean format install uninstall diff --git a/README.md b/README.md index 7c27708..5736941 100644 --- a/README.md +++ b/README.md @@ -25,5 +25,5 @@ sudo make uninstall ## Usage ``` -stc address|hostname [port] +stc address|domainname [port] ``` diff --git a/man1/stc.1 b/man1/stc.1 new file mode 100644 index 0000000..19cfe9b --- /dev/null +++ b/man1/stc.1 @@ -0,0 +1,45 @@ +.TH STC 1 "2020-09-02" 1.0 +.SH NAME +stc \- Simple Telnet Client +.SH SYNOPSIS +.B stc +address|hostname [port] +.SH DESCRIPTION +.B stc +is a Simple Telnet Client that take at least an IP address or a domain name as a first argument. If a domain name is provided, it will try to resolve it. +Optionnaly it can take a port number as a second argument. In this case it will be used instead of the default (which is 23). +.SH EXIT STATUS +.TP +0 +if no error uncountered +.TP +1 +if the wrong amount of arguments has been given +.TP +2 +if it failed to initialize network connection (socket, NS resolution, ...) +.TP +3 +if it failed to setup terminal +.TP +4 +if it failed to create epoll instance +.TP +5 +if it failed to set signal handler (for SIGINT or SIGTERM) +.TP +6 +if it failed to add a file descriptor to the epoll instance (for stdin or the socket) +.TP +7 +if error happened during epoll_wait +.TP +8 +if it failed to receive data +.TP +9 +if it failed to send data +.SH AUTHOR +Franck STAUFFER +.I + diff --git a/src/main.c b/src/main.c index 620207e..0556edb 100644 --- a/src/main.c +++ b/src/main.c @@ -135,7 +135,7 @@ int main(int argc, char** argv) { if (argc < 2 || argc > 3) { - printf("USAGE: %s, address|hostname [port]\n", argv[0]); + printf("USAGE: %s, address|domainname [port]\n", argv[0]); return 1; } @@ -176,7 +176,7 @@ main(int argc, char** argv) ev[1].data.fd = sock; if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, sock, &ev[1])) { perror("epoll_ctl"); - return 7; + return 6; } uint_fast8_t run = 1; @@ -186,7 +186,7 @@ main(int argc, char** argv) int_fast8_t count = epoll_wait(epoll_fd, events, 2, -1); if (count == -1) { perror("epoll_wait"); - return 8; + return 7; } for (int_fast8_t i = 0; i < count; ++i) { @@ -196,7 +196,7 @@ main(int argc, char** argv) int_fast8_t ret = recv(sock, buf, 1, 0); if (ret == -1) { perror("recv"); - return 9; + return 8; } if (!ret) @@ -206,7 +206,7 @@ main(int argc, char** argv) ret = recv(sock, buf + 1, 2, 0); if (ret < 0) { perror("recv"); - return 10; + return 8; } if (!ret) @@ -226,7 +226,7 @@ main(int argc, char** argv) if (send(sock, &chr, 1, 0) != 1) { perror("send"); - return 11; + return 9; } if (chr == '\n')