2013-04-09 99 views
-2

在下面的代碼段第三行:net_ntoa,結構SOCKADDR_IN和指針轉換

char cli_ip[20]; 
struct sockaddr cliaddr; 
....... 
memcpy(cli_ip, inet_ntoa(((struct sockaddr_in *)cliaddr)->sin_addr), 20); 

我得到的錯誤:

udp_receiver.c:96:41: error: cannot convert to a pointer type udp_receiver.c:96:41: warning: passing argument 2 of ‘memcpy’ makes pointer from integer without a cast [enabled by default] /usr/include/string.h:44:14: note: expected ‘const void * restrict’ but argument is of type ‘int’

是什麼原因?

+0

-1在獲得答案後,​​千萬不要完全改變問題! - 如果您有其他問題,請將其作爲新帖子。 – deepmax 2013-04-09 08:55:01

+0

至於@MM。請注意,請不要以這種方式編輯您的問題。你的新錯誤顯然是一個不同的問題。 – 2013-04-10 04:16:15

回答

1

您是否適當地包含了標題?

inet_ntoa人建議下,包括

#include <sys/socket.h> 
#include <netinet/in.h> 
#include <arpa/inet.h> 

這可能是編譯器未找到的inet_ntoa原型,並假設它返回int,然後給出memcpy警告的情況下。

+0

啊,好的,這是因爲'#include '在我的源代碼中缺少,謝謝 – misteryes 2013-04-09 08:50:23