char * host_name="220.181.38.82";///百度音乐盒网址http://220.181.38.82 struct in_addr addr; if(inet_pton(AF_INET,host_name,(void*)&addr)==-1) { perror("phost"); exit(1); } if((host = gethostbyaddr((char *)&addr, 4, AF_INET))==null) { perror("gethostbyaddr"); exit(1); } 失败。为什么啊? 即是解析主机IP地址都是失败的。 说明一下,我在虚拟机下的linux系统下做的。
by greatho1507 - Linux环境编程 - 2008-07-17 12:22:13 阅读(4204) 回复(2)
char * host_name="220.181.38.82";///百度音乐盒网址http://220.181.38.82 struct in_addr addr; if(inet_pton(AF_INET,host_name,(void*)&addr)==-1) { perror("phost"); exit(1); } if((host = gethostbyaddr((char *)&addr, 4, AF_INET))==null) { perror("gethostbyaddr"); exit(1); } 失败。为什么啊? 即是解析主机IP地址都是失败的。 说明一下,我在虚拟机下的linux系统下做的。
[code] main(int argc,char *argv[]) { struct hostent *hent; unsigned long lng=inet_addr(argv[1]); hent=gethostbyaddr((const char *)&lng,sizeof(unsigned long),AF_INET); printf("%s\n",hent->;h_name); } [/code] 测试本机 网关 以及局域网内没开防火墙的虚拟机都失败 是为什么?
代码如: [code] void f(PTRType ptr) { //...对ptr进行一些操作 fprintf(stderr, "ptr is %s", (ptr == null) ? "null" : "not null"); return ; } int main() { PTRType ptr = null; ptr = MakeDoc("Hello"); fprintf(stderr, "ptr is %s", (ptr == null) ? "null" : "not null"); f(ptr); fprintf(stderr, "ptr is %s", (ptr == null) ? "null" : "not null"); } [/code] ...
nl_sk = netlink_kernel_create(&init_net, NETLINK_TEST, 0, nl_data_ready, null, THIS_MODULE); nl_ck 总是为null。 个人目前认为应该是跟挂载点有关系 此挂载点是网桥下的挂载点,创建socket可以成功 static struct nf_hook_ops http_hooks = { .pf = PF_BRIDGE, //IPV4 协议 的 .priority = NF_BR_PRI_NAT_SRC + 1 , // NF_IP_PRI_FIRST, //NF_IP_PRI_LAST ;NF_IP_PRI_NAT_SRC ; .hooknum = NF_BR...
本帖最后由 markieff 于 2014-03-25 18:09 编辑
程序:用gethostbyaddr获取目的IP信息的程序。
程序在编译上没有问题,之前写过一个gethostbyname的程序,可以正常运行,但这个就不行。输入任何IP地址输出的都是:gethostbyaddr error for addr:加上IP,等于返回值是null,希望有大神帮忙看看为什么,困扰好久了,谢谢啦~
上程序:
#include
我在网上查gets这个方法,说出现异常或遇到EOF的时候会返回null,有两点不太理解: 1.什么情况会出现这种异常啊? 2.EOF不都是文件结尾标志么,会用gets方法去读取一个文件么?
如题~~用 malloc 分配内存返回给指针的是null。运行的程序需要分配很多的内存,不能准确得知程序分配的内存大小,但不需要的被free 为什么会返回null值?要怎么处理呀,或者有没有相关资料让我参详一下呀?PS:我用的code::blocks 菜鸟一枚~~请大家多指教啊~~~
用的是网上找到的源码[code]/***************************************************
* file: testpcap1.c
* Date: Thu Mar 08 17:14:36 MST 2001
* Author: Martin Casado
* Location: LAX Airport (woof!)
*
* Simple single packet capture program
*****************************************************/
#include