mirror of
https://github.com/riba2534/TCP-IP-NetworkNote.git
synced 2026-02-02 17:48:55 +08:00
20 lines
547 B
C
20 lines
547 B
C
#include <stdio.h>
|
|
#include <arpa/inet.h>
|
|
int main(int argc, char *argv[])
|
|
{
|
|
unsigned short host_port = 0x1234;
|
|
unsigned short net_port;
|
|
unsigned long host_addr = 0x12345678;
|
|
unsigned long net_addr;
|
|
|
|
net_port = htons(host_port); //转换为网络字节序
|
|
net_addr = htonl(host_addr);
|
|
|
|
printf("Host ordered port: %#x \n", host_port);
|
|
printf("Network ordered port: %#x \n", net_port);
|
|
printf("Host ordered address: %#lx \n", host_addr);
|
|
printf("Network ordered address: %#lx \n", net_addr);
|
|
|
|
return 0;
|
|
}
|