-(Nsstring *) macaddress {
Int MIB [6];
Size_t Len;
Char * Buf;
Unsigned char * PTR;
Struct if_msghdr * IFM;
Struct sockaddr_dl * SDL;
MiB [0] = ctl_net;
MiB [1] = af_route;
MiB [2] = 0;
MiB [3] = af_link;
MiB [4] = net_rt_iflist;
If (MIB [5] = if_nametoindex ("en0") = 0 ){
// Printf ("error: if_nametoindex error \ n ");
Return NULL;
}
If (sysctl (MIB, 6, null, & Len, null, 0) <0 ){
// Printf ("error: sysctl, take 1 \ n ");
Return NULL;
}
If (BUF = malloc (LEN) = NULL ){
// Printf ("cocould not allocate memory. Error! \ N ");
Return NULL;
}
If (sysctl (MIB, 6, Buf, & Len, null, 0) <0 ){
// Printf ("error: sysctl, take 2 ");
Free (BUF );
Return NULL;
}
IFM = (struct if_msghdr *) BUF;
SDL = (struct sockaddr_dl *) (IFM + 1 );
PTR = (unsigned char *) lladdr (SDL );
Nsstring * outstring = [nsstring stringwithformat: @ "% 02x % 02x % 02x % 02x % 02x % 02x ",
* PTR, * (PTR + 1), * (PTR + 2), * (PTR + 3), * (PTR + 4), * (PTR + 5)];
Free (BUF );
// Nslog (@ "macstring: % @", outstring );
Return outstring;
}