public IP4Header(ByteBuffer buffer)
            {
                try
                {
                    byte versionAndIHL = (byte)buffer.Get();
                    this.version      = (byte)(versionAndIHL >> 4);
                    this.IHL          = (byte)(versionAndIHL & 0x0F);
                    this.headerLength = this.IHL << 2;

                    this.typeOfService = BitUtils.GetUnsignedByte((byte)buffer.Get());
                    this.totalLength   = BitUtils.GetUnsignedShort(buffer.Short);

                    this.identificationAndFlagsAndFragmentOffset = buffer.Int;

                    this.TTL            = BitUtils.GetUnsignedByte((byte)buffer.Get());
                    this.protocolNum    = BitUtils.GetUnsignedByte((byte)buffer.Get());
                    this.protocol       = (TransportProtocol)protocolNum;
                    this.headerChecksum = BitUtils.GetUnsignedShort(buffer.Short);

                    byte[] addressBytes = new byte[4];
                    buffer.Get(addressBytes, 0, 4);
                    this.sourceAddress = InetAddress.GetByAddress(addressBytes);

                    buffer.Get(addressBytes, 0, 4);
                    this.destinationAddress = InetAddress.GetByAddress(addressBytes);

                    //this.optionsAndPadding = buffer.getInt();
                }
                catch
                {
                    throw new UnknownHostException();
                }
            }
Example #2
0
        public string GetBroadcastAddress()
        {
            Log.Debug("UDP", "Getting broadcast adress");
            WifiManager wifi = (WifiManager)Android.App.Application.Context.GetSystemService(Context.WifiService);
            DhcpInfo    dhcp = wifi.DhcpInfo;
            // handle null somehow

            int broadcast = (dhcp.IpAddress & dhcp.Netmask) | ~dhcp.Netmask;

            byte[] quads = new byte[4];
            for (int k = 0; k < 4; k++)
            {
                quads[k] = (byte)((broadcast >> k * 8) & 0xFF);
            }
            Log.Debug("UDP", "Adrress is: " + InetAddress.GetByAddress(quads));
            return(InetAddress.GetByAddress(quads).ToString());
        }
Example #3
0
        //ブロードキャストアドレスの取得
        InetAddress getBroadcastAddress()
        {
            DhcpInfo dhcpInfo  = wifi.DhcpInfo;
            int      broadcast = (dhcpInfo.IpAddress & dhcpInfo.Netmask) | ~dhcpInfo.Netmask;

            byte[] quads = new byte[4];
            for (int i = 0; i < 4; i++)
            {
                quads[i] = (byte)((broadcast >> i * 8) & 0xFF);
            }
            try
            {
                return(InetAddress.GetByAddress(quads));
            }
            catch (IOException e)
            {
                e.PrintStackTrace();
                return(null);
            }
        }
Example #4
0
            public override void OnOutputBufferAvailable(MediaCodec codec, int index, MediaCodec.BufferInfo info)
            {
                ByteBuffer outputBuffer = codec.GetOutputBuffer(index);

                byte[] outputArray = new byte[outputBuffer.Remaining()];
                outputBuffer.Get(outputArray);

                DatagramPacket packet = new DatagramPacket(outputArray, outputArray.Length, InetAddress.GetByAddress(new byte[] { 192, 168, 0, 31 }), 9482);

                _udpSocket.Send(packet);

                codec.ReleaseOutputBuffer(index, false);
            }