From 09bd0186c6a568b8a1028d119e5289cb3ec88083 Mon Sep 17 00:00:00 2001 From: teodor Date: Fri, 30 Nov 2007 18:08:56 +0000 Subject: [PATCH] Adapt for changes in tedtools --- rtop.c | 10 ++++++---- sendtop.c | 6 +++--- td_lmsg.c | 18 ++++++++++-------- top.h | 2 +- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/rtop.c b/rtop.c index 59b1664..a9f7260 100644 --- a/rtop.c +++ b/rtop.c @@ -67,7 +67,6 @@ main( int argc, char *argv[] ) { int port=TOPD_SERVER_DEFAULT_PORT; int i; - MassiveUnit *mu; TCMsg *pmsg; TC_Connection cs; @@ -100,13 +99,16 @@ main( int argc, char *argv[] ) { pmsg = (TCMsg*)tmalloc( TCMSGHDRSZ ); pmsg->type = TOPGETTYPE; pmsg->len = TCMSGHDRSZ; - cs.buf = (char*)pmsg; - cs.len = pmsg->len; + cs.buf = pmsg; if ( TC_Talk(&cs, 0) == CS_OK ) { - pmsg = (TCMsg*) cs.buf; + MassiveUnit *mu; + + pmsg = cs.buf; mu = (MassiveUnit*)pmsg->data; + tlog(TL_DEBUG,"Got packet len:%db type:%08x n:%d", pmsg->len, pmsg->type, mu->number); + printf("\tIP\tLoad\tFree\tTotal\tDate\n"); for(i=0; inumber; i++) printf("%s\t%.2f\t%.1fM\t%.1fM\t%s", diff --git a/sendtop.c b/sendtop.c index ce24d62..9b41b22 100644 --- a/sendtop.c +++ b/sendtop.c @@ -169,17 +169,17 @@ fillMsgTop(TCMsgTop *m) { static int sendTop(Msg *msg) { TCMsg *pmsg; + int msglen = TCMSGHDRSZ + sizeof(TCMsgTop); if ( !msg->msg ) { - int msglen = TCMSGHDRSZ + sizeof(TCMsgTop); pmsg = (TCMsg*)tmalloc(msglen); - pmsg->len = msglen; - pmsg->type=TOPMSGTYPE; msg->msg = pmsg; } else { pmsg = msg->msg; } + pmsg->len = msglen; + pmsg->type=TOPMSGTYPE; fillMsgTop( (TCMsgTop*)(pmsg->data) ); return TC_sendMsg(msg); diff --git a/td_lmsg.c b/td_lmsg.c index cd6e6ad..22cd925 100644 --- a/td_lmsg.c +++ b/td_lmsg.c @@ -37,23 +37,25 @@ static void getTopData(TC_Connection *conn) { TCMsg *pmsg; + conn->len = TCMSGHDRSZ + MUHDRSZ + cfg.mu->number * sizeof(UnitInfo); conn->buf = trealloc( conn->buf, conn->len ); - pmsg = (TCMsg*) conn->buf; - + pmsg = conn->buf; + pmsg->len = conn->len; pmsg->type = TOPGETTYPE; memcpy( pmsg->data, cfg.mu, pmsg->len - TCMSGHDRSZ ); ((MassiveUnit*)pmsg->data)->maxnumber = cfg.mu->number; + TC_Send(conn); } static void gotLongMessage( TC_Connection *conn ) { - TCMsg *pmsg = (TCMsg*) conn->buf; + TCMsg *pmsg = conn->buf; - if ( conn->ptr - conn->buf < TCMSGHDRSZ ) { - tlog(TL_ALARM,"Wrong size of long message (%d bytes)", conn->ptr - conn->buf); + if ( conn->ptr -(char*) conn->buf < TCMSGHDRSZ ) { + tlog(TL_ALARM,"Wrong size of long message (%d bytes)", conn->ptr - (char*)conn->buf); conn->state = CS_ERROR; return; } @@ -63,20 +65,20 @@ gotLongMessage( TC_Connection *conn ) { getTopData(conn); break; default: - tlog(TL_ALARM,"Got unknown packet type: %d", pmsg->type); + tlog(TL_ALARM,"Got unknown packet type: %u (%08x)", pmsg->type, pmsg->type); conn->state = CS_ERROR; } } static void sendedLongMessage( TC_Connection *conn ) { - TCMsg *pmsg = (TCMsg*) conn->buf; + TCMsg *pmsg = conn->buf; switch(pmsg->type) { case TOPGETTYPE: conn->state = CS_FINISH; break; default: - tlog(TL_ALARM,"Send unknown packet type: %d", pmsg->type); + tlog(TL_ALARM,"Send unknown packet type: %u(0x%08x)", pmsg->type, pmsg->type); conn->state = CS_ERROR; } } diff --git a/top.h b/top.h index 64a8f1b..8fb1dd3 100644 --- a/top.h +++ b/top.h @@ -55,7 +55,7 @@ typedef struct { UnitInfo units[1]; } MassiveUnit; -#define MUHDRSZ (2*sizeof(u_int32_t)) +#define MUHDRSZ offsetof( MassiveUnit, units ) MassiveUnit *allocUnits(int n); void fillUnit( MassiveUnit* mu, UnitInfo *unit ); -- 2.46.1