Byte Order 1
-
Upload
nivi-senthil -
Category
Documents
-
view
219 -
download
0
Transcript of Byte Order 1
-
7/27/2019 Byte Order 1
1/10
#include
Datatype Description
int8_t
uint8_t
int16_t
uint16_t
int32_t
uint32_t
Signed 8-bit integer
Unsigned 8-bit integer
Signed 16-bit integer
Unsigned 16-bit integer
Signed 32-bit integer
Unsigned 32-bit integer
sa_family_t
socklen_t
Address family of socket address structure
Length of socket address structure, normally
uint32_t
in_addr_t
in_port_t
IPv4 address, normally uint32_t
TCP or UDP port, normally uint16_t
-
7/27/2019 Byte Order 1
2/10
Byte Ordering
16-bit integer is made up of 2 bytes. 2 ways
to store the bytes in memory
Little-endian byte order: low order byte at
the beginning address
Big-endian byte order: high-order byte at
the starting address
-
7/27/2019 Byte Order 1
3/10
Network byte order and host byte
order TCP/IP specifies a standard representation
for binary integers used in protocol headers
called Network byte order that representsintegers with the most significant byte first
We refer to the byte ordering used by given
system as the host byte order
-
7/27/2019 Byte Order 1
4/10
Byte-ordering functions
Following function converts integers
htons--from host to network byte order short
unit16_t htons(unit16_t value); ntohs--from network to host byte order short
unit16_t ntohs(unit16_t value);
htonlfrom host to network byte order long
unit32_t htonl(unit32_t value);
ntohs--from network to host byte order longunit32_t ntohl(unit32_t value);
-
7/27/2019 Byte Order 1
5/10
bzero function
Syntax
void bzero( void *dest, size_t nbytes);
It is provided by most the system to set nbytes ofmemory pointed by dest as 0.
Example
bzero( &servaddr, sizeof(servaddr)); Will set servaddr ( server address struct) as 0
-
7/27/2019 Byte Order 1
6/10
Group of address conversion
functionsint inet_aton( const char *strptr, struct in_addr *addrptr);
Returns; 1 if string was valid, 0 on error
convert from ASCII string to network byte order binaryvalues
char * inet_ntoa( struct inaddr inaddr);
Return: pointer to dotted-decimal string
Convert from network byte order binary value to dotteddecimal string
These two functions convert IPv4 address
-
7/27/2019 Byte Order 1
7/10
int inet_pton( int family, constchar* strptr, void *addrptr);
Function will convert IP address in string(strptr) to the numeric value as in address
struct( addptr).
Return 1 if OK, return1 on error
-
7/27/2019 Byte Order 1
8/10
Const char *inet_ntop(int family,const void *addptr, char *strptr,size_t len);
return pointer if K, NULL on error
Does the reverse conversion, from numeric(addptr) to presentation (strptr). The len is
the size of the destination, to prevent thefunction from overflowing the callersbuffer.
-
7/27/2019 Byte Order 1
9/10
-
7/27/2019 Byte Order 1
10/10