«   2026/01   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Archives
관리 메뉴

printf("ho_tari\n");

Chapter 3 (endian) 본문

TCP IP 소켓 프로그래밍

Chapter 3 (endian)

호타리 2023. 10. 10. 16:22

<endian_conv.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;
}

 

<compile 결과>

'TCP IP 소켓 프로그래밍' 카테고리의 다른 글

Chapter 4 (echo server, client 통신)  (0) 2023.10.11
Chapter 3 (address)  (0) 2023.10.10
Chapter 1 (read, server, client 통신)  (0) 2023.10.10
Chapter 1 (read)  (0) 2023.10.10
Chapter 1 (open)  (0) 2023.10.10