37 const std::string LOWPANDatagramService::TAG =
"LOWPANDatagramService";
40 : _panid(panid), _iface(iface)
74 }
catch (
const std::bad_cast&) {
75 throw DatagramException(
"bind failed");
77 throw DatagramException(
"bind failed");
99 if (length > _params.max_msg_length)
106 if (socks.size() == 0)
return;
111 LOWPANDatagramService::decode(identifier, destaddr);
114 std::vector<char> tmp(length + 1);
128 tmp[0] |=
static_cast<char>((0x03 & seqno) << 2);
136 ::memcpy(&tmp[1], buf, length);
142 sock.
sendto(&tmp[0], length + 1, 0, destaddr);
156 if (length > _params.max_msg_length)
163 if (socks.size() == 0)
return;
167 std::vector<char> tmp(length + 1);
181 tmp[0] |=
static_cast<char>((0x03 & seqno) << 2);
189 ::memcpy(&tmp[1], buf, length);
198 sock.
sendto(&tmp[0], length + 1, 0, _addr_broadcast);
219 _vsocket.select(&readfds, NULL, NULL, NULL);
221 for (ibrcommon::socketset::iterator iter = readfds.begin(); iter != readfds.end(); ++iter) {
224 std::vector<char> tmp(length + 1);
230 size_t ret = sock.
recvfrom(&tmp[0], length + 1, 0, fromaddr);
239 switch (tmp[0] & (0x03 << 4)) {
264 seqno = (tmp[0] & (0x03 << 2)) >> 2;
268 ::memcpy(buf, &tmp[1], ret);
272 address = LOWPANDatagramService::encode(fromaddr);
292 std::stringstream ss_pan; ss_pan << _panid;
298 return LOWPANDatagramService::encode(addr);
326 std::stringstream ss;
327 ss <<
"addr=" << addr.
address() <<
";pan=" << addr.
service() <<
";";
331 void LOWPANDatagramService::decode(
const std::string &identifier,
ibrcommon::vaddress &addr)
338 std::vector<string>::const_iterator param_iter = parameters.begin();
340 while (param_iter != parameters.end())
344 if (p[0].compare(
"addr") == 0)
349 if (p[0].compare(
"pan") == 0)