mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 09:04:13 +00:00
Use NSByteOrder functions
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@6644 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
420a803031
commit
eb61fa59fd
3 changed files with 39 additions and 36 deletions
|
@ -14,6 +14,8 @@
|
|||
* Source/UdpPort.m: Likewise.
|
||||
* Tools/gdomap.c: Likewise.
|
||||
|
||||
* Source/NSBinaryCStream: Use NSByteOrder functions.
|
||||
* Source/UdpPort.m: Likewise.
|
||||
* Source/Invocation.m (initWithTarget:selector:): Use proper cast.
|
||||
* Source/NSFileManager.m (-isExecutableFileAtPath): Typo.
|
||||
* Source/NSPage.m (getpagesize): New function for WIN32
|
||||
|
|
|
@ -29,16 +29,11 @@
|
|||
#include <base/TextCStream.h>
|
||||
#include <Foundation/NSData.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSByteOrder.h>
|
||||
#include <math.h>
|
||||
#ifdef __WIN32__
|
||||
#include <winsock.h>
|
||||
#else /* __WIN32__ */
|
||||
#if HAVE_VALUES_H
|
||||
#include <values.h> // This gets BITSPERBYTE on Solaris
|
||||
#endif
|
||||
#include <sys/types.h>
|
||||
#include <netinet/in.h> // for byte-conversion
|
||||
#endif /* !__WIN32__ */
|
||||
|
||||
#define PRE_SIZEOF_PREFIX_FORMAT_VERSION 0
|
||||
#define CURRENT_FORMAT_VERSION ((((GNUSTEP_BASE_MAJOR_VERSION * 100) + \
|
||||
|
@ -315,7 +310,7 @@ static int debug_binary_coder = 0;
|
|||
{
|
||||
unsigned length = strlen (*(char**)d);
|
||||
unsigned nlength;
|
||||
nlength = htonl (length);
|
||||
nlength = NSSwapHostIntToBig (length);
|
||||
[stream writeBytes: &nlength
|
||||
length: NUM_BYTES_STRING_LENGTH];
|
||||
[stream writeBytes: *(char**)d
|
||||
|
@ -331,24 +326,24 @@ static int debug_binary_coder = 0;
|
|||
/* Reading and writing signed scalar types. */
|
||||
|
||||
case _C_SHT:
|
||||
WRITE_SIGNED_TYPE (d, short, htons);
|
||||
WRITE_SIGNED_TYPE (d, short, NSSwapHostShortToBig);
|
||||
break;
|
||||
case _C_USHT:
|
||||
WRITE_UNSIGNED_TYPE (d, short, htons);
|
||||
WRITE_UNSIGNED_TYPE (d, short, NSSwapHostShortToBig);
|
||||
break;
|
||||
|
||||
case _C_INT:
|
||||
WRITE_SIGNED_TYPE (d, int, htonl);
|
||||
WRITE_SIGNED_TYPE (d, int, NSSwapHostIntToBig);
|
||||
break;
|
||||
case _C_UINT:
|
||||
WRITE_UNSIGNED_TYPE (d, int, htonl);
|
||||
WRITE_UNSIGNED_TYPE (d, int, NSSwapHostIntToBig);
|
||||
break;
|
||||
|
||||
case _C_LNG:
|
||||
WRITE_SIGNED_TYPE (d, long, htonl);
|
||||
WRITE_SIGNED_TYPE (d, long, NSSwapHostLongToBig);
|
||||
break;
|
||||
case _C_ULNG:
|
||||
WRITE_UNSIGNED_TYPE (d, long, htonl);
|
||||
WRITE_UNSIGNED_TYPE (d, long, NSSwapHostLongToBig);
|
||||
break;
|
||||
|
||||
/* xxx The handling of floats and doubles could be improved.
|
||||
|
@ -373,8 +368,8 @@ static int debug_binary_coder = 0;
|
|||
NSAssert (value - mantissa == 0,
|
||||
@"mantissa and value should be the same");
|
||||
/* Encode the value as its two integer components. */
|
||||
WRITE_SIGNED_TYPE (&exponent_encoded, short, htons);
|
||||
WRITE_SIGNED_TYPE (&mantissa, int, htonl);
|
||||
WRITE_SIGNED_TYPE (&exponent_encoded, short, NSSwapHostShortToBig);
|
||||
WRITE_SIGNED_TYPE (&mantissa, int, NSSwapHostIntToBig);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -398,9 +393,9 @@ static int debug_binary_coder = 0;
|
|||
NSAssert (value - mantissa2 == 0,
|
||||
@"mantissa2 and value should be the same");
|
||||
/* Encode the value as its three integer components. */
|
||||
WRITE_SIGNED_TYPE (&exponent_encoded, short, htons);
|
||||
WRITE_SIGNED_TYPE (&mantissa1, int, htonl);
|
||||
WRITE_SIGNED_TYPE (&mantissa2, int, htonl);
|
||||
WRITE_SIGNED_TYPE (&exponent_encoded, short, NSSwapHostShortToBig);
|
||||
WRITE_SIGNED_TYPE (&mantissa1, int, NSSwapHostIntToBig);
|
||||
WRITE_SIGNED_TYPE (&mantissa2, int, NSSwapHostIntToBig);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -485,7 +480,7 @@ static int debug_binary_coder = 0;
|
|||
NSAssert2 (read_count == NUM_BYTES_STRING_LENGTH,
|
||||
@"expected %d bytes of input, got %d",
|
||||
NUM_BYTES_STRING_LENGTH,read_count);
|
||||
length = ntohl (length);
|
||||
length = NSSwapBigIntToHost (length);
|
||||
OBJC_MALLOC (*(char**)d, char, length+1);
|
||||
read_count = [stream readBytes: *(char**)d
|
||||
length: length];
|
||||
|
@ -504,24 +499,24 @@ static int debug_binary_coder = 0;
|
|||
break;
|
||||
|
||||
case _C_SHT:
|
||||
READ_SIGNED_TYPE (d, short, ntohs);
|
||||
READ_SIGNED_TYPE (d, short, NSSwapBigShortToHost);
|
||||
break;
|
||||
case _C_USHT:
|
||||
READ_UNSIGNED_TYPE (d, short, ntohs);
|
||||
READ_UNSIGNED_TYPE (d, short, NSSwapBigShortToHost);
|
||||
break;
|
||||
|
||||
case _C_INT:
|
||||
READ_SIGNED_TYPE (d, int, ntohl);
|
||||
READ_SIGNED_TYPE (d, int, NSSwapBigIntToHost);
|
||||
break;
|
||||
case _C_UINT:
|
||||
READ_UNSIGNED_TYPE (d, int, ntohl);
|
||||
READ_UNSIGNED_TYPE (d, int, NSSwapBigIntToHost);
|
||||
break;
|
||||
|
||||
case _C_LNG:
|
||||
READ_SIGNED_TYPE (d, long, ntohl);
|
||||
READ_SIGNED_TYPE (d, long, NSSwapBigLongToHost);
|
||||
break;
|
||||
case _C_ULNG:
|
||||
READ_UNSIGNED_TYPE (d, long, ntohl);
|
||||
READ_UNSIGNED_TYPE (d, long, NSSwapBigLongToHost);
|
||||
break;
|
||||
|
||||
case _C_FLT:
|
||||
|
@ -532,8 +527,8 @@ static int debug_binary_coder = 0;
|
|||
float fvalue;
|
||||
|
||||
/* Decode the exponent and mantissa. */
|
||||
READ_SIGNED_TYPE (&exponent, short, ntohs);
|
||||
READ_SIGNED_TYPE (&mantissa, int, ntohl);
|
||||
READ_SIGNED_TYPE (&exponent, short, NSSwapBigShortToHost);
|
||||
READ_SIGNED_TYPE (&mantissa, int, NSSwapBigIntToHost);
|
||||
/* Assemble them into a double */
|
||||
value = mantissa / FLOAT_FACTOR;
|
||||
value = ldexp (value, exponent);
|
||||
|
@ -550,9 +545,9 @@ static int debug_binary_coder = 0;
|
|||
double value;
|
||||
|
||||
/* Decode the exponent and the two pieces of the mantissa. */
|
||||
READ_SIGNED_TYPE (&exponent, short, ntohs);
|
||||
READ_SIGNED_TYPE (&mantissa1, int, ntohl);
|
||||
READ_SIGNED_TYPE (&mantissa2, int, ntohl);
|
||||
READ_SIGNED_TYPE (&exponent, short, NSSwapBigShortToHost);
|
||||
READ_SIGNED_TYPE (&mantissa1, int, NSSwapBigIntToHost);
|
||||
READ_SIGNED_TYPE (&mantissa2, int, NSSwapBigIntToHost);
|
||||
/* Assemble them into a double */
|
||||
value = ((mantissa2 / FLOAT_FACTOR) + mantissa1) / FLOAT_FACTOR;
|
||||
value = ldexp (value, exponent);
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include <Foundation/NSLock.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSHost.h>
|
||||
#include <Foundation/NSByteOrder.h>
|
||||
|
||||
#if _AIX
|
||||
#include <sys/select.h>
|
||||
|
@ -141,7 +142,7 @@ static NSMapTable *port_number_2_in_port = NULL;
|
|||
our unique host address that can identify us across the network. */
|
||||
memcpy (&(p->_address.sin_addr), hp->h_addr, hp->h_length);
|
||||
p->_address.sin_family = AF_INET;
|
||||
p->_address.sin_port = htons (n);
|
||||
p->_address.sin_port = NSSwapHostShortToBig (n);
|
||||
/* N may be zero, in which case bind() will choose a port number
|
||||
for us. */
|
||||
if (bind (p->_port_socket,
|
||||
|
@ -177,7 +178,7 @@ static NSMapTable *port_number_2_in_port = NULL;
|
|||
|
||||
if (udp_port_debug)
|
||||
fprintf(stderr, "created new UdpInPort 0x%x, fd=%d port_number=%d\n",
|
||||
(unsigned)p, p->_port_socket, htons(p->_address.sin_port));
|
||||
(unsigned)p, p->_port_socket, NSSwapHostShortToBig(p->_address.sin_port));
|
||||
|
||||
return p;
|
||||
}
|
||||
|
@ -261,6 +262,11 @@ static NSMapTable *port_number_2_in_port = NULL;
|
|||
{
|
||||
if (_is_valid)
|
||||
{
|
||||
#if defined(__WIN32__)
|
||||
closesocket (_port_socket);
|
||||
#else
|
||||
close (_port_socket);
|
||||
#endif /* __WIN32__ */
|
||||
close (_port_socket);
|
||||
[super invalidate];
|
||||
}
|
||||
|
@ -279,7 +285,7 @@ static NSMapTable *port_number_2_in_port = NULL;
|
|||
|
||||
- (int) portNumber
|
||||
{
|
||||
return (int) ntohs (_address.sin_port);
|
||||
return (int) NSSwapBigShortToHost (_address.sin_port);
|
||||
}
|
||||
|
||||
- (Class) packetClass
|
||||
|
@ -401,7 +407,7 @@ static Array *udp_out_port_array;
|
|||
/* Get the sockaddr_in address. */
|
||||
memcpy (&addr.sin_addr, hp->h_addr, hp->h_length);
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons (n);
|
||||
addr.sin_port = NSSwapHostShortToBig (n);
|
||||
|
||||
return [self newForSendingToSockaddr: &addr];
|
||||
}
|
||||
|
@ -419,7 +425,7 @@ static Array *udp_out_port_array;
|
|||
if ( ! [reply_port isKindOfClass: [UdpInPort class]])
|
||||
[self error:"Trying to send to a port that is not a UdpInPort"];
|
||||
if (udp_port_debug)
|
||||
fprintf (stderr, "sending to %d\n", (int) ntohs (_address.sin_port));
|
||||
fprintf (stderr, "sending to %d\n", (int) NSSwapBigShortToHost (_address.sin_port));
|
||||
if (sendto ([reply_port socket],
|
||||
[packet streamBuffer], len, 0,
|
||||
(struct sockaddr*)&_address, sizeof (_address))
|
||||
|
@ -433,7 +439,7 @@ static Array *udp_out_port_array;
|
|||
|
||||
- (int) portNumber
|
||||
{
|
||||
return (int) ntohs (_address.sin_port);
|
||||
return (int) NSSwapBigShortToHost (_address.sin_port);
|
||||
}
|
||||
|
||||
- (NSString*) hostname
|
||||
|
|
Loading…
Reference in a new issue