mirror of
https://github.com/transmission/transmission
synced 2025-03-03 10:15:45 +00:00
remove the TR_HTONL macro
This commit is contained in:
parent
6d21f2fb16
commit
05d88f2c48
4 changed files with 28 additions and 30 deletions
|
@ -85,22 +85,6 @@ int vasprintf( char **, const char *, va_list );
|
|||
}
|
||||
#endif
|
||||
|
||||
/* Convenient macros to perform uint32_t endian conversions with
|
||||
char pointers */
|
||||
#define TR_HTONL(a,p) tr_htonl((a), ( uint8_t * )(p))
|
||||
static inline uint32_t tr_ntohl( uint8_t * p )
|
||||
{
|
||||
uint32_t u;
|
||||
memcpy( &u, p, sizeof( uint32_t ) );
|
||||
return ntohl( u );
|
||||
}
|
||||
static inline void tr_htonl( uint32_t a, uint8_t * p )
|
||||
{
|
||||
uint32_t u;
|
||||
u = htonl( a );
|
||||
memcpy ( p, &u, sizeof( uint32_t ) );
|
||||
}
|
||||
|
||||
/* Sometimes the system defines MAX/MIN, sometimes not. In the latter
|
||||
case, define those here since we will use them */
|
||||
#ifndef MAX
|
||||
|
|
|
@ -226,6 +226,20 @@ static void __peer_dbg( tr_peer_t * peer, char * msg, ... )
|
|||
tr_dbg( "%s", string );
|
||||
}
|
||||
|
||||
/* utilities for endian conversions with char pointers */
|
||||
|
||||
static uint32_t tr_ntohl( const void * p )
|
||||
{
|
||||
uint32_t u;
|
||||
memcpy( &u, p, sizeof( uint32_t ) );
|
||||
return ntohl( u );
|
||||
}
|
||||
static void tr_htonl( uint32_t a, void * p )
|
||||
{
|
||||
const uint32_t u = htonl( a );
|
||||
memcpy ( p, &u, sizeof( uint32_t ) );
|
||||
}
|
||||
|
||||
#include "peerext.h"
|
||||
#include "peeraz.h"
|
||||
#include "peermessages.h"
|
||||
|
|
|
@ -114,9 +114,9 @@ makeAZHandshake( tr_torrent_t * tor, tr_peer_t * peer, int * buflen )
|
|||
}
|
||||
|
||||
/* set length to zero for now, we won't know it until after bencoding */
|
||||
TR_HTONL( 0, buf );
|
||||
tr_htonl( 0, buf );
|
||||
/* set name length, name, and version */
|
||||
TR_HTONL( azmsgLen( idx ), buf + 4 );
|
||||
tr_htonl( azmsgLen( idx ), buf + 4 );
|
||||
memcpy( buf + 8, azmsgStr( idx ), azmsgLen( idx ) );
|
||||
buf[8 + azmsgLen( idx )] = AZ_EXT_VERSION;
|
||||
|
||||
|
@ -187,7 +187,7 @@ makeAZHandshake( tr_torrent_t * tor, tr_peer_t * peer, int * buflen )
|
|||
|
||||
tr_bencFree( &val );
|
||||
/* we know the length now, fill it in */
|
||||
TR_HTONL( len - 4, buf );
|
||||
tr_htonl( len - 4, buf );
|
||||
|
||||
/* XXX is there a way to tell azureus that the public port has changed? */
|
||||
peer->advertisedPort = tor->publicPort;
|
||||
|
|
|
@ -81,13 +81,13 @@ fillHeader( tr_peer_t * peer, int size, int id, uint8_t * buf )
|
|||
{
|
||||
int index;
|
||||
|
||||
TR_HTONL( size - 4, buf );
|
||||
tr_htonl( size - 4, buf );
|
||||
buf += 4;
|
||||
if( peer->azproto )
|
||||
{
|
||||
index = azmsgIdIndex( id );
|
||||
assert( 0 <= index );
|
||||
TR_HTONL( azmsgLen( index ), buf );
|
||||
tr_htonl( azmsgLen( index ), buf );
|
||||
buf += 4;
|
||||
memcpy( buf, azmsgStr( index ), azmsgLen( index ) );
|
||||
buf += azmsgLen( index );
|
||||
|
@ -138,9 +138,9 @@ blockPending( tr_torrent_t * tor,
|
|||
assert( hdrlen <= ( signed )sizeof peer->outBlock );
|
||||
buf = fillHeader( peer, hdrlen, PEER_MSG_PIECE, peer->outBlock );
|
||||
|
||||
TR_HTONL( r->index, buf );
|
||||
tr_htonl( r->index, buf );
|
||||
buf += 4;
|
||||
TR_HTONL( r->begin, buf );
|
||||
tr_htonl( r->begin, buf );
|
||||
buf += 4;
|
||||
|
||||
tr_ioRead( tor->io, r->index, r->begin, r->length, buf );
|
||||
|
@ -261,7 +261,7 @@ static void sendHave( tr_peer_t * peer, int piece )
|
|||
|
||||
p = getMessagePointer( peer, 4, PEER_MSG_HAVE );
|
||||
|
||||
TR_HTONL( piece, p );
|
||||
tr_htonl( piece, p );
|
||||
|
||||
peer_dbg( "SEND have %d", piece );
|
||||
}
|
||||
|
@ -310,9 +310,9 @@ static void sendRequest( tr_torrent_t * tor, tr_peer_t * peer, int block )
|
|||
/* Build the "ask" message */
|
||||
p = getMessagePointer( peer, 12, PEER_MSG_REQUEST );
|
||||
|
||||
TR_HTONL( r->index, p );
|
||||
TR_HTONL( r->begin, p + 4 );
|
||||
TR_HTONL( r->length, p + 8 );
|
||||
tr_htonl( r->index, p );
|
||||
tr_htonl( r->begin, p + 4 );
|
||||
tr_htonl( r->length, p + 8 );
|
||||
|
||||
tr_cpDownloaderAdd( tor->completion, block );
|
||||
|
||||
|
@ -331,9 +331,9 @@ static void sendCancel( tr_peer_t * peer, int index, int begin,
|
|||
uint8_t * p;
|
||||
p = getMessagePointer( peer, 12, PEER_MSG_CANCEL );
|
||||
|
||||
TR_HTONL( index, p );
|
||||
TR_HTONL( begin, p + 4 );
|
||||
TR_HTONL( length, p + 8 );
|
||||
tr_htonl( index, p );
|
||||
tr_htonl( begin, p + 4 );
|
||||
tr_htonl( length, p + 8 );
|
||||
|
||||
peer_dbg( "SEND cancel %d/%d (%d bytes)", index, begin, length );
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue