Ejemplo n.º 1
0
        public override byte[] ToByteArray()
        {
            List <byte> buffer = new List <byte>();

            buffer.AddRange(Utils.GetBytesFromString(Name, 32));
            buffer.AddRange(Ip.GetAddressBytes());
            buffer.AddRange(NetMask.GetAddressBytes());
            buffer.AddRange(DefaultGateway.GetAddressBytes());
            return(buffer.ToArray());
        }
Ejemplo n.º 2
0
            public int Serialize(System.IO.Stream buffer)
            {
                int ret = 0;

                byte[] tmp;
                tmp = Ip.GetAddressBytes();
                buffer.Write(tmp, 0, tmp.Length);
                ret += tmp.Length;
                tmp  = SubnetMask.GetAddressBytes();
                buffer.Write(tmp, 0, tmp.Length);
                ret += tmp.Length;
                tmp  = Gateway.GetAddressBytes();
                buffer.Write(tmp, 0, tmp.Length);
                ret += tmp.Length;
                return(ret);
            }
Ejemplo n.º 3
0
        protected void PostEditing()
        {
            if (CurrentPart == "")
            {
                return;
            }
            byte a = atStart;

            if (CurrentPart != "")
            {
                a = System.Convert.ToByte(CurrentPart);
            }
            if (CurrentPart != null)
            {
                switch (Selected)
                {
                case DataPart.A:
                    Ip = new IPAddress(new byte[4] {
                        a, Ip.GetAddressBytes()[1], Ip.GetAddressBytes()[2], Ip.GetAddressBytes()[3]
                    });
                    break;

                case DataPart.B:
                    Ip = new IPAddress(new byte[4] {
                        Ip.GetAddressBytes()[0], a, Ip.GetAddressBytes()[2], Ip.GetAddressBytes()[3]
                    });
                    break;

                case DataPart.C:
                    Ip = new IPAddress(new byte[4] {
                        Ip.GetAddressBytes()[0], Ip.GetAddressBytes()[1], a, Ip.GetAddressBytes()[3]
                    });
                    break;

                case DataPart.D:
                    Ip = new IPAddress(new byte[4] {
                        Ip.GetAddressBytes()[0], Ip.GetAddressBytes()[1], Ip.GetAddressBytes()[2], a
                    });
                    break;
                }
            }
        }
Ejemplo n.º 4
0
        private long SerializeHostEnt(ServiceCtx Context, IPHostEntry HostEntry, List <IPAddress> Addresses = null)
        {
            long OriginalBufferPosition = Context.Request.ReceiveBuff[0].Position;
            long BufferPosition         = OriginalBufferPosition;
            long BufferSize             = Context.Request.ReceiveBuff[0].Size;

            string HostName = HostEntry.HostName + '\0';

            // h_name
            Context.Memory.WriteBytes(BufferPosition, Encoding.ASCII.GetBytes(HostName));
            BufferPosition += HostName.Length;

            // h_aliases list size
            Context.Memory.WriteInt32(BufferPosition, IPAddress.HostToNetworkOrder(HostEntry.Aliases.Length));
            BufferPosition += 4;

            // Actual aliases
            foreach (string Alias in HostEntry.Aliases)
            {
                Context.Memory.WriteBytes(BufferPosition, Encoding.ASCII.GetBytes(Alias + '\0'));
                BufferPosition += Alias.Length + 1;
            }

            // h_addrtype but it's a short (also only support IPv4)
            Context.Memory.WriteInt16(BufferPosition, IPAddress.HostToNetworkOrder((short)2));
            BufferPosition += 2;

            // h_length but it's a short
            Context.Memory.WriteInt16(BufferPosition, IPAddress.HostToNetworkOrder((short)4));
            BufferPosition += 2;

            // Ip address count, we can only support ipv4 (blame Nintendo)
            Context.Memory.WriteInt32(BufferPosition, Addresses != null ? IPAddress.HostToNetworkOrder(Addresses.Count) : 0);
            BufferPosition += 4;

            if (Addresses != null)
            {
                foreach (IPAddress Ip in Addresses)
                {
                    Context.Memory.WriteInt32(BufferPosition, IPAddress.HostToNetworkOrder(BitConverter.ToInt32(Ip.GetAddressBytes(), 0)));
                    BufferPosition += 4;
                }
            }

            return(BufferPosition - OriginalBufferPosition);
        }