mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-01-29 12:32:48 +00:00
- Made net_htons() endian-clean for big endian.
This commit is contained in:
parent
2b245ebd9f
commit
1d4f30ca4d
@ -14,6 +14,8 @@ PolarSSL ChangeLog
|
|||||||
Olsson).
|
Olsson).
|
||||||
* Centralized file opening and reading for x509 files into
|
* Centralized file opening and reading for x509 files into
|
||||||
load_file()
|
load_file()
|
||||||
|
* Made definition of net_htons() endian-clean for big endian
|
||||||
|
systems (Found by Gernot).
|
||||||
|
|
||||||
= Version 0.10.0 released on 2009-01-12
|
= Version 0.10.0 released on 2009-01-12
|
||||||
* Migrated XySSL to PolarSSL
|
* Migrated XySSL to PolarSSL
|
||||||
|
@ -55,6 +55,7 @@ static int wsa_init_done = 0;
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <endian.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -64,18 +65,18 @@ static int wsa_init_done = 0;
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* htons() is not always available
|
* htons() is not always available.
|
||||||
|
* By default go for LITTLE_ENDIAN variant. Otherwise hope for _BYTE_ORDER and __BIG_ENDIAN
|
||||||
|
* to help determine endianess.
|
||||||
*/
|
*/
|
||||||
static unsigned short net_htons( int port )
|
#if defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && __BYTE_ORDER == __BIG_ENDIAN
|
||||||
{
|
#define HTONS(n) (n)
|
||||||
unsigned char buf[4];
|
#else
|
||||||
|
#define HTONS(n) (((((unsigned short)(n) & 0xFF)) << 8) | (((unsigned short)(n) & 0xFF00) >> 8))
|
||||||
|
#endif
|
||||||
|
|
||||||
buf[0] = (unsigned char)( port >> 8 );
|
unsigned short net_htons(unsigned short n);
|
||||||
buf[1] = (unsigned char)( port );
|
#define net_htons(n) HTONS(n)
|
||||||
buf[2] = buf[3] = 0;
|
|
||||||
|
|
||||||
return( *(unsigned short *) buf );
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initiate a TCP connection with host:port
|
* Initiate a TCP connection with host:port
|
||||||
|
Loading…
x
Reference in New Issue
Block a user