Monitoring network usage excluding local traffic

前端 未结 8 2049
一整个雨季
一整个雨季 2020-12-29 13:14

I am working on an app that monitors network usage. However I noticed many ways to do this does not allow exclusion of local traffic (say, Time Machine).

I am lookin

8条回答
  •  离开以前
    2020-12-29 14:01

    you need to read the source for ifconfig(8), which describes how to get the status of every attached network interface.

    pay particular attention to in_status(), which gets the inet address and netmask of an interface.

    when the source or destination address in the traffic has the same host as a local interface

    int is_local =
    (src && netmask) == (ifaddr && netmask)
    || (dst && netmask) == (ifaddr && netmask)

    then you can be sure that it is local

    http://www.opensource.apple.com/source/network_cmds/network_cmds-307/ifconfig.tproj/ifconfig.c

提交回复
热议问题