From c722f350ba95dc7ad4bedede7a2e9ae0f2106a9c Mon Sep 17 00:00:00 2001 From: Pekka Helenius Date: Fri, 19 Feb 2021 14:07:17 +0200 Subject: [PATCH] Add whichport & whichservice --- tools/PKGBUILD | 9 ++++++++- tools/whichport.c | 20 ++++++++++++++++++++ tools/whichservice.c | 22 ++++++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 tools/whichport.c create mode 100644 tools/whichservice.c diff --git a/tools/PKGBUILD b/tools/PKGBUILD index 94bd5b1..7b823a7 100644 --- a/tools/PKGBUILD +++ b/tools/PKGBUILD @@ -29,6 +29,7 @@ arch-audit bc # risks.sh glibc # missinglibs.sh util-linux # killprocess.sh (kill command) stderred # bash.custom LD_PRELOAD +gcc ) makedepends=(git) source=( @@ -57,6 +58,8 @@ specialchars.sh whichcmd.sh killns.sh psns.sh +whichport.c +whichservice.c bash.custom https://raw.github.com/trapd00r/LS_COLORS/master/LS_COLORS) @@ -104,6 +107,11 @@ package() { mv "$pkgdir"/usr/bin/$sh $(echo "$pkgdir"/usr/bin/$sh | sed 's/\.sh//') done + for i in ./*.c; do + gcc $i -o $(echo $i | sed 's/\.c$//') + install -m755 $i "$pkgdir"/usr/bin/ + done + msg2 ' In /etc/bash.bashrc file, replace line @@ -120,4 +128,3 @@ package() { #msg2 "You can change bash settings globally by editing /etc/bash.custom file" } - diff --git a/tools/whichport.c b/tools/whichport.c new file mode 100644 index 0000000..e0928df --- /dev/null +++ b/tools/whichport.c @@ -0,0 +1,20 @@ +#include +#include +#include + +int main(int argc, char *argv[]) +{ + struct servent *se; + + if (argc != 3) { + printf("%s usage: [tcp|udp]\n", argv[0]); + return 1; + } + + if ((se = getservbyname(argv[1], argv[2])) == NULL) { + return 1; + } else { + printf("%d\n", ntohs(se->s_port)); + } + return 0; +} diff --git a/tools/whichservice.c b/tools/whichservice.c new file mode 100644 index 0000000..2cded1d --- /dev/null +++ b/tools/whichservice.c @@ -0,0 +1,22 @@ +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + struct servent *se; + int port = atoi(argv[1]); + + if (argc != 3) { + printf("%s usage: [tcp|udp]\n", argv[0]); + return 1; + } + + if ((se = getservbyport(ntohs(port), argv[2])) == NULL) { + return 1; + } else { + printf("%s\n", se->s_name); + } + return 0; +}