extended bio_reader and bio_writer to handle u_int64_t
This commit is contained in:
@@ -482,6 +482,27 @@ static inline void htoun32(void *network, u_int32_t host)
|
||||
memcpy((char*)unaligned, &host, sizeof(host));
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a 64-bit host order value in network order to an unaligned address.
|
||||
*
|
||||
* @param host host order 32-bit value
|
||||
* @param network unaligned address to write network order value to
|
||||
*/
|
||||
static inline void htoun64(void *network, u_int64_t host)
|
||||
{
|
||||
char *unaligned = (char*)network;
|
||||
u_int32_t high_part, low_part;
|
||||
|
||||
high_part = host >> 32;
|
||||
high_part = htonl(high_part);
|
||||
low_part = host & 0xFFFFFFFFLL;
|
||||
low_part = htonl(low_part);
|
||||
|
||||
memcpy(unaligned, &high_part, sizeof(high_part));
|
||||
unaligned += sizeof(high_part);
|
||||
memcpy(unaligned, &low_part, sizeof(low_part));
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a 16-bit value in network order from an unaligned address to host order.
|
||||
*
|
||||
@@ -512,6 +533,27 @@ static inline u_int32_t untoh32(void *network)
|
||||
return ntohl(tmp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a 64-bit value in network order from an unaligned address to host order.
|
||||
*
|
||||
* @param network unaligned address to read network order value from
|
||||
* @return host order value
|
||||
*/
|
||||
static inline u_int64_t untoh64(void *network)
|
||||
{
|
||||
char *unaligned = (char*)network;
|
||||
u_int32_t high_part, low_part;
|
||||
|
||||
memcpy(&high_part, unaligned, sizeof(high_part));
|
||||
unaligned += sizeof(high_part);
|
||||
memcpy(&low_part, unaligned, sizeof(low_part));
|
||||
|
||||
high_part = ntohl(high_part);
|
||||
low_part = ntohl(low_part);
|
||||
|
||||
return (((u_int64_t)high_part) << 32) + low_part;
|
||||
}
|
||||
|
||||
/**
|
||||
* Special type to count references
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user