Modifications to fix some networking/endian issues on PPC OSX.

* added sockaddr_clear() function to zero network addresses before use.
* used this function in p3connmgr.
* added htonll() and ntohll() functions to rsnet.h with compile-time ENDIAN checking
* use htonll() and ntohll() in serialiser.
* added net_test.cc to check network/endian/inet_addr issues.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@328 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2008-02-03 12:07:59 +00:00
parent cea158b77d
commit 31136da7cc
10 changed files with 374 additions and 40 deletions

View file

@ -7,7 +7,7 @@ RS_TOP_DIR = ..
include $(RS_TOP_DIR)/scripts/config.mk
###############################################################
RSOBJ = rsthreads.o rsdir.o rsprint.o
RSOBJ = rsthreads.o rsdir.o rsprint.o rsnet.o
TESTOBJ = dirtest.o dir2test.o

View file

@ -0,0 +1,55 @@
/*
* libretroshare/src/util: rsnet.cc
*
* Universal Networking Header for RetroShare.
*
* Copyright 2007-2008 by Robert Fernie.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
#include "util/rsnet.h"
uint64_t ntohll(uint64_t x)
{
#ifdef BYTE_ORDER
#if BYTE_ORDER == BIG_ENDIAN
return x;
#elif BYTE_ORDER == LITTLE_ENDIAN
uint32_t top = (uint32_t) (x >> 32);
uint32_t bot = (uint32_t) (0x00000000ffffffffULL & x);
uint64_t rev = ((uint64_t) ntohl(top)) | (((uint64_t) ntohl(bot)) << 32);
return rev;
#else
#error "ENDIAN determination Failed"
#endif
#else
#error "ENDIAN determination Failed (BYTE_ORDER not defined)"
#endif
}
uint64_t htonll(uint64_t x)
{
return ntohll(x);
}

View file

@ -51,4 +51,8 @@ typedef uint32_t in_addr_t;
#endif
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
/* 64 bit conversions */
uint64_t ntohll(uint64_t x);
uint64_t htonll(uint64_t x);
#endif /* RS_UNIVERSAL_NETWORK_HEADER */