+}
+
+static void reverse_services(char *buf, int port, int dgram)
+{
+ unsigned long svport;
+ char line[128], *p, *z;
+ unsigned char _buf[1032];
+ FILE _f, *f = __fopen_rb_ca("/etc/services", &_f, _buf, sizeof _buf);
+ if (!f) return;
+ while (fgets(line, sizeof line, f)) {
+ if ((p=strchr(line, '#'))) *p++='\n', *p=0;
+
+ for (p=line; *p && !isspace(*p); p++);
+ if (!*p) continue;
+ *p++ = 0;
+ svport = strtoul(p, &z, 10);
+
+ if (svport != port || z==p) continue;
+ if (dgram && strncmp(z, "/udp", 4)) continue;
+ if (!dgram && strncmp(z, "/tcp", 4)) continue;
+ if (p-line > 32) continue;
+
+ memcpy(buf, line, p-line);
+ break;
+ }
+ __fclose_ca(f);