From 085ba9a481cf284ff62019d1945ea787bdf1c9b9 Mon Sep 17 00:00:00 2001 From: michael Date: Mon, 13 Aug 2018 19:15:38 +0200 Subject: [PATCH 01/27] fix377 --- src/mod/uptime.mod/uptime.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/mod/uptime.mod/uptime.c b/src/mod/uptime.mod/uptime.c index 3d8ca96ff8..a3a7757240 100644 --- a/src/mod/uptime.mod/uptime.c +++ b/src/mod/uptime.mod/uptime.c @@ -67,7 +67,6 @@ typedef struct PackUp { unsigned long ontime; unsigned long now2; unsigned long sysup; - char string[3]; } PackUp; PackUp upPack; @@ -173,7 +172,7 @@ int send_uptime(void) { struct sockaddr_in sai; struct stat st; - PackUp *mem; + char *mem; int len, servidx; char servhost[UHOSTLEN] = "none"; module_entry *me; @@ -212,14 +211,10 @@ int send_uptime(void) upPack.sysup = htonl(st.st_ctime); len = sizeof(upPack) + strlen(botnetnick) + strlen(servhost) + - strlen(uptime_version); - mem = (PackUp *) nmalloc(len); - egg_bzero(mem, len); /* mem *should* be completely filled before it's - * sent to the server. But belt-and-suspenders - * is always good. - */ + strlen(uptime_version) + 3; + mem = nmalloc(len); my_memcpy(mem, &upPack, sizeof(upPack)); - sprintf(mem->string, "%s %s %s", botnetnick, servhost, uptime_version); + sprintf(mem + sizeof(upPack), "%s %s %s", botnetnick, servhost, uptime_version); egg_bzero(&sai, sizeof(sai)); sai.sin_family = AF_INET; sai.sin_addr.s_addr = uptimeip; From 47945cc471d2016e8977217a850f0e894ea3c61d Mon Sep 17 00:00:00 2001 From: michael Date: Mon, 13 Aug 2018 20:07:27 +0200 Subject: [PATCH 02/27] sanitize struct --- src/mod/uptime.mod/uptime.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/mod/uptime.mod/uptime.c b/src/mod/uptime.mod/uptime.c index a3a7757240..4a7035c6aa 100644 --- a/src/mod/uptime.mod/uptime.c +++ b/src/mod/uptime.mod/uptime.c @@ -59,14 +59,14 @@ */ typedef struct PackUp { - int regnr; - int pid; - int type; - unsigned long packets_sent; - unsigned long uptime; - unsigned long ontime; - unsigned long now2; - unsigned long sysup; + uint32_t regnr; + uint32_t pid; + uint32_t type; + uint32_t packets_sent; + uint32_t uptime; + uint32_t ontime; + uint32_t now2; + uint32_t sysup; } PackUp; PackUp upPack; From 663f8e6f704f19d3f25221a48f255d9bb9edc537 Mon Sep 17 00:00:00 2001 From: michael Date: Mon, 13 Aug 2018 20:43:35 +0200 Subject: [PATCH 03/27] doc fix --- src/mod/uptime.mod/uptime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mod/uptime.mod/uptime.c b/src/mod/uptime.mod/uptime.c index 4a7035c6aa..837331650a 100644 --- a/src/mod/uptime.mod/uptime.c +++ b/src/mod/uptime.mod/uptime.c @@ -55,7 +55,7 @@ * repurposed and renamed as of uptime v1.3 to reflect * the number of packets the client thinks it has sent * over the life of the module. Only the name has changed - - * the type (unsigned long) is still the same. + * the type is still the same. */ typedef struct PackUp { From e7d5904c6c74cc8976b5bec0486b5529435c8a4e Mon Sep 17 00:00:00 2001 From: michael Date: Mon, 13 Aug 2018 20:51:39 +0200 Subject: [PATCH 04/27] make get_ip() static --- src/mod/uptime.mod/uptime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mod/uptime.mod/uptime.c b/src/mod/uptime.mod/uptime.c index 837331650a..c79589b576 100644 --- a/src/mod/uptime.mod/uptime.c +++ b/src/mod/uptime.mod/uptime.c @@ -109,7 +109,7 @@ static void uptime_report(int idx, int details) } } -unsigned long get_ip() +static unsigned long get_ip() { struct hostent *hp; IP ip; From 954b1eb8604559fadc6c64ce035f32ed2fd764b8 Mon Sep 17 00:00:00 2001 From: michaelortmann Date: Sun, 26 Aug 2018 23:14:59 +0200 Subject: [PATCH 05/27] rand() -> random() --- src/mod/uptime.mod/uptime.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/mod/uptime.mod/uptime.c b/src/mod/uptime.mod/uptime.c index c79589b576..db8c2db03c 100644 --- a/src/mod/uptime.mod/uptime.c +++ b/src/mod/uptime.mod/uptime.c @@ -77,7 +77,7 @@ static int minutes = 0; static int seconds = 0; static int next_seconds = 0; static int next_minutes = 0; -static int update_interval = 720; /* rand(0..12) hours: ~6 hour average. */ +static int update_interval = 720; /* random(0..12) hours: ~6 hour average. */ static time_t next_update = 0; static int uptimesock; static int uptimecount; @@ -159,8 +159,8 @@ int init_uptime(void) } fcntl(uptimesock, F_SETFL, O_NONBLOCK | fcntl(uptimesock, F_GETFL)); - next_minutes = rand() % update_interval; /* Initial update delay */ - next_seconds = rand() % 59; + next_minutes = random() % update_interval; /* Initial update delay */ + next_seconds = random() % 59; next_update = (time_t) ((time(NULL) / 60 * 60) + (next_minutes * 60) + next_seconds); @@ -245,8 +245,8 @@ void check_secondly() minutes = 0; /* Reset for the next countdown. */ seconds = 0; - next_minutes = rand() % update_interval; - next_seconds = rand() % 59; + next_minutes = random() % update_interval; + next_seconds = random() % 59; next_update = (time_t) ((time(NULL) / 60 * 60) + (next_minutes * 60) + next_seconds); From 30b0114d240d8e843c4566bc38ade3bf110515eb Mon Sep 17 00:00:00 2001 From: michaelortmann Date: Mon, 1 Oct 2018 23:30:24 +0200 Subject: [PATCH 06/27] cleanup comment --- src/mod/uptime.mod/uptime.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/mod/uptime.mod/uptime.c b/src/mod/uptime.mod/uptime.c index db8c2db03c..289892d444 100644 --- a/src/mod/uptime.mod/uptime.c +++ b/src/mod/uptime.mod/uptime.c @@ -1,13 +1,15 @@ /* - * This module reports uptime information about your bot to http://uptime.eggheads.org. The - * purpose for this is to see how your bot rates against many others (including EnergyMechs - * and Eggdrops) -- It is a fun little project, jointly run by Eggheads.org and EnergyMech.net. + * This module reports uptime information about your bot to + * http://uptime.eggheads.org. The purpose for this is to see how your bot rates + * against many others (including EnergyMechs and Eggdrops) -- It is a fun + * little project, jointly run by Eggheads.org and EnergyMech.net. * * If you don't like being a part of it please just unload this module. * - * Also for bot developers feel free to modify this code to make it a part of your bot and - * e-mail webmaster@eggheads.org for more information on registering your bot type. See how - * your bot's stability rates against ours and ours against yours . + * Also for bot developers feel free to modify this code to make it a part of + * your bot and e-mail webmaster@eggheads.org for more information on + * registering your bot type. See how your bot's stability rates against ours + * and ours against yours . */ /* * Copyright (C) 2001 proton @@ -46,18 +48,15 @@ #include /* - * regnr is unused; however, it must be here inorder for - * us to create a proper struct for the uptime server. + * regnr is unused; however, it must be here inorder for us to create a proper + * struct for the uptime server. * - * "packets_sent" was originally defined as "cookie", - * however this field was deprecated and set to zero - * for most versions of the uptime client. It has been - * repurposed and renamed as of uptime v1.3 to reflect - * the number of packets the client thinks it has sent - * over the life of the module. Only the name has changed - - * the type is still the same. + * "packets_sent" was originally defined as "cookie", however this field was + * deprecated and set to zero for most versions of the uptime client. It has + * been repurposed and renamed as of uptime v1.3 to reflect the number of + * packets the client thinks it has sent over the life of the module. Only the + * name has changed - the type is still the same. */ - typedef struct PackUp { uint32_t regnr; uint32_t pid; From a2b3e740055ee31394566f4f3c3ba72cf105da86 Mon Sep 17 00:00:00 2001 From: michaelortmann Date: Mon, 1 Oct 2018 23:45:37 +0200 Subject: [PATCH 07/27] Fix struct hack / flexible array member, requires merged #660 --- src/mod/uptime.mod/uptime.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mod/uptime.mod/uptime.c b/src/mod/uptime.mod/uptime.c index 289892d444..6c245fb0b6 100644 --- a/src/mod/uptime.mod/uptime.c +++ b/src/mod/uptime.mod/uptime.c @@ -66,6 +66,7 @@ typedef struct PackUp { uint32_t ontime; uint32_t now2; uint32_t sysup; + char string[FLEXIBLE_ARRAY_MEMBER]; } PackUp; PackUp upPack; @@ -213,7 +214,7 @@ int send_uptime(void) strlen(uptime_version) + 3; mem = nmalloc(len); my_memcpy(mem, &upPack, sizeof(upPack)); - sprintf(mem + sizeof(upPack), "%s %s %s", botnetnick, servhost, uptime_version); + sprintf(mem->string, "%s %s %s", botnetnick, servhost, uptime_version); egg_bzero(&sai, sizeof(sai)); sai.sin_family = AF_INET; sai.sin_addr.s_addr = uptimeip; From 6fafbb5026f72a2cbf11251cbdff110a8819c4e0 Mon Sep 17 00:00:00 2001 From: michaelortmann Date: Mon, 1 Oct 2018 23:58:25 +0200 Subject: [PATCH 08/27] fix --- src/mod/uptime.mod/uptime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mod/uptime.mod/uptime.c b/src/mod/uptime.mod/uptime.c index 3e43a6dc47..2425d5f90c 100644 --- a/src/mod/uptime.mod/uptime.c +++ b/src/mod/uptime.mod/uptime.c @@ -212,7 +212,7 @@ int send_uptime(void) len = sizeof(upPack) + strlen(botnetnick) + strlen(servhost) + strlen(uptime_version) + 3; - mem = nmalloc(len); + mem = (PackUp *) nmalloc(len); my_memcpy(mem, &upPack, sizeof(upPack)); sprintf(mem->string, "%s %s %s", botnetnick, servhost, uptime_version); egg_bzero(&sai, sizeof(sai)); From 368f8e8f2d524465429d5f8b087436398d072e15 Mon Sep 17 00:00:00 2001 From: michaelortmann Date: Tue, 2 Oct 2018 00:03:50 +0200 Subject: [PATCH 09/27] fix --- src/mod/uptime.mod/uptime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mod/uptime.mod/uptime.c b/src/mod/uptime.mod/uptime.c index 2425d5f90c..f22f07cbd6 100644 --- a/src/mod/uptime.mod/uptime.c +++ b/src/mod/uptime.mod/uptime.c @@ -172,7 +172,7 @@ int send_uptime(void) { struct sockaddr_in sai; struct stat st; - char *mem; + PackUp *mem; int len, servidx; char servhost[UHOSTLEN] = "none"; module_entry *me; From 957c6654aecbc836b32c963d3b5d48b7014b5595 Mon Sep 17 00:00:00 2001 From: michaelortmann Date: Tue, 2 Oct 2018 00:37:41 +0200 Subject: [PATCH 10/27] fix #664 --- src/mod/uptime.mod/uptime.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mod/uptime.mod/uptime.h b/src/mod/uptime.mod/uptime.h index 4e0a23720e..ff57b3bc9d 100644 --- a/src/mod/uptime.mod/uptime.h +++ b/src/mod/uptime.mod/uptime.h @@ -24,7 +24,7 @@ #define _EGG_MOD_UPTIME_UPTIME_H static const int uptime_type = 2; -static const int uptime_port = 9969; +static int uptime_port = 9969; static const char *uptime_host = "uptime.eggheads.org"; #endif /* _EGG_MOD_UPTIME_UPTIME_H */ From b2a7d4a558524a1a1833d51f632f16f2a9dddc55 Mon Sep 17 00:00:00 2001 From: michaelortmann Date: Tue, 2 Oct 2018 01:03:02 +0200 Subject: [PATCH 11/27] enhance fix #664 / convert some (const) variables to #defines --- src/mod/uptime.mod/uptime.c | 21 +++++++++++---------- src/mod/uptime.mod/uptime.h | 6 +++--- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/mod/uptime.mod/uptime.c b/src/mod/uptime.mod/uptime.c index f22f07cbd6..12b8647358 100644 --- a/src/mod/uptime.mod/uptime.c +++ b/src/mod/uptime.mod/uptime.c @@ -47,6 +47,8 @@ #include #include +#define UPDATE_INTERVAL (12 * 60) /* random(0..12) hours: ~6 hour average. */ + /* * regnr is unused; however, it must be here inorder for us to create a proper * struct for the uptime server. @@ -77,7 +79,6 @@ static int minutes = 0; static int seconds = 0; static int next_seconds = 0; static int next_minutes = 0; -static int update_interval = 720; /* random(0..12) hours: ~6 hour average. */ static time_t next_update = 0; static int uptimesock; static int uptimecount; @@ -116,12 +117,12 @@ static unsigned long get_ip() struct in_addr *in; /* could be pre-defined */ - if (uptime_host[0]) { - if ((uptime_host[strlen(uptime_host) - 1] >= '0') && - (uptime_host[strlen(uptime_host) - 1] <= '9')) - return (IP) inet_addr(uptime_host); + if (UPTIME_HOST[0]) { + if ((UPTIME_HOST[strlen(UPTIME_HOST) - 1] >= '0') && + (UPTIME_HOST[strlen(UPTIME_HOST) - 1] <= '9')) + return (IP) inet_addr(UPTIME_HOST); } - hp = gethostbyname(uptime_host); + hp = gethostbyname(UPTIME_HOST); if (hp == NULL) return -1; in = (struct in_addr *) (hp->h_addr_list[0]); @@ -136,7 +137,7 @@ int init_uptime(void) upPack.regnr = 0; /* unused */ upPack.pid = 0; /* must set this later */ - upPack.type = htonl(uptime_type); + upPack.type = htonl(UPTIME_TYPE); upPack.packets_sent = 0; /* reused (abused?) to send our packet count */ upPack.uptime = 0; /* must set this later */ uptimecount = 0; @@ -159,7 +160,7 @@ int init_uptime(void) } fcntl(uptimesock, F_SETFL, O_NONBLOCK | fcntl(uptimesock, F_GETFL)); - next_minutes = random() % update_interval; /* Initial update delay */ + next_minutes = random() % UPDATE_INTERVAL; /* Initial update delay */ next_seconds = random() % 59; next_update = (time_t) ((time(NULL) / 60 * 60) + (next_minutes * 60) + next_seconds); @@ -218,7 +219,7 @@ int send_uptime(void) egg_bzero(&sai, sizeof(sai)); sai.sin_family = AF_INET; sai.sin_addr.s_addr = uptimeip; - sai.sin_port = htons(uptime_port); + sai.sin_port = htons(UPTIME_PORT); len = sendto(uptimesock, (void *) mem, len, 0, (struct sockaddr *) &sai, sizeof(sai)); nfree(mem); @@ -245,7 +246,7 @@ void check_secondly() minutes = 0; /* Reset for the next countdown. */ seconds = 0; - next_minutes = random() % update_interval; + next_minutes = random() % UPDATE_INTERVAL; next_seconds = random() % 59; next_update = (time_t) ((time(NULL) / 60 * 60) + (next_minutes * 60) + next_seconds); diff --git a/src/mod/uptime.mod/uptime.h b/src/mod/uptime.mod/uptime.h index ff57b3bc9d..93252432ef 100644 --- a/src/mod/uptime.mod/uptime.h +++ b/src/mod/uptime.mod/uptime.h @@ -23,8 +23,8 @@ #ifndef _EGG_MOD_UPTIME_UPTIME_H #define _EGG_MOD_UPTIME_UPTIME_H -static const int uptime_type = 2; -static int uptime_port = 9969; -static const char *uptime_host = "uptime.eggheads.org"; +#define UPTIME_TYPE 2 +#define UPTIME_PORT 9969 +#define UPTIME_HOST "uptime.eggheads.org" #endif /* _EGG_MOD_UPTIME_UPTIME_H */ From f44dfad4689a732befd6df514998b6210022b584 Mon Sep 17 00:00:00 2001 From: michaelortmann Date: Sat, 13 Oct 2018 21:24:51 +0200 Subject: [PATCH 12/27] cleanup includes --- src/mod/uptime.mod/uptime.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/mod/uptime.mod/uptime.c b/src/mod/uptime.mod/uptime.c index 573614c7d7..cc71255605 100644 --- a/src/mod/uptime.mod/uptime.c +++ b/src/mod/uptime.mod/uptime.c @@ -33,19 +33,11 @@ #define MODULE_NAME "uptime" #define MAKING_UPTIME +#include +#include #include "uptime.h" #include "../module.h" #include "../server.mod/server.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #define UPDATE_INTERVAL (12 * 60) /* random(0..12) hours: ~6 hour average. */ From 57d7528b2c54c3e4851ef1ff31b311df28e82ffd Mon Sep 17 00:00:00 2001 From: michaelortmann Date: Sat, 13 Oct 2018 21:45:55 +0200 Subject: [PATCH 13/27] sizeof -> offsetof; added comment; my_memcpy -> memcpy --- src/mod/uptime.mod/uptime.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mod/uptime.mod/uptime.c b/src/mod/uptime.mod/uptime.c index cc71255605..6fe1a73939 100644 --- a/src/mod/uptime.mod/uptime.c +++ b/src/mod/uptime.mod/uptime.c @@ -203,10 +203,10 @@ int send_uptime(void) else upPack.sysup = htonl(st.st_ctime); - len = sizeof(upPack) + strlen(botnetnick) + strlen(servhost) + - strlen(uptime_version) + 3; + len = offsetof(struct PackUp, string) + strlen(botnetnick) + strlen(servhost) + + strlen(uptime_version) + 3; /* whitespace + whitespace + \0 */ mem = (PackUp *) nmalloc(len); - my_memcpy(mem, &upPack, sizeof(upPack)); + memcpy(mem, &upPack, sizeof(upPack)); sprintf(mem->string, "%s %s %s", botnetnick, servhost, uptime_version); egg_bzero(&sai, sizeof(sai)); sai.sin_family = AF_INET; From 496d5cec8883c7cffd69055b29958e63f8612948 Mon Sep 17 00:00:00 2001 From: michaelortmann Date: Sun, 14 Oct 2018 01:28:37 +0200 Subject: [PATCH 14/27] tab -> space, format --- src/mod/uptime.mod/uptime.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mod/uptime.mod/uptime.c b/src/mod/uptime.mod/uptime.c index 6fe1a73939..8391fd0035 100644 --- a/src/mod/uptime.mod/uptime.c +++ b/src/mod/uptime.mod/uptime.c @@ -177,8 +177,8 @@ int send_uptime(void) } uptimecount++; - upPack.packets_sent = htonl(uptimecount); /* Tell the server how many - uptime packets we've sent. */ + upPack.packets_sent = htonl(uptimecount); /* Tell the server how many uptime + packets we've sent. */ upPack.now2 = htonl(time(NULL)); upPack.ontime = 0; From 5e899950d698ff6496f1aa8002f03c57b9ba9de5 Mon Sep 17 00:00:00 2001 From: michaelortmann Date: Sun, 14 Oct 2018 02:49:25 +0200 Subject: [PATCH 15/27] gethostbyname -> getaddrinfo(); prepare fr ipv6 ;); static functions --- src/mod/uptime.mod/uptime.c | 61 +++++++++++++------------------------ src/mod/uptime.mod/uptime.h | 2 +- 2 files changed, 23 insertions(+), 40 deletions(-) diff --git a/src/mod/uptime.mod/uptime.c b/src/mod/uptime.mod/uptime.c index 8391fd0035..7f6a0c305b 100644 --- a/src/mod/uptime.mod/uptime.c +++ b/src/mod/uptime.mod/uptime.c @@ -77,8 +77,8 @@ static int uptimecount; static unsigned long uptimeip; static char uptime_version[48] = ""; -void check_secondly(void); -void check_minutely(void); +static void check_secondly(void); +static void check_minutely(void); static int uptime_expmem() { @@ -102,27 +102,7 @@ static void uptime_report(int idx, int details) } } -static unsigned long get_ip() -{ - struct hostent *hp; - IP ip; - struct in_addr *in; - - /* could be pre-defined */ - if (UPTIME_HOST[0]) { - if ((UPTIME_HOST[strlen(UPTIME_HOST) - 1] >= '0') && - (UPTIME_HOST[strlen(UPTIME_HOST) - 1] <= '9')) - return (IP) inet_addr(UPTIME_HOST); - } - hp = gethostbyname(UPTIME_HOST); - if (hp == NULL) - return -1; - in = (struct in_addr *) (hp->h_addr_list[0]); - ip = (IP) (in->s_addr); - return ip; -} - -int init_uptime(void) +static int init_uptime(void) { struct sockaddr_in sai; char x[64], *z = x; @@ -161,19 +141,24 @@ int init_uptime(void) } -int send_uptime(void) +static int send_uptime(void) { - struct sockaddr_in sai; + struct addrinfo hints, *res0; + int error; struct stat st; PackUp *mem; int len, servidx; char servhost[UHOSTLEN] = "none"; module_entry *me; - if (uptimeip == -1) { - uptimeip = get_ip(); - if (uptimeip == -1) - return -2; + egg_bzero(&hints, sizeof(hints)); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_DGRAM; + error = getaddrinfo(UPTIME_HOST, UPTIME_PORT, &hints, &res0); + if (error) { + putlog(LOG_DEBUG, "*", "send_uptime(): getaddrinfo(): %s", + gai_strerror(error)); + return -2; } uptimecount++; @@ -203,22 +188,20 @@ int send_uptime(void) else upPack.sysup = htonl(st.st_ctime); - len = offsetof(struct PackUp, string) + strlen(botnetnick) + strlen(servhost) + - strlen(uptime_version) + 3; /* whitespace + whitespace + \0 */ + len = offsetof(struct PackUp, string) + strlen(botnetnick) + strlen(servhost) + + strlen(uptime_version) + 3; /* whitespace + whitespace + \0 */ mem = (PackUp *) nmalloc(len); memcpy(mem, &upPack, sizeof(upPack)); sprintf(mem->string, "%s %s %s", botnetnick, servhost, uptime_version); - egg_bzero(&sai, sizeof(sai)); - sai.sin_family = AF_INET; - sai.sin_addr.s_addr = uptimeip; - sai.sin_port = htons(UPTIME_PORT); - len = sendto(uptimesock, (void *) mem, len, 0, (struct sockaddr *) &sai, - sizeof(sai)); + len = sendto(uptimesock, (void *) mem, len, 0, res0->ai_addr, + res0->ai_addrlen); + if (len < 0) + putlog(LOG_DEBUG, "*", "send_uptime(): sendto(): %s", gai_strerror(error)); nfree(mem); return len; } -void check_minutely() +static void check_minutely() { minutes++; if (minutes >= next_minutes) { @@ -228,7 +211,7 @@ void check_minutely() } } -void check_secondly() +static void check_secondly() { seconds++; if (seconds >= next_seconds) { /* DING! */ diff --git a/src/mod/uptime.mod/uptime.h b/src/mod/uptime.mod/uptime.h index 93252432ef..3a5714ea5d 100644 --- a/src/mod/uptime.mod/uptime.h +++ b/src/mod/uptime.mod/uptime.h @@ -24,7 +24,7 @@ #define _EGG_MOD_UPTIME_UPTIME_H #define UPTIME_TYPE 2 -#define UPTIME_PORT 9969 #define UPTIME_HOST "uptime.eggheads.org" +#define UPTIME_PORT "9969" #endif /* _EGG_MOD_UPTIME_UPTIME_H */ From 6099b88fdcab650caa6afa271d09b0e5e3589de7 Mon Sep 17 00:00:00 2001 From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com> Date: Thu, 12 Sep 2019 23:25:29 +0200 Subject: [PATCH 16/27] Cleanup sizeof --- src/mod/uptime.mod/uptime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mod/uptime.mod/uptime.c b/src/mod/uptime.mod/uptime.c index ef7f07623e..739fb5309c 100644 --- a/src/mod/uptime.mod/uptime.c +++ b/src/mod/uptime.mod/uptime.c @@ -151,7 +151,7 @@ static int send_uptime(void) char servhost[UHOSTLEN] = "none"; module_entry *me; - egg_bzero(&hints, sizeof(hints)); + egg_bzero(&hints, sizeof hints); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_DGRAM; error = getaddrinfo(UPTIME_HOST, UPTIME_PORT, &hints, &res0); From b27615997adf088196af79ee4098f69586bed9eb Mon Sep 17 00:00:00 2001 From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com> Date: Tue, 26 Nov 2019 07:47:25 +0100 Subject: [PATCH 17/27] Cleanup --- src/mod/uptime.mod/uptime.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/mod/uptime.mod/uptime.c b/src/mod/uptime.mod/uptime.c index 739fb5309c..059ffe7478 100644 --- a/src/mod/uptime.mod/uptime.c +++ b/src/mod/uptime.mod/uptime.c @@ -134,8 +134,7 @@ static int init_uptime(void) next_minutes = random() % UPDATE_INTERVAL; /* Initial update delay */ next_seconds = random() % 59; - next_update = (time_t) ((time(NULL) / 60 * 60) + (next_minutes * 60) + - next_seconds); + next_update = (time_t) (time(NULL) + next_minutes * 60 + next_seconds); return 0; } From a9966e0908f17f4dc45e3d953a9ea27e6d705b0f Mon Sep 17 00:00:00 2001 From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com> Date: Tue, 26 Nov 2019 07:55:30 +0100 Subject: [PATCH 18/27] Cleanup --- src/mod/uptime.mod/uptime.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/mod/uptime.mod/uptime.c b/src/mod/uptime.mod/uptime.c index 059ffe7478..1b78c4c825 100644 --- a/src/mod/uptime.mod/uptime.c +++ b/src/mod/uptime.mod/uptime.c @@ -222,8 +222,7 @@ static void check_secondly() seconds = 0; next_minutes = random() % UPDATE_INTERVAL; next_seconds = random() % 59; - next_update = (time_t) ((time(NULL) / 60 * 60) + (next_minutes * 60) + - next_seconds); + next_update = (time_t) (time(NULL) + next_minutes * 60 + next_seconds); /* Go back to checking every minute. */ add_hook(HOOK_MINUTELY, (Function) check_minutely); From 26e58f0dc996222b7a7514fdff0b1aab3f1501fb Mon Sep 17 00:00:00 2001 From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com> Date: Tue, 26 Nov 2019 08:05:32 +0100 Subject: [PATCH 19/27] undo my stupidity --- src/mod/uptime.mod/uptime.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/mod/uptime.mod/uptime.c b/src/mod/uptime.mod/uptime.c index 1b78c4c825..739fb5309c 100644 --- a/src/mod/uptime.mod/uptime.c +++ b/src/mod/uptime.mod/uptime.c @@ -134,7 +134,8 @@ static int init_uptime(void) next_minutes = random() % UPDATE_INTERVAL; /* Initial update delay */ next_seconds = random() % 59; - next_update = (time_t) (time(NULL) + next_minutes * 60 + next_seconds); + next_update = (time_t) ((time(NULL) / 60 * 60) + (next_minutes * 60) + + next_seconds); return 0; } @@ -222,7 +223,8 @@ static void check_secondly() seconds = 0; next_minutes = random() % UPDATE_INTERVAL; next_seconds = random() % 59; - next_update = (time_t) (time(NULL) + next_minutes * 60 + next_seconds); + next_update = (time_t) ((time(NULL) / 60 * 60) + (next_minutes * 60) + + next_seconds); /* Go back to checking every minute. */ add_hook(HOOK_MINUTELY, (Function) check_minutely); From 4686ec03551d24f0bdf14718235b6078f9be77e6 Mon Sep 17 00:00:00 2001 From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com> Date: Sat, 23 Oct 2021 07:04:12 +0200 Subject: [PATCH 20/27] simplify, we dont need this string copy --- src/mod/uptime.mod/uptime.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mod/uptime.mod/uptime.c b/src/mod/uptime.mod/uptime.c index 3f457b1c20..45b4271804 100644 --- a/src/mod/uptime.mod/uptime.c +++ b/src/mod/uptime.mod/uptime.c @@ -148,7 +148,7 @@ static int send_uptime(void) struct stat st; PackUp *mem; int len, servidx; - char servhost[UHOSTLEN] = "none"; + char *servhost = "none"; module_entry *me; egg_bzero(&hints, sizeof hints); @@ -172,7 +172,7 @@ static int send_uptime(void) if (server_online) { servidx = findanyidx(serv); - strlcpy(servhost, dcc[servidx].host, sizeof servhost); + servhost = dcc[servidx].host; upPack.ontime = htonl(server_online); } } From 6040550eb1ba8ef81456e556cb81466c6da5e670 Mon Sep 17 00:00:00 2001 From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com> Date: Sat, 23 Oct 2021 14:33:32 +0200 Subject: [PATCH 21/27] update module minor version --- src/mod/uptime.mod/uptime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mod/uptime.mod/uptime.c b/src/mod/uptime.mod/uptime.c index 45b4271804..ccdf1ccf7b 100644 --- a/src/mod/uptime.mod/uptime.c +++ b/src/mod/uptime.mod/uptime.c @@ -251,7 +251,7 @@ char *uptime_start(Function *global_funcs) if (global_funcs) { global = global_funcs; - module_register(MODULE_NAME, uptime_table, 1, 4); + module_register(MODULE_NAME, uptime_table, 1, 5); if (!module_depend(MODULE_NAME, "eggdrop", 108, 0)) { module_undepend(MODULE_NAME); return "This module requires Eggdrop 1.8.0 or later."; From b48ca7bfbc67affc38a1338a7249def229af2e55 Mon Sep 17 00:00:00 2001 From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com> Date: Thu, 15 Sep 2022 23:32:24 +0200 Subject: [PATCH 22/27] Enhance logging --- src/mod/uptime.mod/uptime.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/mod/uptime.mod/uptime.c b/src/mod/uptime.mod/uptime.c index c3979095f1..494e59d59f 100644 --- a/src/mod/uptime.mod/uptime.c +++ b/src/mod/uptime.mod/uptime.c @@ -156,8 +156,13 @@ static int send_uptime(void) hints.ai_socktype = SOCK_DGRAM; error = getaddrinfo(UPTIME_HOST, UPTIME_PORT, &hints, &res0); if (error) { - putlog(LOG_DEBUG, "*", "send_uptime(): getaddrinfo(): %s", - gai_strerror(error)); + if (error == EAI_NONAME) + putlog(LOG_MISC, "*", + "send_uptime(): getaddrinfo(): hostname:port '%s:%s' not known", + UPTIME_HOST, UPTIME_PORT); + else + putlog(LOG_MISC, "*", "send_uptime(): getaddrinfo(): error = %s", + gai_strerror(error)); return -2; } From 563b60fbcf5b25268445c198db4713169702708f Mon Sep 17 00:00:00 2001 From: Michael Ortmann Date: Thu, 4 Jan 2024 00:02:14 +0100 Subject: [PATCH 23/27] Fix include --- src/mod/uptime.mod/uptime.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mod/uptime.mod/uptime.c b/src/mod/uptime.mod/uptime.c index c8850cedc1..4c7760f986 100644 --- a/src/mod/uptime.mod/uptime.c +++ b/src/mod/uptime.mod/uptime.c @@ -34,6 +34,7 @@ #define MAKING_UPTIME #include +#include #include #include "uptime.h" #include "../module.h" From f68ed1459d79a87105a64c21505b74b81884df0a Mon Sep 17 00:00:00 2001 From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com> Date: Wed, 10 Jul 2024 20:46:22 +0200 Subject: [PATCH 24/27] Fix include / --disable-tls --- src/mod/uptime.mod/uptime.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mod/uptime.mod/uptime.c b/src/mod/uptime.mod/uptime.c index 2f1f96bb56..2045ab75b0 100644 --- a/src/mod/uptime.mod/uptime.c +++ b/src/mod/uptime.mod/uptime.c @@ -35,6 +35,7 @@ #include #include +#include #include #include "uptime.h" #include "../module.h" From e5ec86b2020550b1df58857a1cb2f4e0118d1763 Mon Sep 17 00:00:00 2001 From: Michael Ortmann Date: Fri, 17 Oct 2025 13:14:42 +0200 Subject: [PATCH 25/27] Make struct packed --- src/mod/uptime.mod/uptime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mod/uptime.mod/uptime.c b/src/mod/uptime.mod/uptime.c index 6ce6e59db2..09fbc30437 100644 --- a/src/mod/uptime.mod/uptime.c +++ b/src/mod/uptime.mod/uptime.c @@ -53,7 +53,7 @@ * packets the client thinks it has sent over the life of the module. Only the * name has changed - the type is still the same. */ -typedef struct PackUp { +typedef struct __attribute__((packed)) PackUp { uint32_t regnr; uint32_t pid; uint32_t type; From 7dbb60cc5bcc6aa3de94779ca591b68b92b981a6 Mon Sep 17 00:00:00 2001 From: Michael Ortmann Date: Sat, 30 May 2026 14:19:22 +0200 Subject: [PATCH 26/27] Fix and enhance error logging --- src/mod/uptime.mod/uptime.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/mod/uptime.mod/uptime.c b/src/mod/uptime.mod/uptime.c index 09fbc30437..fbdab08fcf 100644 --- a/src/mod/uptime.mod/uptime.c +++ b/src/mod/uptime.mod/uptime.c @@ -34,6 +34,7 @@ #define MAKING_UPTIME #include +#include #include #include #include @@ -122,13 +123,14 @@ static int init_uptime(void) strlcpy(uptime_version, z, sizeof uptime_version); if ((uptimesock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { - putlog(LOG_DEBUG, "*", "init_uptime socket returned < 0 %d", uptimesock); + putlog(LOG_DEBUG, "*", "Error: init_uptime(): socket(): %s", strerror(errno)); return ((uptimesock = -1)); } egg_bzero(&sai, sizeof(sai)); sai.sin_addr.s_addr = INADDR_ANY; sai.sin_family = AF_INET; if (bind(uptimesock, (struct sockaddr *) &sai, sizeof(sai)) < 0) { + putlog(LOG_DEBUG, "*", "Error: init_uptime(): bind(): %s", strerror(errno)); close(uptimesock); return ((uptimesock = -1)); } @@ -203,7 +205,7 @@ static int send_uptime(void) len = sendto(uptimesock, (void *) mem, len, 0, res0->ai_addr, res0->ai_addrlen); if (len < 0) - putlog(LOG_DEBUG, "*", "send_uptime(): sendto(): %s", gai_strerror(error)); + putlog(LOG_DEBUG, "*", "Error: send_uptime(): sendto(): %s", strerror(errno)); nfree(mem); return len; } From e8d7653a3f8647936daf9719e22e71a109e1a6dd Mon Sep 17 00:00:00 2001 From: Michael Ortmann Date: Sat, 30 May 2026 14:25:41 +0200 Subject: [PATCH 27/27] Cleanup --- src/mod/uptime.mod/uptime.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mod/uptime.mod/uptime.c b/src/mod/uptime.mod/uptime.c index fbdab08fcf..b4690d233e 100644 --- a/src/mod/uptime.mod/uptime.c +++ b/src/mod/uptime.mod/uptime.c @@ -123,14 +123,14 @@ static int init_uptime(void) strlcpy(uptime_version, z, sizeof uptime_version); if ((uptimesock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { - putlog(LOG_DEBUG, "*", "Error: init_uptime(): socket(): %s", strerror(errno)); + putlog(LOG_DEBUG, "*", "init_uptime(): socket(): %s", strerror(errno)); return ((uptimesock = -1)); } egg_bzero(&sai, sizeof(sai)); sai.sin_addr.s_addr = INADDR_ANY; sai.sin_family = AF_INET; if (bind(uptimesock, (struct sockaddr *) &sai, sizeof(sai)) < 0) { - putlog(LOG_DEBUG, "*", "Error: init_uptime(): bind(): %s", strerror(errno)); + putlog(LOG_DEBUG, "*", "init_uptime(): bind(): %s", strerror(errno)); close(uptimesock); return ((uptimesock = -1)); } @@ -205,7 +205,7 @@ static int send_uptime(void) len = sendto(uptimesock, (void *) mem, len, 0, res0->ai_addr, res0->ai_addrlen); if (len < 0) - putlog(LOG_DEBUG, "*", "Error: send_uptime(): sendto(): %s", strerror(errno)); + putlog(LOG_DEBUG, "*", "send_uptime(): sendto(): %s", strerror(errno)); nfree(mem); return len; }