Merge pull request #2301 from sonndinh/remove-dup-reactor-functions
[ACE_TAO.git] / ACE / ace / SOCK_Netlink.cpp
blobc1c1ce4d5abb789bed17011be0e3900bbceb3a9c
1 #include /* */ "ace/SOCK_Netlink.h"
3 #ifdef ACE_HAS_NETLINK
5 #include "ace/Log_Category.h"
6 #include "ace/ACE.h"
7 #include "ace/OS_NS_string.h"
8 #include "ace/OS_NS_unistd.h"
9 #include "ace/SOCK_Netlink.h"
10 #include "ace/OS_NS_sys_socket.h"
11 #if defined (ACE_HAS_ALLOC_HOOKS)
12 # include "ace/Malloc_Base.h"
13 #endif /* ACE_HAS_ALLOC_HOOKS */
15 #if !defined (__ACE_INLINE__)
16 #include "ace/SOCK_Netlink.inl"
17 #endif /* __ACE_INLINE__ */
19 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
21 ACE_ALLOC_HOOK_DEFINE (ACE_SOCK_Netlink)
23 int ACE_SOCK_Netlink::open (ACE_Netlink_Addr &local,
24 int protocol_family,
25 int protocol) //! protocol of your choosing
27 ACE_TRACE ("ACE_SOCK_Netlink::open");
29 if ( ACE_SOCK::open (SOCK_RAW,
30 protocol_family, //! RAW or DGRAM valid
31 protocol,0) < 0 ) {
32 ACE_TRACE ("ACE_SOCK_Netlink::open failed to open");
33 return -1;
36 if (ACE_OS::bind(this->get_handle(),
37 (sockaddr*)local.get_addr(),
38 local.get_addr_size()) == -1 ) {
39 ACE_TRACE ("ACE_SOCK_Netlink::open failed to bind socket");
40 return -1;
42 return 0;
46 ACE_SOCK_Netlink::ACE_SOCK_Netlink (ACE_Netlink_Addr &local,
47 int protocol_family,
48 int protocol)
50 ACE_TRACE ("ACE_SOCK_Netlink::ACE_SOCK_Netlink");
52 if (this->open (local,
53 protocol_family,
54 protocol) == -1)
55 ACELIB_ERROR ((LM_ERROR,
56 ACE_TEXT ("%p\n"),
57 ACE_TEXT ("ACE_SOCK_Netlink")));
60 ssize_t
61 ACE_SOCK_Netlink::send (const iovec iov[],
62 int n,
63 const ACE_Addr &addr,
64 int flags) const
66 ACE_TRACE ("ACE_SOCK_Netlink::send");
67 msghdr send_msg;
69 send_msg.msg_iov = (iovec *) iov;
70 send_msg.msg_iovlen = n;
71 send_msg.msg_name = (char *) addr.get_addr ();
72 send_msg.msg_namelen = addr.get_size ();
73 send_msg.msg_control = 0;
74 send_msg.msg_controllen = 0;
75 send_msg.msg_flags = 0;
77 return ACE_OS::sendmsg (this->get_handle (),
78 &send_msg,
79 flags);
82 ssize_t
83 ACE_SOCK_Netlink::recv (iovec iov[],
84 int n,
85 ACE_Addr &addr,
86 int flags) const
88 ACE_TRACE ("ACE_SOCK_Netlink::recv");
89 msghdr recv_msg;
91 recv_msg.msg_iov = (iovec *) iov;
92 recv_msg.msg_iovlen = n;
93 recv_msg.msg_name = (char *) addr.get_addr ();
94 recv_msg.msg_namelen = addr.get_size ();
95 recv_msg.msg_control = 0;
96 recv_msg.msg_controllen = 0;
97 recv_msg.msg_flags = 0;
99 ssize_t status = ACE_OS::recvmsg (this->get_handle (),
100 &recv_msg,
101 flags);
103 if (recv_msg.msg_flags & MSG_TRUNC)
104 return -1;
106 addr.set_size (recv_msg.msg_namelen);
107 addr.set_type (((sockaddr_in *) addr.get_addr())->sin_family);
109 return status;
112 ACE_END_VERSIONED_NAMESPACE_DECL
114 #endif /* ACE_HAS_NETLINK */