mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-11-18 10:08:29 +01:00
keep hostname as well as IP address in CommsAddrRec
This commit is contained in:
parent
fa7dcd1217
commit
49e4c1f6e4
2 changed files with 31 additions and 11 deletions
|
@ -32,6 +32,8 @@
|
|||
|
||||
#ifndef XWFEATURE_STANDALONE_ONLY
|
||||
|
||||
EXTERN_C_START
|
||||
|
||||
typedef struct MsgQueueElem {
|
||||
struct MsgQueueElem* next;
|
||||
XP_U8* msg;
|
||||
|
@ -113,10 +115,14 @@ comms_make( MPFORMAL XW_UtilCtxt* util, XP_Bool isServer,
|
|||
|
||||
#ifdef BEYOND_IR
|
||||
/* default values; default is still IR where there's a choice */
|
||||
result->addr.conType = COMMS_CONN_IR;
|
||||
result->addr.conType = COMMS_CONN_IP;
|
||||
result->addr.u.ip.ipAddr = 0L; /* force 'em to set it */
|
||||
result->addr.u.ip.port = 6000;
|
||||
result->listenPort = 6001;
|
||||
{
|
||||
char* name = "aphraea.org";
|
||||
XP_MEMCPY( result->addr.u.ip.hostName, name, XP_STRLEN(name) );
|
||||
}
|
||||
#endif
|
||||
|
||||
return result;
|
||||
|
@ -129,9 +135,9 @@ cleanupInternal( CommsCtxt* comms )
|
|||
MsgQueueElem* next;
|
||||
|
||||
for ( msg = comms->msgQueueHead; !!msg; msg = next ) {
|
||||
next = msg->next;
|
||||
XP_FREE( comms->mpool, msg->msg );
|
||||
XP_FREE( comms->mpool, msg );
|
||||
next = msg->next;
|
||||
XP_FREE( comms->mpool, msg->msg );
|
||||
XP_FREE( comms->mpool, msg );
|
||||
}
|
||||
comms->queueLen = 0;
|
||||
comms->msgQueueHead = comms->msgQueueTail = (MsgQueueElem*)NULL;
|
||||
|
@ -188,7 +194,7 @@ comms_makeFromStream( MPFORMAL XWStreamCtxt* stream, XW_UtilCtxt* util,
|
|||
XP_U16 nAddrRecs;
|
||||
AddressRecord** prevsAddrNext;
|
||||
MsgQueueElem** prevsQueueNext;
|
||||
short i;
|
||||
short i, len;
|
||||
|
||||
isServer = stream_getU8( stream );
|
||||
comms = comms_make( MPPARM(mpool) util, isServer, sendproc, closure );
|
||||
|
@ -261,6 +267,10 @@ comms_makeFromStream( MPFORMAL XWStreamCtxt* stream, XW_UtilCtxt* util,
|
|||
comms->addr.u.ip.ipAddr = stream_getU32( stream );
|
||||
comms->addr.u.ip.port = stream_getU16( stream );
|
||||
comms->listenPort = stream_getU16( stream );
|
||||
len = stream_getU8( stream );
|
||||
stream_getBytes( stream, comms->addr.u.ip.hostName, len );
|
||||
comms->addr.u.ip.hostName[len] = '\0';
|
||||
|
||||
/* tell client about the port */
|
||||
util_listenPortChange( util, comms->listenPort );
|
||||
#endif
|
||||
|
@ -274,7 +284,7 @@ comms_makeFromStream( MPFORMAL XWStreamCtxt* stream, XW_UtilCtxt* util,
|
|||
void
|
||||
comms_writeToStream( CommsCtxt* comms, XWStreamCtxt* stream )
|
||||
{
|
||||
XP_U16 nAddrRecs;
|
||||
XP_U16 nAddrRecs, len;
|
||||
AddressRecord* rec;
|
||||
MsgQueueElem* msg;
|
||||
|
||||
|
@ -321,6 +331,9 @@ comms_writeToStream( CommsCtxt* comms, XWStreamCtxt* stream )
|
|||
stream_putU32( stream, comms->addr.u.ip.ipAddr );
|
||||
stream_putU16( stream, comms->addr.u.ip.port );
|
||||
stream_putU16( stream, comms->listenPort );
|
||||
len = XP_STRLEN( comms->addr.u.ip.hostName );
|
||||
stream_putU8( stream, len );
|
||||
stream_putBytes( stream, comms->addr.u.ip.hostName, len );
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
|
@ -744,4 +757,6 @@ countAddrRecs( CommsCtxt* comms )
|
|||
return count;
|
||||
} /* countAddrRecs */
|
||||
|
||||
EXTERN_C_END
|
||||
|
||||
#endif /* #ifndef XWFEATURE_STANDALONE_ONLY */
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
#include "comtypes.h"
|
||||
#include "mempool.h"
|
||||
|
||||
EXTERN_C_START
|
||||
|
||||
#define CHANNEL_NONE ((XP_PlayerAddr)0)
|
||||
#define CONN_ID_NONE 0L
|
||||
|
||||
|
@ -30,21 +32,22 @@ typedef XP_U32 MsgID;
|
|||
|
||||
typedef enum {
|
||||
COMMS_CONN_UNUSED, /* I want errors on uninited case */
|
||||
COMMS_CONN_IR,
|
||||
COMMS_CONN_IP,
|
||||
COMMS_CONN_BT,
|
||||
COMMS_CONN_IR,
|
||||
|
||||
LAST_____FOO
|
||||
} CommsConnType;
|
||||
|
||||
|
||||
#define MAX_HOSTNAME_LEN 63
|
||||
typedef struct CommsAddrRec {
|
||||
CommsConnType conType;
|
||||
|
||||
union {
|
||||
struct {
|
||||
|
||||
XP_U32 ipAddr;
|
||||
XP_U16 port; /* return port, not sent-from */
|
||||
XP_UCHAR hostName[MAX_HOSTNAME_LEN + 1];
|
||||
XP_U32 ipAddr; /* looked up from above */
|
||||
XP_U16 port;
|
||||
} ip;
|
||||
struct {
|
||||
/* nothing? */
|
||||
|
@ -90,4 +93,6 @@ XP_Bool comms_checkIncommingStream( CommsCtxt* comms, XWStreamCtxt* stream,
|
|||
void comms_getStats( CommsCtxt* comms, XWStreamCtxt* stream );
|
||||
# endif
|
||||
|
||||
EXTERN_C_END
|
||||
|
||||
#endif /* _COMMS_H_ */
|
||||
|
|
Loading…
Reference in a new issue