From 42a5043091a77ee3dc29d7d861d1206fa215ea4f Mon Sep 17 00:00:00 2001 From: Michiel Broek Date: Sat, 17 Dec 2005 16:35:10 +0000 Subject: [PATCH] Added crc32 value to server state table --- mbtask/crc.c | 16 ++++++++++++++++ mbtask/taskibc.c | 15 ++++++++++++--- mbtask/taskibc.h | 1 + 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/mbtask/crc.c b/mbtask/crc.c index 60af5f0e..943c3654 100644 --- a/mbtask/crc.c +++ b/mbtask/crc.c @@ -119,3 +119,19 @@ unsigned int StringCRC32(char *str) +/* + * Update CRC32, first initialize crc with 0xffffffff + */ +unsigned int upd_crc32(char *buf, unsigned int crc, int len) +{ + int i; + unsigned int cr; + + cr = crc; + for (i = 0; i < len; i++) { + cr = (crc32tab[((int)cr ^ ((int)buf[i])) & 0xff] ^ ((((unsigned int)cr) >> 8) & 0x00ffffffL)); + } + return cr; +} + + diff --git a/mbtask/taskibc.c b/mbtask/taskibc.c index 1bd952c6..8ca4cb1a 100644 --- a/mbtask/taskibc.c +++ b/mbtask/taskibc.c @@ -60,6 +60,7 @@ int chnchg = FALSE; /* Is channellist changed */ int banchg = FALSE; /* Is banned users changed */ int nickchg = FALSE; /* Is nicknames changed */ +#define PING_PONG_LOG 1 pthread_mutex_t b_mutex = PTHREAD_MUTEX_INITIALIZER; @@ -78,7 +79,7 @@ static char *ncsstate[] = { /* * Internal prototypes */ -void fill_ncslist(ncs_list **, char *, char *, char *, int); +void fill_ncslist(ncs_list **, char *, char *, char *, int, unsigned int); void dump_ncslist(void); void tidy_servers(srv_list **); int add_server(srv_list **, char *, int, char *, char *, char *, char *); @@ -104,7 +105,7 @@ void receiver(struct servent *); /* * Add a server to the serverlist */ -void fill_ncslist(ncs_list **fdp, char *server, char *myname, char *passwd, int dyndns) +void fill_ncslist(ncs_list **fdp, char *server, char *myname, char *passwd, int dyndns, unsigned int crc) { ncs_list *tmp, *ta; @@ -128,6 +129,7 @@ void fill_ncslist(ncs_list **fdp, char *server, char *myname, char *passwd, int tmp->gotserver = FALSE; tmp->dyndns = dyndns; tmp->halfdead = 0; + tmp->crc = crc; if (*fdp == NULL) { *fdp = tmp; @@ -608,6 +610,7 @@ void check_servers(void) srv_list *srv; int j, inlist, Remove; int a1, a2, a3, a4; + unsigned int crc; struct servent *se; struct hostent *he; @@ -630,6 +633,12 @@ void check_servers(void) fread(&ibcsrvhdr, sizeof(ibcsrvhdr), 1, fp); while (fread(&ibcsrv, ibcsrvhdr.recsize, 1, fp)) { + crc = 0xffffffff; + crc = upd_crc32((char *)&ibcsrv, crc, sizeof(ibcsrv)); + + /* + * Check for new configured servers + */ if (ibcsrv.Active) { inlist = FALSE; for (tnsl = ncsl; tnsl; tnsl = tnsl->next) { @@ -645,7 +654,7 @@ void check_servers(void) } } if (!inlist ) { - fill_ncslist(&ncsl, ibcsrv.server, ibcsrv.myname, ibcsrv.passwd, ibcsrv.Dyndns); + fill_ncslist(&ncsl, ibcsrv.server, ibcsrv.myname, ibcsrv.passwd, ibcsrv.Dyndns, crc); srvchg = TRUE; callchg = TRUE; Syslog('+', "IBC: new configured Internet BBS Chatserver: %s", ibcsrv.server); diff --git a/mbtask/taskibc.h b/mbtask/taskibc.h index 9a2de030..c2ad65c4 100644 --- a/mbtask/taskibc.h +++ b/mbtask/taskibc.h @@ -26,6 +26,7 @@ typedef struct _ncs_list { int socket; /* Peer socket */ unsigned int token; /* Server token */ int halfdead; /* Halfdead connect count */ + unsigned int crc; /* CRC value of record */ } ncs_list;