- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
#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
但结果是实现定义的(首先,需要考虑字节顺序)。
关于c - 如何将 uint32_t 转换为 struct in_addr?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9961056/
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我想使用 gethostbyname() 创建一个 in_addr 数组。在 Google 上查看后,我发现了这个简短的代码(在 http://www.logix.cz/michal/devel/va
我不明白MSDN's documentation因为它是成员(member)的。它要求我以前从未做过的事情,比如 S_un_b 成员需要 主机的 IPv4 地址,格式为四个 u_chars。 这对我来
我正在使用 pcap 库,我正在 try catch 源和目标 IP 地址,但它似乎给我完全随机的结果: 这是我的结构: struct sniff_ip { u_char ip_vhl; u_
查看 inet_pton 的返回值时和 inet_ntop 的参数在 PHP 手册中,它指的是 in_addr在这两种情况下。 快速搜索将我带到 MSDN Dev Center有了这个答案: The
好的,我有一个包含 struct in_addr 元素的结构。这应该使结构 addrlist_t 至少 12 字节大小 (8 + 4)。平台是amd64。 #include // struct in
只是想知道我是否有一个结构 in_addr,如何将其转换回主机名? 最佳答案 您可以通过将 struct in_addr 包装在 struct sockaddr_in 中来使用 getnameinfo
我正在尝试在 android 上编译网络代码并看到编译错误。我正在使用的结构是 ip_mreq_source,它应该像这样在 header 中定义: struct ip_mreq_source {
我正在阅读本教程:here但我不明白这部分是如何工作的。从 char** 转换为包含 unsigned long 的 struct in_addr ** 似乎很奇怪。 // Cast the h_ad
我的老师给了我一个任务,用 C++ 读取 pcap 文件并显示每条消息的一些信息。使用一些旧资源,我设法读取了 pcap 文件,但是我在访问 IP header 等方面遇到了问题。 我有ip_src对
假设您有以下 IP 地址: 192.168.0.255 如何将人类可读的 IP 地址存储到 struct in_addr 中?我对这种低级别的 C 网络编程是全新的,因此非常感谢任何帮助。 最佳答案
我正在尝试在我的 C 程序中打印一些输出。 当我用cc编译时,我得到这个错误: "whoisclient.c", line 70: argument #1 is incompatible with p
当涉及到这个问题时,我担心字节顺序。也许我想多了我要担心的事情。 我的代码的输入是一个看起来像这样的数据包: 我收到了一个包含一些字节的网络数据包。如果我知道 in_addr 所在的字节数组中的索引(
我正在尝试了解 IN_ADDR 中的 S_un .这是我的 IP 为 127.0.0.1 时的输出: 关于类型的信息: S_un_b An IPv4 address formatted as four
#include #include #include #include int main() { uint32_t ip = 0; printf("%s\n",inet_ntoa(*(stru
下面的转换工作正常,但是当我有 IPV6 时如何处理? sockaddr foo; in_addr_t ip_address = ((sockaddr_in)foo).sin_addr.s_addr;
我需要将结构sockaddr 中的套接字地址转换为结构in_addr。我试图了解 IP 如何存储在这些结构中: struct sockaddr { u_short sa_family;
我在linux(ubuntu 12.04 linux kernel 3.12.17)中写了下面的代码,比较成功,但是当我用eclipse移动android中的代码,并与ndk比较时,它显示错误:分配时
我正在使用 Linux 进行编译。在 struct ip(对于 IPv4)中,当我尝试将值作为 ip1.ip_dst = 0xffffffff; 时,出现以下错误: error: incompatib
我正在将一些 Windows 代码移植到 Mac。我遇到过一些使用 in_addr 类型的代码,并在此处找到了 Windows 实现的文档:http://msdn.microsoft.com/en-u
我是一名优秀的程序员,十分优秀!