25 #include <sys/socket.h>
27 #include <sys/types.h>
28 #include <netinet/in.h>
29 #include <arpa/inet.h>
35 #if defined HAVE_LIBNL || HAVE_LIBNL3
36 #include <netlink/route/link.h>
37 #include <netlink/route/addr.h>
38 #include <netlink/genl/genl.h>
39 #include <netlink/genl/ctrl.h>
51 : _panid(panid), _iface(iface)
63 throw socket_exception(
"socket is already up");
69 bzero(&sockaddr,
sizeof(sockaddr));
78 if ( ::
bind(
_fd, (
struct sockaddr *) &sockaddr,
sizeof(sockaddr)) < 0 )
80 throw socket_exception(
"cannot bind socket");
89 throw socket_exception(
"socket is not up");
96 int optval = (enable ? 1 : 0);
104 struct sockaddr_storage clientAddress;
105 socklen_t clientAddressLength =
sizeof(clientAddress);
106 ::memset(&clientAddress, 0, clientAddressLength);
109 ssize_t ret = ::recvfrom(_fd, buf, buflen, flags, (
struct sockaddr *) &clientAddress, &clientAddressLength);
117 std::stringstream ss_pan; ss_pan << addr154->
addr.
pan_id;
129 bzero(&sockaddr,
sizeof(sockaddr));
134 std::stringstream ss_pan(
addr.service());
137 std::stringstream ss_short(
addr.address());
140 ::connect(_fd, (
struct sockaddr *) &sockaddr,
sizeof(sockaddr));
143 ret = ::send(_fd, buf, buflen, flags);
157 std::stringstream ss_pan; ss_pan << address.
addr.
pan_id;
165 #if defined HAVE_LIBNL || HAVE_LIBNL3
167 struct nl_sock *nl = nl_socket_alloc();
169 struct nl_handle *nl = nl_handle_alloc();
171 unsigned char *buf = NULL;
172 struct sockaddr_nl nla;
175 struct nlmsghdr *nlh;
186 family = genl_ctrl_resolve(nl,
"802.15.4 MAC");
189 nl_send_auto_complete(nl, msg);
193 nl_recv(nl, &nla, &buf, NULL);
194 nlh = (
struct nlmsghdr*)buf;
203 ret->
short_addr = nla_get_u16(attrs[IEEE802154_ATTR_SHORT_ADDR]);
211 nl_handle_destroy(nl);