mirror of
https://github.com/riba2534/TCP-IP-NetworkNote.git
synced 2026-02-02 17:48:55 +08:00
23 lines
627 B
C
23 lines
627 B
C
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <arpa/inet.h>
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
struct sockaddr_in addr1, addr2;
|
|
char *str_ptr;
|
|
char str_arr[20];
|
|
|
|
addr1.sin_addr.s_addr = htonl(0x1020304);
|
|
addr2.sin_addr.s_addr = htonl(0x1010101);
|
|
//把addr1中的结构体信息转换为字符串的IP地址形式
|
|
str_ptr = inet_ntoa(addr1.sin_addr);
|
|
strcpy(str_arr, str_ptr);
|
|
printf("Dotted-Decimal notation1: %s \n", str_ptr);
|
|
|
|
inet_ntoa(addr2.sin_addr);
|
|
printf("Dotted-Decimal notation2: %s \n", str_ptr);
|
|
printf("Dotted-Decimal notation3: %s \n", str_arr);
|
|
return 0;
|
|
}
|