gpt4 book ai didi

c - 如何将字符复制到 srv_address.sin_addr.s_addr

转载 作者:行者123 更新时间:2023-11-30 17:40:55 25 4
gpt4 key购买 nike

我不知道如何复制这个:

srv_address.sin_addr.s_addr = udp->address;

我知道它们是不同的类型,我无法通过这种方式复制它们,但我尝试了几乎所有方法但没有成功,请帮助我解决它

最佳答案

试试这个:inet_pton(AF_INET, udp->peer_address, &srv_address.sin_addr);

int inet_pton(int af, const char *src, void *dst);

This function converts the character string src into a network address structure in the af address family, then copies the network address structure to dst. The af argument must be either AF_INET or AF_INET6.

srv_address.sin_addr.s_addr= inet_addr(udp->peer_address);

in_addr_t inet_addr(const char *cp);

The inet_addr() function converts the Internet host address cp from IPv4 numbers-and-dots notation into binary data in network byte order

关于c - 如何将字符复制到 srv_address.sin_addr.s_addr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21333175/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com