Search in sources :

Example 6 with StructNdMsg

use of android.net.netlink.StructNdMsg in project android_frameworks_base by ResurrectionRemix.

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);
}
Also used : StructNlMsgHdr(android.net.netlink.StructNlMsgHdr) StructNdMsg(android.net.netlink.StructNdMsg) NetlinkMessage(android.net.netlink.NetlinkMessage) ByteBuffer(java.nio.ByteBuffer) InetAddress(java.net.InetAddress) RtNetlinkNeighborMessage(android.net.netlink.RtNetlinkNeighborMessage)

Example 7 with StructNdMsg

use of android.net.netlink.StructNdMsg in project android_frameworks_base by crdroidandroid.

the class RtNetlinkNeighborMessage method newGetNeighborsRequest.

/**
     * A convenience method to create an RTM_GETNEIGH request message.
     */
public static byte[] newGetNeighborsRequest(int seqNo) {
    final int length = StructNlMsgHdr.STRUCT_SIZE + StructNdMsg.STRUCT_SIZE;
    final byte[] bytes = new byte[length];
    final ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
    byteBuffer.order(ByteOrder.nativeOrder());
    final StructNlMsgHdr nlmsghdr = new StructNlMsgHdr();
    nlmsghdr.nlmsg_len = length;
    nlmsghdr.nlmsg_type = NetlinkConstants.RTM_GETNEIGH;
    nlmsghdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP;
    nlmsghdr.nlmsg_seq = seqNo;
    nlmsghdr.pack(byteBuffer);
    final StructNdMsg ndmsg = new StructNdMsg();
    ndmsg.pack(byteBuffer);
    return bytes;
}
Also used : StructNlMsgHdr(android.net.netlink.StructNlMsgHdr) StructNdMsg(android.net.netlink.StructNdMsg) ByteBuffer(java.nio.ByteBuffer)

Example 8 with StructNdMsg

use of android.net.netlink.StructNdMsg in project platform_frameworks_base by android.

the class RtNetlinkNeighborMessage method newGetNeighborsRequest.

/**
     * A convenience method to create an RTM_GETNEIGH request message.
     */
public static byte[] newGetNeighborsRequest(int seqNo) {
    final int length = StructNlMsgHdr.STRUCT_SIZE + StructNdMsg.STRUCT_SIZE;
    final byte[] bytes = new byte[length];
    final ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
    byteBuffer.order(ByteOrder.nativeOrder());
    final StructNlMsgHdr nlmsghdr = new StructNlMsgHdr();
    nlmsghdr.nlmsg_len = length;
    nlmsghdr.nlmsg_type = NetlinkConstants.RTM_GETNEIGH;
    nlmsghdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP;
    nlmsghdr.nlmsg_seq = seqNo;
    nlmsghdr.pack(byteBuffer);
    final StructNdMsg ndmsg = new StructNdMsg();
    ndmsg.pack(byteBuffer);
    return bytes;
}
Also used : StructNlMsgHdr(android.net.netlink.StructNlMsgHdr) StructNdMsg(android.net.netlink.StructNdMsg) ByteBuffer(java.nio.ByteBuffer)

Example 9 with StructNdMsg

use of android.net.netlink.StructNdMsg in project android_frameworks_base by DirtyUnicorns.

the class RtNetlinkNeighborMessageTest method testParseRtmNewNeigh.

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);
}
Also used : StructNlMsgHdr(android.net.netlink.StructNlMsgHdr) StructNdMsg(android.net.netlink.StructNdMsg) NetlinkMessage(android.net.netlink.NetlinkMessage) ByteBuffer(java.nio.ByteBuffer) InetAddress(java.net.InetAddress) RtNetlinkNeighborMessage(android.net.netlink.RtNetlinkNeighborMessage)

Example 10 with StructNdMsg

use of android.net.netlink.StructNdMsg in project android_frameworks_base by DirtyUnicorns.

the class RtNetlinkNeighborMessage method newGetNeighborsRequest.

/**
     * A convenience method to create an RTM_GETNEIGH request message.
     */
public static byte[] newGetNeighborsRequest(int seqNo) {
    final int length = StructNlMsgHdr.STRUCT_SIZE + StructNdMsg.STRUCT_SIZE;
    final byte[] bytes = new byte[length];
    final ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
    byteBuffer.order(ByteOrder.nativeOrder());
    final StructNlMsgHdr nlmsghdr = new StructNlMsgHdr();
    nlmsghdr.nlmsg_len = length;
    nlmsghdr.nlmsg_type = NetlinkConstants.RTM_GETNEIGH;
    nlmsghdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP;
    nlmsghdr.nlmsg_seq = seqNo;
    nlmsghdr.pack(byteBuffer);
    final StructNdMsg ndmsg = new StructNdMsg();
    ndmsg.pack(byteBuffer);
    return bytes;
}
Also used : StructNlMsgHdr(android.net.netlink.StructNlMsgHdr) StructNdMsg(android.net.netlink.StructNdMsg) ByteBuffer(java.nio.ByteBuffer)

Aggregations

StructNdMsg (android.net.netlink.StructNdMsg)16 StructNlMsgHdr (android.net.netlink.StructNlMsgHdr)16 ByteBuffer (java.nio.ByteBuffer)16 NetlinkMessage (android.net.netlink.NetlinkMessage)8 RtNetlinkNeighborMessage (android.net.netlink.RtNetlinkNeighborMessage)8 InetAddress (java.net.InetAddress)8 Inet6Address (java.net.Inet6Address)4 SmallTest (android.test.suitebuilder.annotation.SmallTest)2