(365)
(8)
(130)
(155)
(50)
(22)
分类: java
2021-07-21 17:22:50
bool netlinkmanager::sendmessageandgetackorerror(const nl80211packet& packet,
int* error_code) {
unique_ptr
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
vector
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
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
}
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
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;
}
上一篇:
下一篇: