142 lines
4.7 KiB
C
142 lines
4.7 KiB
C
/********************************************************************************/
|
|
/* */
|
|
/* NetEnd.c */
|
|
/* */
|
|
/* This file deals with the different memory architecture */
|
|
/* */
|
|
/********************************************************************************/
|
|
|
|
|
|
#include "warnings.h"
|
|
#include "netend.h"
|
|
|
|
/*for little/big-endian*/
|
|
static NetLib_tducBigLittleEndian gs_ucLocalBigEndian;
|
|
|
|
/*
|
|
------------------------------------------------------------------------------------------
|
|
LITTLE/BIG ENDIAN
|
|
------------------------------------------------------------------------------------------
|
|
*/
|
|
|
|
/*
|
|
|
|
Little endian :
|
|
bits: [ 7 6 5 4 3 2 1 0 ] Byte 0 < Pointer
|
|
bits: [ 15 14 13 12 11 10 9 8 ] Byte 1
|
|
bits: [ 23 22 21 20 19 18 17 16 ] Byte 2
|
|
bits: [ 31 30 29 28 27 26 25 24 ] Byte 3
|
|
|
|
Big endian :
|
|
bits: [ 31 30 29 28 27 26 25 24 ] Byte 0 < Pointer
|
|
bits: [ 23 22 21 20 19 18 17 16 ] Byte 1
|
|
bits: [ 15 14 13 12 11 10 9 8 ] Byte 2
|
|
bits: [ 7 6 5 4 3 2 1 0 ] Byte 3
|
|
*/
|
|
|
|
/*
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
Description : NetLib_eSetLittleBigEndian
|
|
Sets the little/big endian
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
Input :
|
|
An unsigned char
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
Output :
|
|
NetLib_E_es_NoError if no error occured
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
Date : October 22, 1996
|
|
Author : Albert Pais
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
*/
|
|
NetLib_tdeErrorStatus _NET_CALLING_CONV_ NetLib_eSetLittleBigEndian(NetLib_tducBigLittleEndian ucNewEndian)
|
|
{
|
|
gs_ucLocalBigEndian=ucNewEndian;
|
|
return NetLib_E_es_NoError;
|
|
}
|
|
|
|
/*
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
Description : ucL0GetLittleBigEndian
|
|
Gets the littel/big endian
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
Input :
|
|
None
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
Output :
|
|
An unsigned char
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
Date : October 22, 1996
|
|
Author : Albert Pais
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
*/
|
|
NetLib_tducBigLittleEndian _NET_CALLING_CONV_ NetLib_ucGetLittleBigEndian(void)
|
|
{
|
|
return gs_ucLocalBigEndian;
|
|
}
|
|
|
|
/*
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
Description : eL0ProcessLittleBigEndian
|
|
Process the littel/big endian
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
Input :
|
|
Nonr
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
Output :
|
|
NetLib_E_es_NoError if no error occured
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
Date : October 22, 1996
|
|
Author : Albert Pais
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
*/
|
|
NetLib_tdeErrorStatus NetLib_eProcessLittleBigEndian(void)
|
|
{
|
|
union
|
|
{
|
|
short m_wValue;
|
|
char m_cIsLittleEndian;
|
|
} uLittleBigEndian;
|
|
|
|
uLittleBigEndian.m_wValue = 1;
|
|
|
|
if(uLittleBigEndian.m_cIsLittleEndian)
|
|
NetLib_eSetLittleBigEndian(0);
|
|
else
|
|
NetLib_eSetLittleBigEndian(1);
|
|
|
|
return NetLib_E_es_NoError;
|
|
}
|
|
|
|
/*
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
Description : NetLib_eSwapLittleBigEndianMsgHeader
|
|
Converts a msg header from little/big endian to the reverse
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
Input :
|
|
a pointer to a tdstNetMessage
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
Output :
|
|
A NetLib_tdeErrorStatus
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
Date : October 23, 1996
|
|
Author : Albert Pais
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
Comment :
|
|
Msg Header :
|
|
NetLib_tduxSessionId ulSessionId;-> Nothing to do
|
|
NetLib_tduxPlayerId ulSenderId;-> Nothing to do
|
|
NetLib_tduxPlayerId ulRecipientId;-> Nothing to do
|
|
unsigned long ulMessageSizeInBytes;-> Swap
|
|
unsigned long ulReserved;-> Swap
|
|
NetLib_uxReadReceiptId m_ulReadReceiptId;-> Nothing to do
|
|
NetLib_tduwPriority m_uwReceivingPriority;-> Nothing to do
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
*/
|
|
NetLib_tdeErrorStatus NetLib_eSwapLittleBigEndianMsgHeader(tdstNetMessage*p_stMsg)
|
|
{
|
|
p_stMsg->uwMessageSizeInBytes=M_NET_uwSwapLittleBigEndian(p_stMsg->uwMessageSizeInBytes);
|
|
p_stMsg->ulReserved = M_NET_ulSwapLittleBigEndian(p_stMsg->ulReserved);
|
|
return NetLib_E_es_NoError;
|
|
}
|