c - 警告 : passing argument 2 of ‘memcpy’ makes pointer from integer without a cast [enabled by default]

标签 c memcpy strcpy

对于以下片段:

    /* get IP address on a specific network interface */
    void get_ip_dev(char* ipaddr, char* interface)
    {
            int fd;
            struct ifreq ifr;
            fd = socket(AF_INET, SOCK_DGRAM, 0);
            ifr.ifr_addr.sa_family = AF_INET;
            strncpy(ifr.ifr_name, interface, IFNAMSIZ-1);
            ioctl(fd, SIOCGIFADDR, &ifr);
            close(fd);
            memcpy(ipaddr, inet_ntoa(((struct sockaddr_in *)&(ifr.ifr_addr))->sin_addr), 20);
    }

我从 memcpy 收到警告,为什么?谢谢!

network.c: In function ‘get_ip_dev’:
network.c:39:43: 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’

最佳答案

这应该是一个简单的修复:您需要包含 <arpa/inet.h> .编译器可能假设它返回 int。

关于c - 警告 : passing argument 2 of ‘memcpy’ makes pointer from integer without a cast [enabled by default],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17077341/

相关文章:

c - C 中的锯齿状数组

python - 为什么允许字符串文字的连接?

c - 如何在 C 语言中为我的 8051、AT89C51CC03 板微 Controller 创建按钮软件复位?

c - 以下 memcpy 如何超出 C 中的数组?

c - memcpy 额外的起始字符

c - 是否有 "lseek"要内存?

c - 字符串复制中的段错误

c++ - 无法使用 C++ catch(...) 捕获访问冲突异常

c++ - round_down 宏需要解释

c - 如何在c中正确实现strcpy?