public byte[] this[DHCPOptionEnum optype] { get { byte[] ret = null; foreach (DHCPOption op in Options) { if (op.Type == optype) { ret = op.Value; break; } } return(ret); } set { for (int x = 0; x < Options.Count; x++) { if (Options[x].Type == optype) { _options.RemoveAt(x); break; } } if (value != null) { _options.Add(new DHCPOption(optype, value)); } } }
internal DHCPOption(byte[] data) { BinaryReader br = new BinaryReader(new MemoryStream(data)); _type = (DHCPOptionEnum)br.ReadByte(); _value = br.ReadBytes((int)br.ReadByte()); }
//create an option message //shall always append at the end of the message private void CreateOptionElement(DHCPOptionEnum Code, byte[] DataToAdd, ref byte[] AddtoMe) { byte[] tOption; try { tOption = new byte[DataToAdd.Length + 2]; //add the code, and data length tOption[0] = (byte)Code; tOption[1] = (byte)DataToAdd.Length; //add the code to put in Array.Copy(DataToAdd, 0, tOption, 2, DataToAdd.Length); //copy the data to the out array if (AddtoMe == null) { Array.Resize(ref AddtoMe, (int)tOption.Length); } else { Array.Resize(ref AddtoMe, AddtoMe.Length + tOption.Length); } Array.Copy(tOption, 0, AddtoMe, AddtoMe.Length - tOption.Length, tOption.Length); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
//pass the option type that you require //parse the option data //return the data in a byte of what we need private byte[] GetOptionData(DHCPOptionEnum DHCPTyp, cDHCPStruct cdDHCPs) { int DHCPId = 0; byte DDataID, DataLength = 0; byte[] dumpData; try { DHCPId = (int)DHCPTyp; //loop through look for the bit that states that the identifier is there for (int i = 0; i < cdDHCPs.dStruct.D_options.Length; i++) { //at the start we have the code + length //i has the code, i+1 = length of data, i+1+n = data skip DDataID = cdDHCPs.dStruct.D_options[i]; if (DDataID == DHCPId) { DataLength = cdDHCPs.dStruct.D_options[i + 1]; dumpData = new byte[DataLength]; Array.Copy(cdDHCPs.dStruct.D_options, i + 2, dumpData, 0, DataLength); return(dumpData); } else { DataLength = cdDHCPs.dStruct.D_options[i + 1]; //'length of code i += 1 + DataLength; } //.endif } //for } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { dumpData = null; } return(null); }
public DHCPOption(DHCPOptionEnum type, byte[] value) { _type = type; _value = value; }
public byte[] this[DHCPOptionEnum optype] { get { byte[] ret = null; foreach (DHCPOption op in Options) { if (op.Type == optype) { ret = op.Value; break; } } return ret; } set { for (int x = 0; x < Options.Count;x++ ) { if (Options[x].Type == optype) { _options.RemoveAt(x); break; } } if (value!=null) _options.Add(new DHCPOption(optype, value)); } }
internal DHCPOption(byte[] data) { BinaryReader br = new BinaryReader(new MemoryStream(data)); _type = (DHCPOptionEnum)br.ReadByte(); _value = br.ReadBytes((int)br.ReadByte()); }
public DHCPOption(DHCPOptionEnum type, byte[] value) { _type = type; _value = value; }