项目作者: michelbarbeau

项目描述 :
Wireless Network Programming - The Linux Way
高级语言: C++
项目地址: git://github.com/michelbarbeau/wireless-network-programming.git


Wireless Network Programming - The Linux Way

Installing

git clone https://github.com/michelbarbeau/wireless-network-programming.git

Configuration

Usually the default configuration is fine, but if your wireless interface is called something other than wlan0, modifying label.h is necessary.

iwconfig is a standard program in Ubuntu. It shows the status of wireless devices on your system.

Sample output:

  1. barbeau@ubuntu:~/wireless-network-programming$ iwconfig
  2. eth0 no wireless extensions.
  3. wlan0 IEEE 802.11bgn ESSID:"BELL150"
  4. Mode:Managed Frequency:2.412 GHz Access Point: D8:6C:E9:2A:3C:CD
  5. Bit Rate=1 Mb/s Tx-Power=20 dBm
  6. Retry short limit:7 RTS thr:off Fragment thr:off
  7. Power Management:off
  8. Link Quality=65/70 Signal level=-45 dBm
  9. Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
  10. Tx excessive retries:0 Invalid misc:54 Missed beacon:0
  11. lo no wireless extensions.

label.h contains the device that should be used when running this program. Currently it’s a compile-time dependency and the program must be recompiled if the device needs to be changed. (ie. you get errors saying that wlan0 does not exist)

  1. barbeau@ubuntu:~/wireless-network-programming$ more label.h
  2. // File: label.h
  3. // Author: Michel Barbeau
  4. // Version: January 16, 2016
  5. //#define LABEL "eth0"
  6. #define LABEL "wlan0"

Building

Execute make in the project root directory.

If your system doesn’t have g++ or make installed, on Ubuntu try installing build-essential using apt-get.

Example build output:

  1. barbeau@ubuntu:~/wireless-network-programming$ make
  2. g++ -std=c++0x -c Handler.cpp
  3. g++ -std=c++0x -c WLAN.cpp
  4. g++ -std=c++0x -c Sender.cpp
  5. g++ -std=c++0x -c Receiver.cpp
  6. g++ -std=c++0x WLAN.o Handler.o Sender.o -o sender
  7. g++ -std=c++0x WLAN.o Handler.o Receiver.o -o receiver

Running

Note: This program requires root access.

receiver output:

  1. barbeau@ubuntu:~/wireless-network-programming$ sudo ./receiver
  2. Initializing network interface : wlan0
  3. socket created!
  4. ifindex is: 3
  5. hardware address is: 1c:bd:b9:7e:b6:5a
  6. MTU is: 1500
  7. socket bind done
  8. from 20:68:9d:97:c5:f3 to ff:ff:ff:ff:ff:ff: E
  9. from 20:68:9d:97:c5:f3 to ff:ff:ff:ff:ff:ff:
  10. from 20:68:9d:97:c5:f3 to ff:ff:ff:ff:ff:ff: E
  11. from 20:68:9d:97:c5:f3 to ff:ff:ff:ff:ff:ff:
  12. from 20:68:9d:97:c5:f3 to ff:ff:ff:ff:ff:ff:
  13. from 20:68:9d:97:c5:f3 to ff:ff:ff:ff:ff:ff:
  14. from 1c:bd:b9:7e:b6:5a to ff:ff:ff:ff:ff:ff: This is a test frame
  15. from 20:68:9d:97:c5:f3 to ff:ff:ff:ff:ff:ff:
  16. from 1c:bd:b9:7e:b6:5a to ff:ff:ff:ff:ff:ff: This is a test frame
  17. from 20:68:9d:97:c5:f3 to ff:ff:ff:ff:ff:ff:
  18. from d8:6c:e9:2a:3c:cb to ff:ff:ff:ff:ff:ff:
  19. from 20:68:9d:97:c5:f3 to ff:ff:ff:ff:ff:ff:
  20. ^C

Sender sends out messages to the broadcast address.

sender output:

  1. barbeau@ubuntu:~/wireless-network-programming$ sudo ./sender
  2. Initializing network interface : wlan0
  3. socket created!
  4. ifindex is: 3
  5. hardware address is: 1c:bd:b9:7e:b6:5a
  6. MTU is: 1500
  7. socket bind done

config.sh puts your wlan0 interface into Ad-hoc mode.

config.sh output:

  1. barbeau@ubuntu:~/wireless-network-programming$ sudo ./config.sh
  2. wlan0 IEEE 802.11bgn ESSID:"MyCell"
  3. Mode:Ad-Hoc Frequency:2.422 GHz Cell: 00:00:00:00:00:01
  4. Tx-Power=20 dBm
  5. Retry short limit:7 RTS thr:off Fragment thr:off
  6. Encryption key:off
  7. Power Management:off