How to find information like this in the programmate (in C / C ++ / etc) :
# netstat -g Link-layer Multicast Group Membership Group Link-Layer Address Netif 1: 80: c2: 0: 0: 3 & lt; None & gt; En0 33: 33: FF: C7: 9C: 2F & LT; None & gt; N1 1: 0: 5A: 0: 0: FB & lt; None & gt; N1 33: 33: 0: 0: 0: FB & lt; None & gt; N1 1: 0: 5A: 0: 0: 1 & lt; None & gt; N1 ... and so on ...
On Linux, I can get it from the / proc filesystem, but many searches are about the information Nothing has changed in OSX. I suspect that this may be a sysctl () thing, but I have not found anything about which system is requested to use.
I believe that after the search lot have got it. Eventually, I found Darwin's netstate sources, and it took me to the ceremony. Type: man getifmaddrs It seems that this is one. It also shows that it is for other BSD.
Here are some sample codes:
#include & lt; Stdio.h & gt; # Include & lt; Stdlib.h & gt; #include & lt; String.h & gt; # Include & lt; Unistd.h & gt; # Include & lt; Sys / types.h & gt; # Include & lt; Sys / socket.h & gt; # Include & lt; Net / if_dl.h & gt; # Include & lt; Ifaddrs.h> Int main (int argc, char ** argv) {struct ifmaddrs * ifmap = (straight ifmaddrs *) 0; Structure ifmaddrs * p; Four names [32]; Unsigned four Macs [6]; If (Getifmaddrs (& amp; ifmap)) {p = ifmap; While (p) {if (p-> ifma_addr-> sa_family == AF_LINK} {struct sockaddr_dl * in = (struct sockaddr_dl *) p-> ifma_name; Struct sockaddr_dl * la = (straight sockaddr_dl *) P-& gt; ifma_addr; if (la-> sdl_alen == 6) {memcpy (name, in-> SDL_data, in-> SDL_NLN); Name [in-> sdl_nlen] = 0; Mempi (Mac) , La-> SDL_Data + La-> SDL_NLN, 6); Printf ("% s% .2x:% .2x:% .2x:% .2x:% .2x:% .2x \ n", name, Mac [0], Mac [1], Mac [2], Mac [3], Mac [4], Mac [5]);}} P = p-> ifma_next;} Freemoders (ifmap);}}
No comments:
Post a Comment