如何将uint32_t转换为struct in_addr?

前端之家收集整理的这篇文章主要介绍了如何将uint32_t转换为struct in_addr?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

int main()
{
uint32_t ip = 0;
printf("%s\n",inet_ntoa(*(struct in_addr *)ip));
return 0;
}

我不想通过声明任何临时变量来做到这一点.该程序给出了分段错误.

struct in_addr {
    uint32_t s_addr; 
};
你正在将int转换为指针.也许你想要这个:
*(struct in_addr *)&ip

但结果是实现定义的(一开始就有字节序注意事项).

原文链接:https://www.f2er.com/windows/363584.html

猜你在找的Windows相关文章