如题,本篇文章是为了测试IP地址转换函数 inet_aton 的实现过程,以及对二进制,八进制和十六进制 C++ 输出的测试,Ubuntu系统下,可通过 cat /usr/include/arpa/inet.h | grep inet_aton 查找原函数声明
下面提供测试程序及其结果:
#include <iostream>
#include <arpa/inet.h> // 网络编程中 包含 inet_aton函数,将点分十进制数串转换为32位网络字节序二进制值
#include <netinet/in.h> // 包含结构定义 struct in_addr{in_addr_t s_addr;}; 其中in_addr_t 为32位无符号整数 uint32_t
#include <iomanip> // hex 十六进制,oct 八进制 dec 十进制
#include <bitset>
using std::cout;
using std::endl;
using std::hex; // 16,10,8
using std::dec;
using std::oct;
using std::bitset;
int main(int argc, char ** argv)
{
char str[] = "192.168.229.200";
struct in_addr test;
cout<<"the IP str:"<<str<&l