Tag: ipv4

如何从C中的IPv4地址获取主机名?

我需要一个简单的函数,在给定char* IPAddress输出char* hostname 。 任何想法或提示? 另外,从主机名获取IP地址的最简单方法是gethostbyname()和inet_ntoa()是正确的吗?

将套接字绑定到IPv6地址

我正在尝试编写一个侦听IPv4和IPv6地址的Web服务器。 但是,我最初写的代码不起作用。 然后我发现IPv6结构适用于IPv4和IPv6。 所以现在我使用IPv6结构,但只有IPv4地址才有效。 这篇post, 为什么我不能将ipv6 socket绑定到linklocal地址 ,后面说要添加server.sin6_scope_id = 5; 所以我这样做但它仍然不接受IPv6 telnet连接。 任何帮助将不胜感激,因为我彻底难过。 谢谢! 我的代码如下: void initialize_server(int port, int connections, char* address) { struct sockaddr_in6 socket_struct; /*Creates the socket*/ if ((sock_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { syslog(LOG_ERR, "%s\n", strerror(errno)); exit(EXIT_FAILURE); }/*Ends the socket creation*/ /*Populates the socket address structure*/ socket_struct.sin6_family = AF_INET6; if(address […]

C – Linux – 内核模块 – TCP标头

我正在尝试创建linux内核模块,它将检查传入的数据包。 目前,我正在提取数据包的TCP头并读取源和目标端口 – >但是我得到的值不正确。 我有钩function: unsigned int hook_func(unsigned int hooknum, struct sk_buff *skb, const struct net_device *in, const struct net_device *out, int (*okfn)(struct sk_buff *)) { struct iphdr *ipp = (struct iphdr *)skb_network_header(skb); struct tcphdr *hdr; /* Using this to filter data from another machine */ unsigned long ok_ip = 2396891328; /* Some problem, empty […]