@Override protected int peek(InetAddress sender) throws IOException { // We don't actually want the data: we just want the DatagramPacket's filled-in address. DatagramPacket packet = new DatagramPacket(EmptyArray.BYTE, 0); int result = peekData(packet); // Note: evil side-effect on InetAddress! This method should have returned InetSocketAddress! sender.ipaddress = packet.getAddress().getAddress(); return result; }
private void doRecv(DatagramPacket pack, int flags) throws IOException { IoBridge.recvfrom( false, fd, pack.getData(), pack.getOffset(), pack.getLength(), flags, pack, isNativeConnected); if (isNativeConnected) { updatePacketRecvAddress(pack); } }
/** * Set the received address and port in the packet. We do this when the Datagram socket is * connected at the native level and the recvConnnectedDatagramImpl does not update the packet * with address from which the packet was received * * @param packet the packet to be updated */ private void updatePacketRecvAddress(DatagramPacket packet) { packet.setAddress(connectedAddress); packet.setPort(connectedPort); }
@Override public void send(DatagramPacket packet) throws IOException { int port = isNativeConnected ? 0 : packet.getPort(); InetAddress address = isNativeConnected ? null : packet.getAddress(); IoBridge.sendto(fd, packet.getData(), packet.getOffset(), packet.getLength(), 0, address, port); }
@Override public int peekData(DatagramPacket pack) throws IOException { doRecv(pack, MSG_PEEK); return pack.getPort(); }