Ejemplo n.º 1
0
int ACE_Netlink_Addr::set (const ACE_Netlink_Addr &sa)
{
  ACE_OS::memset ((void *) &this->nl_,0,sizeof this->nl_);
  this->nl_.nl_family = AF_NETLINK;
  this->base_set (sa.get_type (), sa.get_size ());
  return 0;
}
Ejemplo n.º 2
0
int ACE_SOCK_Netlink::open (ACE_Netlink_Addr &local,
                            int protocol_family,
                            int protocol) //! protocol of your choosing
{
  ACE_TRACE ("ACE_SOCK_Netlink::open");

  if ( ACE_SOCK::open (SOCK_RAW,
                       protocol_family, //! RAW or DGRAM valid
                       protocol,0) < 0 ) {
    ACE_TRACE ("ACE_SOCK_Netlink::open failed to open");
    return -1;
  }

  if (ACE_OS::bind(this->get_handle(),
                   (sockaddr*)local.get_addr(),
                   local.get_addr_size())  == -1 ) {
    ACE_TRACE ("ACE_SOCK_Netlink::open failed to bind socket");
    return -1;
  }
  return 0;
}
Ejemplo n.º 3
0
int
Secondary_Ipaddr_Handler::handle_input (ACE_HANDLE)
{
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT("(%P) Secondary_Ipaddr_Handler::handle_input -  entered\n")));

  nlmsghdr *hdr = 0;
  iovec iov;

  iov.iov_base = this->recv_buff_;
  iov.iov_len = sizeof (this->recv_buff_);

  int rval_bytes = -1;
  ACE_Netlink_Addr raddr;
  raddr.set (0, 0);

  rval_bytes = this->socket ().recv (&iov, 1, raddr);
  switch (rval_bytes)
    {
    case -1: // Complain and leave
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT("(%P) Secondary_Ipaddr_Handler::handle_input - ")
                         ACE_TEXT("%p bad read\n"), ACE_TEXT("client")),
                        -1);

    case 0: // Complain and leave
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT("(%P) Secondary_Ipaddr_Handler::handle_input - "),
                         ACE_TEXT("eof, closing daemon (fd = %d)\n"),
                         this->get_handle ()),
                        -1);

    default:
      if (raddr.get_size () != sizeof (sockaddr_nl))
        {
          this->on_recv_error ();
          ACE_ERROR_RETURN ((LM_ERROR,
                             ACE_TEXT("(%n %P) Secondary_Ipaddr_Handler::handle_input - ")
                             ACE_TEXT("address length not equal sockaddr_nl\n")),
                            -1);
        }

      hdr =  reinterpret_cast <nlmsghdr*> (this->recv_buff_);

      if (static_cast <int> (hdr->nlmsg_len) != rval_bytes)
        {
          this->on_recv_error ();
          ACE_ERROR_RETURN ((LM_ERROR,
                             ACE_TEXT("(%P) Secondary_Ipaddr_Handler::handle_input - ")
                             ACE_TEXT("size of nlmsg_len not equal received bytes\n")),
                            -1);
        }

      if (static_cast <int> (hdr->nlmsg_pid) != this->address_.get_pid () || hdr->nlmsg_seq != this->seq_)
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT("(%P) Secondary_Ipaddr_Handler::handle_input - ")
                           ACE_TEXT("process id or message sequence is different\n")),
                          -1);

      if (hdr->nlmsg_type == NLMSG_ERROR)
        {
          struct nlmsgerr *err = static_cast <struct nlmsgerr*> (NLMSG_DATA(hdr));

          errno = -err->error;
          if (errno == 0)
            {
              this->on_command_success ();
              ACE_DEBUG ((LM_DEBUG,
                          ACE_TEXT("(%P) Secondary_Ipaddr_Handler::handle_input -  command success\n")));
              return 0;
            }

          this->on_command_error ();
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT("(%P) Secondary_Ipaddr_Handler::handle_input -  command informs about error\n")));

          // some error message
          ACE_OS::perror("rtnetlink error message: ");

          return 0;
        }
    }
  return -1;
}
Ejemplo n.º 4
0
ACE_Netlink_Addr::ACE_Netlink_Addr (const ACE_Netlink_Addr &sa)
: ACE_Addr (AF_NETLINK, sa.get_size ())
{
  this->set (sa);
}