repo: uritools
action: commit
revision: 
path_from: 
revision_from: 9461063b763062ab0e5cfa3e5f4cf49a7ce86f03:
path_to: 
revision_to: 
git.thebackupbox.net
uritools
git clone git://git.thebackupbox.net/uritools
commit 9461063b763062ab0e5cfa3e5f4cf49a7ce86f03
Author: epoch 
Date:   Mon Jul 28 15:50:07 2025 -0500

    added getservbyname tool

diff --git a/getservbyname.c b/getservbyname.c
new file mode 100644
index 0000000000000000000000000000000000000000..d2d6bacdbdf6d59e483d51f7a1ca1af1aafe40c2
--- /dev/null
+++ b/getservbyname.c
@@ -0,0 +1,40 @@
+#include 
+#include 
+#include 
+
+void usage() {
+  printf("usage: getservbyname [-h|--help] [-v|--verbose]  []\n");
+}
+
+int main(int argc,char *argv[]) {
+  struct servent *serv;
+  unsigned int i;
+  char verbose=0;
+  if(argc < 2) { usage(); return 1; }
+  if(!strcmp(argv[1],"-h") || !strcmp(argv[1],"--help")) { usage(); return 3; }
+  if(!strcmp(argv[1],"-v") || !strcmp(argv[1],"--verbose")) {
+    verbose=1;
+    argc--;
+    argv++;
+  }
+  if(argc < 2) { usage(); return 1; }
+  serv = getservbyname(argv[1],argv[2]);
+  if(!serv) {
+    fprintf(stderr,"getservbyname: serv not found: name: %s proto: %s\n",argv[1],argv[2]);
+    return 2;
+  }
+  if(!verbose) {
+    printf("%u\n",ntohs(serv->s_port));
+    return 0;
+  }
+  printf("name: %s\n",serv->s_name);
+  printf("port: %u\n",ntohs(serv->s_port));
+  printf("proto: %s\n",serv->s_proto);
+  if(!serv->s_aliases[0]) {
+    printf("no aliases.\n");
+  }
+  for(i=0;serv->s_aliases[i];i++) {
+    printf("alias %d: %s\n",i,serv->s_aliases[i]);
+  }
+  return 0;
+}

-----END OF PAGE-----