2

I run this command on the wireless router:

#: iwlist wlan00 scanning
wlan0    Scan completed :
          Cell 01 - Address: 16:76:02:7D:A5:25
          .....

So the "Address" mentioned there is the MAC address of the access point detected?

I looked in iwlib.h and ap_addr is of type sockaddr

When I first tried to print it as %d, it gave me an output similar to 71654, so I figured it's probably not in the right format.

I also tried to print the info using this answer as a guide: https://stackoverflow.com/a/11684101/1306468

but I got this error:

error: 'sockaddr' has no member named 'sa_len'

For your information I also tried printf("%d\n", result->ap_addr.sa_family); which gave me 1 as output in all detected access points.

Anyone has any idea how I can print out this value so it is in the same form as the iwlist wlan0 scanning address is?

Thanks a lot.

Community
  • 1
  • 1
bubbly
  • 495
  • 1
  • 10
  • 22

2 Answers2

0

Code I've found looks more like this:

printf ("Target hardware (MAC) address: ");
for (i=0; i<5; i++) {
  printf ("%02x:", arpheader->target_mac[i]);
}
0

The 'fff...' are because the top bit is set, and it is being interpreted as a sign bit and extended to fill unsigned int. (notice the f's show up on 9D, FE, and D0, all of which have the 80 bit set)

Your solution works, or casting the the arguments to unsigned char should work too.

russell
  • 660
  • 1
  • 10
  • 18