【发布时间】:2014-06-01 13:28:20
【问题描述】:
我正在 C linux 中实现原始套接字。我是套接字编程的新手,所以对用于 Internet 地址的数据类型有一些问题。
我想知道下面代码中 ip_addres(in main) 的数据类型应该是什么。我认为它需要是指针,因为我需要返回两个地址。然后这两个地址要在下一个函数中传递,如图所示。
main()
{
int len,raw_socket;
struct iphdr *ip_header;
unsigned char *packet_buffer[2048];
len=recvfrom(raw_socket,packet_buffer,2048,...);
ip_addres=parseipheader(packet_buffer,len); /*I want this function to return ip address of destination and source*/
ip_header=CreateIPHeader(source_ip,destination_ip);
}
parseipheader(unsigned char *packet,int len)
{
struct iphdr *ip_header;
ip_header=(struct ip_header *)(packet+sizeof(struct ethhdr));
return ip_addresses;
}
struct iphdr* CreateIPHeader(source_ip,destination_ip)
{
struct iphdr *ip_header;
return ip_header;
}
【问题讨论】:
标签: c linux sockets ip-address