From aae28614e07cd3c079227b27c4a51f7620b7bd6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Wed, 8 Mar 2023 14:09:26 +0100 Subject: uname(2) in created by, override with CREATED_BY envvar --- src/tcp.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/tcp.c b/src/tcp.c index bfd49bc..dc73d55 100644 --- a/src/tcp.c +++ b/src/tcp.c @@ -1,3 +1,4 @@ +#include void disconnection (struct torrent * t) { fprintf(stderr, "disconnecting from peer "); peer_print(stderr, t->dl); @@ -22,7 +23,26 @@ void disconnection (struct torrent * t) { if (!inet_ntop(t->dl->addr.sin6_family, t->dl->addr.sin6_addr.s6_addr, remote, INET6_ADDRSTRLEN+7)) snprintf(remote, sizeof remote, "(inet_ntop: %s)", strerror(errno)); sprintf(remote+strlen(remote), "/%d", ntohs(t->dl->addr.sin6_port)); - fprintf(f, "d10:created by58:http://ni.šijanec.eu/sijanec/travnik mailto:tk@sijanec.eu13:creation datei%lde8:encoding5:UTF-84:info", time(NULL)); + char createdby[1024]; + char unam[512]; + char * machinetext = unam; + struct utsname utsname; + if (uname(&utsname) == -1) + snprintf(unam, 512, "uname(&utsname) == -1, errno == %d (%s)", errno, strerror(errno)); + else + snprintf(unam, 512, "%s %s %s %s %s" +#ifdef _GNU_SOURCE + " %s" +#endif + , utsname.sysname, utsname.nodename, utsname.release, utsname.version, utsname.machine +#ifdef _GNU_SOURCE + , utsname.domainname +#endif + ); + if (getenv("CREATED_BY")) + machinetext = getenv("CREATED_BY"); + snprintf(createdby, 1024, "http://ni.šijanec.eu/sijanec/travnik mailto:tk@sijanec.eu %s", machinetext); + fprintf(f, "d10:created by%zu:%s13:creation datei%lde8:encoding5:UTF-84:info", strlen(createdby), createdby, time(NULL)); fwrite(t->metadata, 1, t->size, f); // i don't expect any errors here fprintf(f, "6:sourced2:ip%zu:%s", strlen(remote), remote); if (t->software) -- cgit v1.2.3