IP-address from sk_buff

前端 未结 6 1505
说谎
说谎 2021-02-02 17:43

I am writing a kernel module which registers a netfilter hook. I am trying to get the ip address of the caller by using the sk_buff->saddr member. Is there a way

6条回答
  •  一生所求
    2021-02-02 18:13

    Simple. The IP address in "x.x.x.x" format is called dotted-quad for a reason. Each number represents a byte, for a total of 4 bytes in your address.

    So, with the 4 byte address, you would simply print the decimal value of each byte.

    Quick and dirty example (replace printf with your output function of choice):

    unsigned char *addr = (unsigned char*)sk_buff->addr;
    printf("%d.%d.%d.%d", addr[0], addr[1], addr[2], addr[3]);
    

提交回复
热议问题