android 11 wifi扫描流程梳理-凯发app官方网站

凯发app官方网站-凯发k8官网下载客户端中心 | | 凯发app官方网站-凯发k8官网下载客户端中心
  • 博客访问: 3600101
  • 博文数量: 365
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 2522
  • 用 户 组: 普通用户
  • 注册时间: 2019-10-28 13:40
文章分类

(365)

  • (365)
文章存档

(8)

(130)

(155)

(50)

(22)

我的朋友
相关博文
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·

分类: java

2021-07-21 17:22:50

bool netlinkmanager::sendmessageandgetackorerror(const nl80211packet& packet,

                                                 int* error_code) {

  unique_ptr response;

  if (!sendmessageandgetsingleresponseorerror(packet, &response)) {

    return false;

  }

  uint16_t type = response->getmessagetype();

  if (type != nlmsg_error) {

    log(error) << "receive unexpected message type :" << type;

    return false;

  }

  *error_code = response->geterrorcode();

  return true;

}

bool netlinkmanager::sendmessageandgetsingleresponseorerror(

    const nl80211packet& packet,

    unique_ptr* response) {

  vector> response_vec;

  if (!sendmessageandgetresponses(packet, &response_vec)) {

    return false;

  }

  if (response_vec.size() != 1) {

    log(error) << "unexpected response size: " << response_vec.size();

    return false;

  }

  *response = std::move(response_vec[0]);

  return true;

}

bool netlinkmanager::sendmessageandgetresponses(

    const nl80211packet& packet,

    vector>* response) {

  if (!sendmessageinternal(packet, sync_netlink_fd_.get())) {

    return false;

  }

  // polling netlink socket, waiting for getfamily reply.

  struct pollfd netlink_output;

  memset(&netlink_output, 0, sizeof(netlink_output));

  netlink_output.fd = sync_netlink_fd_.get();

  netlink_output.events = pollin;

  uint32_t sequence = packet.getmessagesequence();

  int time_remaining = kmaximumnetlinkmessagewaitmilliseconds;

  // multipart messages may come with seperated datagrams, ending with a

  // nlmsg_done message.

  // receivepacketandrunhandler() will remove the handler after receiving a

  // nlmsg_done message.

  message_handlers_[sequence] = std::bind(appendpacket, response, _1);

  while (time_remaining > 0 &&

      message_handlers_.find(sequence) != message_handlers_.end()) {

    nsecs_t interval = systemtime(system_time_monotonic);

    int poll_return = poll(&netlink_output,

                           1,

                           time_remaining);

    if (poll_return == 0) {

      log(error) << "failed to poll netlink fd: time out ";

      message_handlers_.erase(sequence);

      return false;

    } else if (poll_return == -1) {

      plog(error) << "failed to poll netlink fd";

      message_handlers_.erase(sequence);

      return false;

    }

    receivepacketandrunhandler(sync_netlink_fd_.get());

    interval = systemtime(system_time_monotonic) - interval;

    time_remaining -= static_cast(ns2ms(interval));

  }

  if (time_remaining <= 0) {

    log(error) << "timeout waiting for netlink reply messages";

    message_handlers_.erase(sequence);

    return false;

  }

  return true;

}

bool netlinkmanager::sendmessageinternal(const nl80211packet& packet, int fd) {

  const vector& data = packet.getconstdata();

  ssize_t bytes_sent =

      temp_failure_retry(send(fd, data.data(), data.size(), 0));

  if (bytes_sent == -1) {

    plog(error) << "failed to send netlink message";

    return false;

  }

  return true;

}

阅读(6470) | 评论(0) | 转发(0) |
0

上一篇:

下一篇:

给主人留下些什么吧!~~
")); function link(t){ var href= $(t).attr('href'); href ="?url=" encodeuricomponent(location.href); $(t).attr('href',href); //setcookie("returnouturl", location.href, 60, "/"); }
网站地图