def main():
    """Main function called upon script execution."""
    # First get the wireless interface index.
    pack = struct.pack('16sI', OPTIONS['<interface>'].encode('ascii'), 0)
    sk = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    try:
        info = struct.unpack('16sI', fcntl.ioctl(sk.fileno(), 0x8933, pack))
    except OSError:
        return error('Wireless interface {0} does not exist.'.format(OPTIONS['<interface>']))
    finally:
        sk.close()
    if_index = int(info[1])

    # Next open a socket to the kernel and bind to it. Same one used for sending and receiving.
    sk = nl_socket_alloc()  # Creates an `nl_sock` instance.
    ok(0, genl_connect, sk)  # Create file descriptor and bind socket.
    _LOGGER.debug('Finding the nl80211 driver ID...')
    driver_id = ok(0, genl_ctrl_resolve, sk, b'nl80211')
    _LOGGER.debug('Finding the nl80211 scanning group ID...')
    mcid = ok(0, genl_ctrl_resolve_grp, sk, b'nl80211', b'scan')

    # Scan for access points 1 or more (if requested) times.
    if not OPTIONS['--no-sudo']:
        print('Scanning for access points, may take about 8 seconds...')
    else:
        print("Attempting to read results of previous scan.")
    results = dict()
    for i in range(2, -1, -1):  # Three tries on errors.
        if not OPTIONS['--no-sudo']:
            ret = ok(i, do_scan_trigger, sk, if_index, driver_id, mcid)
            if ret < 0:
                _LOGGER.warning('do_scan_trigger() returned %d, retrying in 5 seconds.', ret)
                time.sleep(5)
                continue
        ret = ok(i, do_scan_results, sk, if_index, driver_id, results)
        if ret < 0:
            _LOGGER.warning('do_scan_results() returned %d, retrying in 5 seconds.', ret)
            time.sleep(5)
            continue
        break
    if not results:
        print('No access points detected.')
        return

    # Print results.
    print('Found {0} access points:'.format(len(results)))
    print_table(results.values())