Fixed net_bind() for specified IP addresses on little endian systems

This commit is contained in:
Paul Bakker 2013-03-06 16:55:11 +01:00
parent 926c8e49fe
commit 37286a573b
2 changed files with 13 additions and 4 deletions

View File

@ -6,6 +6,7 @@ Bugfix
* Corrected GCM counter incrementation to use only 32-bits instead of
128-bits (found by Yawning Angel)
* Fixes for 64-bit compilation with MS Visual Studio
* Fixed net_bind() for specified IP addresses on little endian systems
Changes
* Internally split up rsa_pkcs1_encrypt(), rsa_pkcs1_decrypt(),

View File

@ -90,12 +90,20 @@ typedef UINT32 uint32_t;
*/
#if defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && __BYTE_ORDER == __BIG_ENDIAN
#define POLARSSL_HTONS(n) (n)
#define POLARSSL_HTONL(n) (n)
#else
#define POLARSSL_HTONS(n) (((((unsigned short)(n) & 0xFF)) << 8) | (((unsigned short)(n) & 0xFF00) >> 8))
#define POLARSSL_HTONS(n) ((((unsigned short)(n) & 0xFF ) << 8 ) | \
(((unsigned short)(n) & 0xFF00 ) >> 8 ))
#define POLARSSL_HTONL(n) ((((unsigned long )(n) & 0xFF ) << 24) | \
(((unsigned long )(n) & 0xFF00 ) << 8 ) | \
(((unsigned long )(n) & 0xFF0000 ) >> 8 ) | \
(((unsigned long )(n) & 0xFF000000) >> 24))
#endif
unsigned short net_htons(unsigned short n);
unsigned long net_htonl(unsigned long n);
#define net_htons(n) POLARSSL_HTONS(n)
#define net_htonl(n) POLARSSL_HTONL(n)
/*
* Initiate a TCP connection with host:port
@ -171,7 +179,7 @@ int net_bind( int *fd, const char *bind_ip, int port )
setsockopt( *fd, SOL_SOCKET, SO_REUSEADDR,
(const char *) &n, sizeof( n ) );
server_addr.sin_addr.s_addr = INADDR_ANY;
server_addr.sin_addr.s_addr = net_htonl( INADDR_ANY );
server_addr.sin_family = AF_INET;
server_addr.sin_port = net_htons( port );
@ -185,11 +193,11 @@ int net_bind( int *fd, const char *bind_ip, int port )
break;
if( n == 4 )
server_addr.sin_addr.s_addr =
server_addr.sin_addr.s_addr = net_htonl(
( (uint32_t) c[0] << 24 ) |
( (uint32_t) c[1] << 16 ) |
( (uint32_t) c[2] << 8 ) |
( (uint32_t) c[3] );
( (uint32_t) c[3] ) );
}
if( bind( *fd, (struct sockaddr *) &server_addr,