linux - parsing ip address in raw socket programming in C -


i implementing raw sockets in c linux. new socket programming have problem data types used internet addresses.

i want know should data type of ip_addres(in main) in code below. think needs pointer need return 2 addresses. these 2 addresses passed in next function shown.

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 function return ip address of destination , 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; } 

yes correct . can return pointer source ip address , destination ip address 4 bytes (32 bits) source ip address in ip header . can add 4 address of source ip address destination ip address .

char *src_ip;

src_ip = parseipheader(packet_buffer,len);

createipheader(src_ip,src_ip+4);


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -