当前位置: 技术问答>linux和unix
一个简单的代码问题,请大虾进来帮帮忙!急!
来源: 互联网 发布时间:2016-02-07
本文导语: 初次在linux下面写一个socket程序,但是在取ip的时候编译就报错!不知道是为什么,请各位大虾帮忙! /* ......前面是一些定义和判断,因此从取ip的地方开始 */ // get host...
初次在linux下面写一个socket程序,但是在取ip的时候编译就报错!不知道是为什么,请各位大虾帮忙!
/* ......前面是一些定义和判断,因此从取ip的地方开始 */
// get host ip from server name
ip = inet_addr(serverName);
if (-1 == ip)
{
struct hostent* hostData = gethostbyname(serverName);
if (!hostData)
{
printf("DL: Failed to get IP of %sn", serverName);
return -1;
}
memcpy((char*)&ip, hostData->h_addr_list[0], sizeof(ip));
}
...........
编译的时候指示struct hostent* hostData = gethostbyname(serverName)行的警告为:warning: initialization makes pointer from integer without a cast;
指示memcpy((char*)&ip, hostData->h_addr_list[0], sizeof(ip))行的错误为:error: dereferencing pointer to incomplete type,
小的冥思苦想也没有得出答案,请各位大虾帮忙了!
/* ......前面是一些定义和判断,因此从取ip的地方开始 */
// get host ip from server name
ip = inet_addr(serverName);
if (-1 == ip)
{
struct hostent* hostData = gethostbyname(serverName);
if (!hostData)
{
printf("DL: Failed to get IP of %sn", serverName);
return -1;
}
memcpy((char*)&ip, hostData->h_addr_list[0], sizeof(ip));
}
...........
编译的时候指示struct hostent* hostData = gethostbyname(serverName)行的警告为:warning: initialization makes pointer from integer without a cast;
指示memcpy((char*)&ip, hostData->h_addr_list[0], sizeof(ip))行的错误为:error: dereferencing pointer to incomplete type,
小的冥思苦想也没有得出答案,请各位大虾帮忙了!
|
#include
你缺少这个文件.加上就ok
你缺少这个文件.加上就ok
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。