2

So I created a simple inetd error logging service according to this example https://en.wikipedia.org/wiki/Inetd

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
  const char *fn = argv[1];
  FILE *fp = fopen(fn, "a+");

  if (fp == NULL) 
    exit(EXIT_FAILURE);

  char str[4096];
  /* inetd passes its information to us in stdin. */
  while (fgets(str, sizeof str, stdin)) {
    fputs(str, fp);
    fflush(fp);
  }
  fclose(fp);
  return 0;
}

I appended this line to /etc/services/

errorLogger 9999/udp

and this line to /etc/inetd.conf

errorLogger dgram udp wait root /usr/local/bin/errlogd errlogd /tmp/logfile.txt

How can I access this now? I configured the service on my Raspberry Pi in my local network. Do I need to write a client program that accesses the UDP port 9999 or can I do it via SSH?

I already tried

ssh pi@raspberrypi -p 9999

but it says ssh: connect to host raspberrypi port 9999: Connection refused

I also reload the systemd service with

sudo service inetd reload

and it didn't help.

neolith
  • 213
  • 2
  • 7

2 Answers2

3

Since you mention a logging service, you can write to it with the logger command:

logger --udp --port 9999 --server 127.0.0.1 'test msg'

Another versatile utility is socat:

echo 'test msg' | socat -u - udp-sendto:127.0.0.1:9999
meuh
  • 49,672
  • 2
  • 52
  • 114
2

You have created a listening service on the UDP port 9999. In order to write to this you need to use a tool that can create UDP packets, and ssh is not one of these.

The netcat tool can generate UDP packets, for example the version I have is used like this,

echo hello | nc -u -q1 remoteHost 9999    # Some versions of nc still also need "-w1"
roaima
  • 107,089
  • 14
  • 139
  • 261
  • Oh right. SSH is TCP based like Telnet. Would it work with SSH if I change the protocol? – neolith Feb 09 '21 at 22:16
  • No it wouldn't. An `ssh` client expects a chatty server. Your server express a chatty client – roaima Feb 10 '21 at 00:26
  • That is weird. We have the task in Uni to set up an inetd service that logs data into a file and are given the instructions to connect to it via Telnet. – neolith Feb 10 '21 at 00:56
  • With TCP/IP, `telnet` could work, but `ssh` will not – roaima Feb 10 '21 at 08:47