最近一直使用linux mint 15,我用的是64位操作系统,在进行网络编程的时候,发现一个问题,请看源码:

/*get_ip_by_name.c*/

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <netdb.h>
#include <sys/types.h>
#include <netinet/in.h> int main(int argc,char *argv[])
{
struct hostent *h; if( argc != 2 )
{
printf("Usage:%s hostname\n",argv[0]);
exit(1);
}
if( (h=gethostbyname(argv[1])) == NULL )
{
herror("gethostbyname");
exit(1);
}
printf("Host name: %s\n",argv[1]);
printf("Ip address: %s\n",inet_ntop(*( (struct in_addr*)h->h_addr) )); return 0;
}

这段代码在以前32位 的机器上面是没有问题的,但是在我的64位机器上面就出问题了,编译时给警告:

linuxmint dns # gcc -o get_ip_by_name get_ip_by_name.c
get_ip_by_name.c: In function ‘main’:
get_ip_by_name.c:26:49: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat]

警告的意思是,%s需要char *型的数据,而inet_ntoa返回的是int类型的,当我执行的时候出现了段错误!然后我man了一下,发现inet_ntoa函数在我的机器上面的返回值是int型的!这个时候需要加上#include <arpa/inet.h>,这样才能让返回值成为char *型的。当然还可以使用inet_ntop函数!

64位linux中使用inet_ntoa报错处理的更多相关文章

  1. 【我的Android进阶之旅】解决Center OS 64位系统编译Android APP报错error=2和finished with non-zero exit value 127

    一.错误描述 1.问题 java.io.IOException: error=2, 没有那个文件或目录 今天在刚重新搭建好的64位的Center OS上安装好了Android SDK,Jenkins, ...

  2. centos7 64位系统jdbc连接oracle报错问题

    这两天发生了一个错误,记录下来. 报错如下: ### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could n ...

  3. linux中启动网卡报错:Bringing up interface eth1: Error: Connection activation failed

    在重启linux网络服务的时候提示: Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/2 并且产生报错 ...

  4. 64位Ubuntu配置android环境报错(...adb": error=2, 没有那个文件或目录)

    Failed to get the adb version: Cannot run program "/home/jayhomzhou/android/android-sdk/platfor ...

  5. 关于 64位系统 java连接access 报错java.sql.SQLException: [Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指定默认驱动程序

    报错的原因是url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=E:/公司/2000.mdb"; 这样是不行 ...

  6. Win7 64位系统 VS2010连接Oracle报错的问题

    1,异常现象: TNS无法识别 2,异常分析:VS2010启动调试的时候,出现异常.但是使用IIS作为服务器的时候,是不会出现异常,也就是可以正常访问到数据库,后来分析是由于VS自带服务器ASP.NE ...

  7. linux中挂载硬盘报错(you must specify the filesystem type)

    公司有台服务器做了raid1,由于容量小,需扩容,原先打算再添加两块硬盘进去做多一组raid1,组成两组raid1混合使用,但是公司抠门,买到服务器只能安装3块硬盘,无奈之下只能放多一块进去单独挂载分 ...

  8. 为什么win记事本编辑的shell在linux中运行会报错

    结论:win记事本使用的格式有别于linux,二者不可混用.linux使用一个叫vi的编辑器. 解决办法:使用vi命令建立文件,在其中敲shell.命令:vi  > filename   (敲完 ...

  9. Delphi - 让Delphi10.2在Windows下开发的图形界面程序运行在64位Linux中!

    FmxLinux官网:https://fmxlinux.com/ 参考: http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Linux_Applica ...

随机推荐

  1. shell编程(一)--常用变量及表达式

    $? 表示执行上一个命令的返回值:如果为0表示执行成功,非0表示执行失败$1.$2.... 分别表示参数1.参数2....$# 表示这个程序的参数个数$*/$@ 表示这个程序的所有参数$$ 表示这个程 ...

  2. icinga 被动模式 nsca 安装

    本文假设读者已安装好icinga,此外nsca本身nagios插件,icinga/nagios都适用 一.编译安装nsca1.编译,拷贝文件tar -vxzf nsca-2.7.2.tar.gz./c ...

  3. Remember the Word,LA3942(Trie树+DP)

    Trie树基础题,记录下代码. #include <cstdio> #include <cstring> #define MaxNode 4005*100 #define No ...

  4. (十)unity4.6学习Ugui中文文档-------參考-UGUI Canvas Components

     大家好,我是孙广东.   转载请注明出处:http://write.blog.csdn.net/postedit/38922399 更全的内容请看我的游戏蛮牛地址:http://www.unit ...

  5. Difference between Tomcat's extraResourcePaths and aliases to access an external directory--转

    Question: Simple question: In Tomcat7, what's the difference between using extraResourcePaths and al ...

  6. 去除jquery.min.map 404错误信息

    调试中出现了 jquery.min.map 404 (Not Found) 的js错误信息: 那么jquery.min.map到底是个什么呢? JQuery 官方解释 从 jQuery 1.9.0 版 ...

  7. ReSharper warning: Virtual member call in a constructor

    1.构造函数的执行顺序是:基类--->派生类 2.如果虚方法被重写后,由于基类中调用了虚方法,此时调用的是最外层的被重写后的虚方法,此时可能会发生异常 举例: class Parent { pu ...

  8. ViewState探索

    什么是 view state? View State是客户端状态管理重要机制之一.当页面PostBack(向服务器发送或获得数据)时,它能存储页面的值.ASP.NET把View State属性作为页面 ...

  9. GDI+基础(3)

    常用图形绘制 <%@ Page ContentType="image/gif" Language="C#" %> <!--ContentTyp ...

  10. 创建实体数据模型需要注意的,不要选单复数形式,否则AddObject出问题

    //这个测试太不容易了,总是出错,addInfo 方法进去,最后调用context对象.AddObject(),也就是context.AddObject(entitySetName, entity); ...