use of android.net.netlink.StructNdMsg in project platform_frameworks_base by android.
the class RtNetlinkNeighborMessageTest method testParseRtmDelNeigh.
@SmallTest
public void testParseRtmDelNeigh() {
final ByteBuffer byteBuffer = ByteBuffer.wrap(RTM_DELNEIGH);
// For testing.
byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
final NetlinkMessage msg = NetlinkMessage.parse(byteBuffer);
assertNotNull(msg);
assertTrue(msg instanceof RtNetlinkNeighborMessage);
final RtNetlinkNeighborMessage neighMsg = (RtNetlinkNeighborMessage) msg;
final StructNlMsgHdr hdr = neighMsg.getHeader();
assertNotNull(hdr);
assertEquals(76, hdr.nlmsg_len);
assertEquals(NetlinkConstants.RTM_DELNEIGH, hdr.nlmsg_type);
assertEquals(0, hdr.nlmsg_flags);
assertEquals(0, hdr.nlmsg_seq);
assertEquals(0, hdr.nlmsg_pid);
final StructNdMsg ndmsgHdr = neighMsg.getNdHeader();
assertNotNull(ndmsgHdr);
assertEquals((byte) OsConstants.AF_INET, ndmsgHdr.ndm_family);
assertEquals(21, ndmsgHdr.ndm_ifindex);
assertEquals(StructNdMsg.NUD_STALE, ndmsgHdr.ndm_state);
final InetAddress destination = neighMsg.getDestination();
assertNotNull(destination);
assertEquals(InetAddress.parseNumericAddress("192.168.159.254"), destination);
}
use of android.net.netlink.StructNdMsg in project platform_frameworks_base by android.
the class RtNetlinkNeighborMessageTest method testParseRtmNewNeigh.
@SmallTest
public void testParseRtmNewNeigh() {
final ByteBuffer byteBuffer = ByteBuffer.wrap(RTM_NEWNEIGH);
// For testing.
byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
final NetlinkMessage msg = NetlinkMessage.parse(byteBuffer);
assertNotNull(msg);
assertTrue(msg instanceof RtNetlinkNeighborMessage);
final RtNetlinkNeighborMessage neighMsg = (RtNetlinkNeighborMessage) msg;
final StructNlMsgHdr hdr = neighMsg.getHeader();
assertNotNull(hdr);
assertEquals(88, hdr.nlmsg_len);
assertEquals(NetlinkConstants.RTM_NEWNEIGH, hdr.nlmsg_type);
assertEquals(0, hdr.nlmsg_flags);
assertEquals(0, hdr.nlmsg_seq);
assertEquals(0, hdr.nlmsg_pid);
final StructNdMsg ndmsgHdr = neighMsg.getNdHeader();
assertNotNull(ndmsgHdr);
assertEquals((byte) OsConstants.AF_INET6, ndmsgHdr.ndm_family);
assertEquals(21, ndmsgHdr.ndm_ifindex);
assertEquals(StructNdMsg.NUD_STALE, ndmsgHdr.ndm_state);
final InetAddress destination = neighMsg.getDestination();
assertNotNull(destination);
assertEquals(InetAddress.parseNumericAddress("fe80::86c9:b2ff:fe6a:ed4b"), destination);
}
use of android.net.netlink.StructNdMsg in project platform_frameworks_base by android.
the class RtNetlinkNeighborMessage method newNewNeighborMessage.
/**
* A convenience method to create an RTM_NEWNEIGH message, to modify
* the kernel's state information for a specific neighbor.
*/
public static byte[] newNewNeighborMessage(int seqNo, InetAddress ip, short nudState, int ifIndex, byte[] llAddr) {
final StructNlMsgHdr nlmsghdr = new StructNlMsgHdr();
nlmsghdr.nlmsg_type = NetlinkConstants.RTM_NEWNEIGH;
nlmsghdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK | NLM_F_REPLACE;
nlmsghdr.nlmsg_seq = seqNo;
final RtNetlinkNeighborMessage msg = new RtNetlinkNeighborMessage(nlmsghdr);
msg.mNdmsg = new StructNdMsg();
msg.mNdmsg.ndm_family = (byte) ((ip instanceof Inet6Address) ? OsConstants.AF_INET6 : OsConstants.AF_INET);
msg.mNdmsg.ndm_ifindex = ifIndex;
msg.mNdmsg.ndm_state = nudState;
msg.mDestination = ip;
// might be null
msg.mLinkLayerAddr = llAddr;
final byte[] bytes = new byte[msg.getRequiredSpace()];
nlmsghdr.nlmsg_len = bytes.length;
final ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
byteBuffer.order(ByteOrder.nativeOrder());
msg.pack(byteBuffer);
return bytes;
}
use of android.net.netlink.StructNdMsg in project android_frameworks_base by DirtyUnicorns.
the class RtNetlinkNeighborMessageTest method testParseRtmDelNeigh.
public void testParseRtmDelNeigh() {
final ByteBuffer byteBuffer = ByteBuffer.wrap(RTM_DELNEIGH);
// For testing.
byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
final NetlinkMessage msg = NetlinkMessage.parse(byteBuffer);
assertNotNull(msg);
assertTrue(msg instanceof RtNetlinkNeighborMessage);
final RtNetlinkNeighborMessage neighMsg = (RtNetlinkNeighborMessage) msg;
final StructNlMsgHdr hdr = neighMsg.getHeader();
assertNotNull(hdr);
assertEquals(76, hdr.nlmsg_len);
assertEquals(NetlinkConstants.RTM_DELNEIGH, hdr.nlmsg_type);
assertEquals(0, hdr.nlmsg_flags);
assertEquals(0, hdr.nlmsg_seq);
assertEquals(0, hdr.nlmsg_pid);
final StructNdMsg ndmsgHdr = neighMsg.getNdHeader();
assertNotNull(ndmsgHdr);
assertEquals((byte) OsConstants.AF_INET, ndmsgHdr.ndm_family);
assertEquals(21, ndmsgHdr.ndm_ifindex);
assertEquals(StructNdMsg.NUD_STALE, ndmsgHdr.ndm_state);
final InetAddress destination = neighMsg.getDestination();
assertNotNull(destination);
assertEquals(InetAddress.parseNumericAddress("192.168.159.254"), destination);
}
use of android.net.netlink.StructNdMsg in project android_frameworks_base by ResurrectionRemix.
the class RtNetlinkNeighborMessage method newNewNeighborMessage.
/**
* A convenience method to create an RTM_NEWNEIGH message, to modify
* the kernel's state information for a specific neighbor.
*/
public static byte[] newNewNeighborMessage(int seqNo, InetAddress ip, short nudState, int ifIndex, byte[] llAddr) {
final StructNlMsgHdr nlmsghdr = new StructNlMsgHdr();
nlmsghdr.nlmsg_type = NetlinkConstants.RTM_NEWNEIGH;
nlmsghdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK | NLM_F_REPLACE;
nlmsghdr.nlmsg_seq = seqNo;
final RtNetlinkNeighborMessage msg = new RtNetlinkNeighborMessage(nlmsghdr);
msg.mNdmsg = new StructNdMsg();
msg.mNdmsg.ndm_family = (byte) ((ip instanceof Inet6Address) ? OsConstants.AF_INET6 : OsConstants.AF_INET);
msg.mNdmsg.ndm_ifindex = ifIndex;
msg.mNdmsg.ndm_state = nudState;
msg.mDestination = ip;
// might be null
msg.mLinkLayerAddr = llAddr;
final byte[] bytes = new byte[msg.getRequiredSpace()];
nlmsghdr.nlmsg_len = bytes.length;
final ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
byteBuffer.order(ByteOrder.nativeOrder());
msg.pack(byteBuffer);
return bytes;
}
Aggregations