From 542a96b7352e46975aa28faced43dae70a9ebeef Mon Sep 17 00:00:00 2001 From: Bradley Bell Date: Fri, 15 Feb 2002 06:41:42 +0000 Subject: [PATCH] enable udp debug messages --- arch/linux/arch_ip.cpp | 19 +++++++++------ arch/win32/arch_ip.cpp | 15 +++++++----- main/ip_base.cpp | 55 ++++++++++++++++++++++-------------------- main/ip_base.h | 20 ++++++++++----- main/ipclient.cpp | 19 +++++++++------ 5 files changed, 74 insertions(+), 54 deletions(-) diff --git a/arch/linux/arch_ip.cpp b/arch/linux/arch_ip.cpp index d66b881c..28bb915c 100644 --- a/arch/linux/arch_ip.cpp +++ b/arch/linux/arch_ip.cpp @@ -1,13 +1,16 @@ /* * $Source: /cvs/cvsroot/d2x/arch/linux/arch_ip.cpp,v $ - * $Revision: 1.1 $ + * $Revision: 1.2 $ * $Author: bradleyb $ - * $Date: 2002-02-06 09:22:41 $ + * $Date: 2002-02-15 06:41:41 $ * * arch_ip.cpp - arch specific udp/ip code. (linux ver) * added 2000/02/07 Matt Mueller (some code borrowed from ipx_udp.c) * * $Log: not supported by cvs2svn $ + * Revision 1.1 2002/02/06 09:22:41 bradleyb + * Adding d1x network code + * * */ @@ -95,10 +98,10 @@ int ip_sendtoca(ip_addr addr,const void *buf,int len){ memcpy(&toaddr.sin_addr,addr.addr,4); toaddr.sin_port=*(unsigned short *)(addr.addr+4); #ifdef UDPDEBUG - printf(MSGHDR "sendtoca((%d) ",len); + con_printf(CON_DEBUG, MSGHDR "sendtoca((%d) ",len); //dumpraddr(addr.addr); addr.dump(); - puts(")."); + con_printf(CON_DEBUG, ").\n"); #endif return sendto(mysock,buf,len,0,(struct sockaddr *)&toaddr,sizeof(toaddr)); } @@ -161,9 +164,9 @@ int arch_ip_get_my_addr(u_short myport){ if (sinp->sin_family!=AF_INET) continue; addr.set(4,(ubyte*)&sinp->sin_addr,htons(myport)); #ifdef UDPDEBUG - printf(MSGHDR"added if "); + con_printf(CON_DEBUG, MSGHDR"added if "); addr.dump(); - printf("\n"); + con_printf(CON_DEBUG, "\n"); #endif ip_my_addrs.add(addr); } @@ -225,9 +228,9 @@ int arch_ip_recvfrom(char*outbuf,int outbufsize,struct ipx_recv_data *rd){ if (fromaddr.sin_family!=AF_INET) return -1; #ifdef UDPDEBUG - printf(MSGHDR "recvfrom((%d-2=%d),",size,size-2); + con_printf(CON_DEBUG, MSGHDR "recvfrom((%d-2=%d),",size,size-2); dumpaddr(&fromaddr); - puts(")."); + con_printf(CON_DEBUG, ").\n"); #endif ip_fromaddr.set(4,(u_char*)&fromaddr.sin_addr,fromaddr.sin_port); diff --git a/arch/win32/arch_ip.cpp b/arch/win32/arch_ip.cpp index aaefa163..c2078be1 100644 --- a/arch/win32/arch_ip.cpp +++ b/arch/win32/arch_ip.cpp @@ -1,13 +1,16 @@ /* * $Source: /cvs/cvsroot/d2x/arch/win32/arch_ip.cpp,v $ - * $Revision: 1.1 $ + * $Revision: 1.2 $ * $Author: bradleyb $ - * $Date: 2002-02-15 02:29:33 $ + * $Date: 2002-02-15 06:41:41 $ * * arch_ip.cpp - arch specific udp/ip code. (win32 ver) * added 2000/02/07 Matt Mueller (some code borrowed from ipx_udp.c) * * $Log: not supported by cvs2svn $ + * Revision 1.1 2002/02/15 02:29:33 bradleyb + * copied from d1x + * * */ @@ -96,10 +99,10 @@ int ip_sendtoca(ip_addr addr,const void *buf,int len){ memcpy(&toaddr.sin_addr,addr.addr,4); toaddr.sin_port=*(unsigned short *)(addr.addr+4); #ifdef UDPDEBUG - printf(MSGHDR "sendtoca((%d) ",len); + con_printf(CON_DEBUG, MSGHDR "sendtoca((%d) ",len); //dumpraddr(addr.addr); addr.dump(); - puts(")."); + con_printf(").\n"); #endif return sendto(mysock,(char*)buf,len,0,(struct sockaddr *)&toaddr,sizeof(toaddr)); } @@ -178,9 +181,9 @@ int arch_ip_recvfrom(char*outbuf,int outbufsize,struct ipx_recv_data *rd){ if (fromaddr.sin_family!=AF_INET) return -1; #ifdef UDPDEBUG - printf(MSGHDR "recvfrom((%d-2=%d),",size,size-2); + con_printf(CON_DEBUG, MSGHDR "recvfrom((%d-2=%d),",size,size-2); dumpaddr(&fromaddr); - puts(")."); + con_printf(CON_DEBUG(").\n"); #endif ip_fromaddr.set(4,(u_char*)&fromaddr.sin_addr,fromaddr.sin_port); diff --git a/main/ip_base.cpp b/main/ip_base.cpp index 7e58b8d4..b1c840a4 100644 --- a/main/ip_base.cpp +++ b/main/ip_base.cpp @@ -1,13 +1,16 @@ /* * $Source: /cvs/cvsroot/d2x/main/ip_base.cpp,v $ - * $Revision: 1.3 $ + * $Revision: 1.4 $ * $Author: bradleyb $ - * $Date: 2002-02-14 09:24:19 $ + * $Date: 2002-02-15 06:41:42 $ * * ip_base.cpp - base for NAT-compatible udp/ip code. * added 2000/02/07 Matt Mueller * * $Log: not supported by cvs2svn $ + * Revision 1.3 2002/02/14 09:24:19 bradleyb + * d1x->d2x + * * Revision 1.2 2002/02/13 10:39:21 bradleyb * Lotsa networking stuff from d1x * @@ -168,13 +171,13 @@ void ip_peer::send_handshake(ip_handshake_base*hsb){ /*#ifdef UDPDEBUG { int hj; - printf(MSGHDR"sending handshake %i (t%i state %i(%s)) for (%i)",hsb->attempts,hsb->type,hsb->state,ip_hs_statetoa(hsb->state),addr.goodaddr); + con_printf(CON_DEBUG, MSGHDR"sending handshake %i (t%i state %i(%s)) for (%i)",hsb->attempts,hsb->type,hsb->state,ip_hs_statetoa(hsb->state),addr.goodaddr); for (hj=0;hj0) - printf(", "); + con_printf(CON_DEBUG, ", "); dumpraddr(addr[hj].addr); } - printf(" v%i\n",iver); + con_printf(CON_DEBUG, " v%i\n",iver); } #endif*/ } @@ -295,13 +298,13 @@ struct do_peer_handshake : public unary_function{ if(hsb->attempts>IP_MAX_HS_ATTEMPTS){ /*#ifdef UDPDEBUG int hj; - printf(MSGHDR"handshake timeout (state %i(%s)) for (%i)",hsb->state,ip_hs_statetoa(hsb->state),peer->goodaddr); + con_printf(CON_DEBUG, MSGHDR"handshake timeout (state %i(%s)) for (%i)",hsb->state,ip_hs_statetoa(hsb->state),peer->goodaddr); for (hj=0;hjnumaddr;hj++){ if (hj>0) - printf(", "); + con_printf(CON_DEBUG, ", "); dumpraddr(peer->addr[hj].addr); } - printf(" v%i\n",peer->iver); + con_printf(CON_DEBUG, " v%i\n",peer->iver); #endif*/ hsb->setstate(STATE_ERR); }else{ @@ -352,7 +355,7 @@ ip_peer_list::~ip_peer_list(){ static void dumpid(unsigned char *a) { - printf("<%u.%u.%u.%u.%u.%u>",a[0],a[1],a[2],a[3],a[4],a[5]); + con_printf(CON_DEBUG, "<%u.%u.%u.%u.%u.%u>",a[0],a[1],a[2],a[3],a[4],a[5]); } #endif @@ -361,9 +364,9 @@ int ip_sendtoid(ubyte *id,const void *buf,int len){ ip_peer *p=peer_list.find_byid(id); if (!p || p->addr.goodaddr==NULL){ #ifdef UDPDEBUG - printf(MSGHDR"send to invalid id("); + con_printf(CON_DEBUG, MSGHDR"send to invalid id("); dumpid(id); - printf(") %p.",p); + con_printf(CON_DEBUG, ") %p.",p); #endif return -1; } @@ -376,17 +379,17 @@ void ip_receive_cfg(ubyte *buf,int buflen,ip_addr fromaddr){ case IP_CFG_SORRY: { #ifdef UDPDEBUG - printf("ip_receive_cfg: %i %i ",buf[0],buf[1]); + con_printf(CON_DEBUG, "ip_receive_cfg: %i %i ",buf[0],buf[1]); dumprid(buf+2); - printf(" v%i tryid%u\n",ntohs(*(unsigned short*)(buf+8)),(unsigned int)ntohl(*(u_int32_t*)(buf+10))); + con_printf(CON_DEBUG, " v%i tryid%u\n",ntohs(*(unsigned short*)(buf+8)),(unsigned int)ntohl(*(u_int32_t*)(buf+10))); #endif }break; case IP_CFG_HANDSHAKE: #ifdef UDPDEBUG - printf("ip_receive_cfg: %i %i ",buf[0],buf[1]); + con_printf(CON_DEBUG, "ip_receive_cfg: %i %i ",buf[0],buf[1]); dumprid(buf+2); - printf(" v%i tryid%u\n",ntohs(*(unsigned short*)(buf+8)),(unsigned int)ntohl(*(u_int32_t*)(buf+10))); + con_printf(CON_DEBUG, " v%i tryid%u\n",ntohs(*(unsigned short*)(buf+8)),(unsigned int)ntohl(*(u_int32_t*)(buf+10))); #endif { ip_handshake_info *hsi=new ip_handshake_info(buf); @@ -394,9 +397,9 @@ void ip_receive_cfg(ubyte *buf,int buflen,ip_addr fromaddr){ ip_handshake_info *lhsi=NULL; p=peer_list.find_byid(hsi->id); /*#ifdef UDPDEBUG - printf("hsi %i %i id=",hsi->type,hsi->state); + con_printf(CON_DEBUG, "hsi %i %i id=",hsi->type,hsi->state); hsi->id.dump(); - printf(" ver=%i tryid=%u\n",hsi->iver,hsi->tryid); + con_printf(CON_DEBUG, " ver=%i tryid=%u\n",hsi->iver,hsi->tryid); mprintf((0,"peer_list.find_byid=%p\n",p)); #endif*/ if (!p){ @@ -436,11 +439,11 @@ void ip_receive_cfg(ubyte *buf,int buflen,ip_addr fromaddr){ ip_peer *rp; ip_handshake_relay hsr(buf); #ifdef UDPDEBUG - printf("ip_receive_cfg: %i %i ",buf[0],buf[1]); + con_printf(CON_DEBUG, "ip_receive_cfg: %i %i ",buf[0],buf[1]); dumprid(buf+2); - printf(" v%i r_id ",ntohs(*(unsigned short*)(buf+8))); + con_printf(CON_DEBUG, " v%i r_id ",ntohs(*(unsigned short*)(buf+8))); hsr.r_id.dump(); - printf(" r_iv%i\n",hsr.r_iver); + con_printf(CON_DEBUG, " r_iv%i\n",hsr.r_iver); #endif p=peer_list.find_byid(hsr.id); if (!p) { @@ -458,11 +461,11 @@ void ip_receive_cfg(ubyte *buf,int buflen,ip_addr fromaddr){ break; rhsr->setstate(0); #ifdef UDPDEBUG - printf("**** "); + con_printf(CON_DEBUG, "**** "); p->id.dump(); - printf(" is ok with "); + con_printf(CON_DEBUG, " is ok with "); rp->id.dump(); - printf("\n"); + con_printf(CON_DEBUG, "\n"); #endif }else{ if (!rp) @@ -497,7 +500,7 @@ int ipx_ip_GetMyAddress(void) { u_int32_t myhandshakeid; d_srand( timer_get_approx_seconds() ); -// printf("set my id to %u\n",myhandshakeid); +// con_printf(CON_DEBUG, "set my id to %u\n",myhandshakeid); ip_my_addrs.clear(); @@ -527,9 +530,9 @@ int ipx_ip_GetMyAddress(void) { memcpy(ipx_MyAddress+6,&myhandshakeid,4); #ifdef UDPDEBUG - printf(MSGHDR "Using TCP/IP id "); + con_printf(CON_DEBUG, MSGHDR "Using TCP/IP id "); dumprid(ipx_MyAddress+4); - putchar('\n'); + con_printf(CON_DEBUG, "\n"); #endif return 0; } diff --git a/main/ip_base.h b/main/ip_base.h index d77f8e14..4ced6df8 100644 --- a/main/ip_base.h +++ b/main/ip_base.h @@ -1,13 +1,16 @@ /* * $Source: /cvs/cvsroot/d2x/main/ip_base.h,v $ - * $Revision: 1.3 $ + * $Revision: 1.4 $ * $Author: bradleyb $ - * $Date: 2002-02-14 09:24:19 $ + * $Date: 2002-02-15 06:41:42 $ * * ip_base.h - base for NAT-compatible udp/ip code. * added 2000/02/07 Matt Mueller * * $Log: not supported by cvs2svn $ + * Revision 1.3 2002/02/14 09:24:19 bradleyb + * d1x->d2x + * * Revision 1.2 2002/02/13 10:45:49 bradleyb * Lotsa networking stuff from d1x * @@ -20,6 +23,10 @@ #ifndef ___IP_BASE_H #define ___IP_BASE_H +#ifndef NDEBUG +#define UDPDEBUG +#endif + #include #include #include @@ -78,7 +85,8 @@ unsigned short ip_portshift(unsigned short baseport, const char *cs); */ #ifdef UDPDEBUG -#include +#include "console.h" + inline char *ip_hs_statetoa(int state){ if (!state) return "NOSTATE"; @@ -94,14 +102,14 @@ inline char *ip_hs_statetoa(int state){ } inline void dumprid(const unsigned char *a) { - printf("<%u.%u.%u.%u.%u.%u>",a[0],a[1],a[2],a[3],a[4],a[5]); + con_printf(CON_DEBUG, "<%u.%u.%u.%u.%u.%u>",a[0],a[1],a[2],a[3],a[4],a[5]); } inline void dumpraddr(const unsigned char *addr) { ushort port; - printf("[%u.%u.%u.%u]",addr[0],addr[1],addr[2],addr[3]); + con_printf(CON_DEBUG, "[%u.%u.%u.%u]",addr[0],addr[1],addr[2],addr[3]); port=(unsigned short)ntohs(*(unsigned short *)(addr+4)); - printf(":%d",port); + con_printf(CON_DEBUG, ":%d",port); } #endif diff --git a/main/ipclient.cpp b/main/ipclient.cpp index 60898393..861fa2d0 100644 --- a/main/ipclient.cpp +++ b/main/ipclient.cpp @@ -1,13 +1,16 @@ /* * $Source: /cvs/cvsroot/d2x/main/ipclient.cpp,v $ - * $Revision: 1.2 $ + * $Revision: 1.3 $ * $Author: bradleyb $ - * $Date: 2002-02-14 09:27:09 $ + * $Date: 2002-02-15 06:41:42 $ * * ipclient.cpp - udp/ip client code * added 2000/02/07 Matt Mueller * * $Log: not supported by cvs2svn $ + * Revision 1.2 2002/02/14 09:27:09 bradleyb + * d1x->d2x + * * Revision 1.1 2002/02/06 09:22:42 bradleyb * Adding d1x network code * @@ -50,9 +53,9 @@ int ip_connect_manual(char *textaddr) { return -1; } #ifdef UDPDEBUG - printf("connecting to "); + con_printf(CON_DEBUG, "connecting to "); addr.dump(); - printf("\n"); + con_printf(CON_DEBUG, "\n"); #endif network_init(); @@ -138,13 +141,13 @@ static int ipx_ip_SendPacket(IPXPacket_t *IPXHeader, memcpy(buf+2,data,dataLen); #ifdef UDPDEBUG - printf(MSGHDR "sendto((%d),Node=[4] %02X %02X,Socket=%02X %02X,s_port=%u,", + con_printf(CON_DEBUG, MSGHDR "sendto((%d),Node=[4] %02X %02X,Socket=%02X %02X,s_port=%u,", dataLen, IPXHeader->Destination.Node [4],IPXHeader->Destination.Node [5], IPXHeader->Destination.Socket[0],IPXHeader->Destination.Socket[1], ntohs(*(unsigned short *)(IPXHeader->Destination.Socket))); dumprid(IPXHeader->Destination.Node); - puts(")."); + con_printf(CON_DEBUG, ").\n"); #endif //toaddr.sin_family=AF_INET; @@ -232,10 +235,10 @@ static int ipx_ip_ReceivePacket(char *outbuf, int outbufsize, rd->pkt_type = 0; #ifdef UDPDEBUG - printf(MSGHDR "ReceivePacket: size=%d,from=",size); + con_printf(CON_DEBUG, MSGHDR "ReceivePacket: size=%d,from=",size); // dumpraddr(rd->src_node); fromaddr->dump(); - putchar('\n'); + con_printf(CON_DEBUG, "\n"); #endif /* ip_peer *p=peer_list.find_by_addr(*fromaddr); if(p) -- 2.39.2