Browse Source

Add whichport & whichservice

master
Pekka Helenius 3 years ago
parent
commit
c722f350ba
3 changed files with 50 additions and 1 deletions
  1. +8
    -1
      tools/PKGBUILD
  2. +20
    -0
      tools/whichport.c
  3. +22
    -0
      tools/whichservice.c

+ 8
- 1
tools/PKGBUILD View File

@ -29,6 +29,7 @@ arch-audit bc # risks.sh
glibc # missinglibs.sh glibc # missinglibs.sh
util-linux # killprocess.sh (kill command) util-linux # killprocess.sh (kill command)
stderred # bash.custom LD_PRELOAD stderred # bash.custom LD_PRELOAD
gcc
) )
makedepends=(git) makedepends=(git)
source=( source=(
@ -57,6 +58,8 @@ specialchars.sh
whichcmd.sh whichcmd.sh
killns.sh killns.sh
psns.sh psns.sh
whichport.c
whichservice.c
bash.custom bash.custom
https://raw.github.com/trapd00r/LS_COLORS/master/LS_COLORS) 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//') mv "$pkgdir"/usr/bin/$sh $(echo "$pkgdir"/usr/bin/$sh | sed 's/\.sh//')
done done
for i in ./*.c; do
gcc $i -o $(echo $i | sed 's/\.c$//')
install -m755 $i "$pkgdir"/usr/bin/
done
msg2 ' msg2 '
In /etc/bash.bashrc file, replace line 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" #msg2 "You can change bash settings globally by editing /etc/bash.custom file"
} }

+ 20
- 0
tools/whichport.c View File

@ -0,0 +1,20 @@
#include <stdio.h>
#include <stddef.h>
#include <netdb.h>
int main(int argc, char *argv[])
{
struct servent *se;
if (argc != 3) {
printf("%s usage: <protocol> [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;
}

+ 22
- 0
tools/whichservice.c View File

@ -0,0 +1,22 @@
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <netdb.h>
int main(int argc, char *argv[])
{
struct servent *se;
int port = atoi(argv[1]);
if (argc != 3) {
printf("%s usage: <port> [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;
}

Loading…
Cancel
Save