none
Creating a dhcp server in C# RRS feed

  • Question

  •  

    Hello everyone, I do apologize if this post is in the wrong forum - it's the best I could find.  Please point me in the right direction if not.

     

    I'm writing a DHCP server in C# (we are a wireless data carrier and the the MS version has some issues).  I've set up a socket listening on 67 and basically intercepting DHCP packets and parsing them.  I've gotten to the DHCP Options part, and am stuck on the first one that I'm getting 99 - GEOCONF_CIVIC.

     

    DHCP RFC: http://www.faqs.org/ftp/rfc/pdf/rfc2131.txt.pdf

    RFC 4776: http://www.faqs.org/ftp/rfc/pdf/rfc4776.txt.pdf

    DHCP Option List:  http://www.iana.org/assignments/bootp-dhcp-parameters/

     

    So RFC 4776 makes differences beteween this attribute for DHCPv4, but we are running IPv4.

     

    Here's my byte array starting at index 236 (first byte of options);

    Byte 236:  99

    Byte 237:  130

    Byte 238:  83

    Byte 239:  99

    Byte 240:  53 - START of new option

    Byte 241:  1

    Byte 242:  3

     

     

    According to the RFC in v4, the first octet is the option type (GEOCONF_CIVIC), the second octet is the length (130) - gotta be wrong because the packet is 300 bytes long.

     

    in the DHCP RFC it says the options follow the tag, length, data format with 1 byte for tag, 1 byte for length.  Page 6 of RFC 4776 has me confused.

     

    So I'm a little confused...  Can anyone help?

    Thursday, September 18, 2008 6:28 PM

Answers

  •  

    Ok, I've now figured this out and am posting for future reference...

     

    According to the RFC(2131) on page 13:

     

    "The first four octets of the ’options’ field of the DHCP message

    contain the (decimal) values 99, 130, 83 and 99, respectively (this

    is the same magic cookie as is defined in RFC 1497 [17])."

     

    No idea why this is done... Anyway, options REALLY start at 240 but I suppose you should validate that 236-239 match the magical cookie.

    Friday, September 19, 2008 1:47 PM

All replies

  •  

    Ok, I've now figured this out and am posting for future reference...

     

    According to the RFC(2131) on page 13:

     

    "The first four octets of the ’options’ field of the DHCP message

    contain the (decimal) values 99, 130, 83 and 99, respectively (this

    is the same magic cookie as is defined in RFC 1497 [17])."

     

    No idea why this is done... Anyway, options REALLY start at 240 but I suppose you should validate that 236-239 match the magical cookie.

    Friday, September 19, 2008 1:47 PM
  • Hello, before the beginning i must admit my English is weak.

    Trying to write a program that downloads a list of DHCP server.

    I wrote just enough:

    using System;
    using System.Threading;
    using System.Net;
    using System.Net.Sockets;
    using System.Text;
    
    namespace DHCPScaner
    {
      class Program
      {
        static void Main(string[] args)
        {
          byte[] send = new byte[237];
          byte[] recv = new byte[237];
          send[0] = 1;
          send[1] = 1;
          send[2] = 6;
          
          IPAddress ip = IPAddress.Parse("255.255.255.255");
          IPEndPoint iep = new IPEndPoint(ip, 67);
          IPEndPoint iep2 = new IPEndPoint(ip, 68);
    
          UdpClient udp = new UdpClient();
          udp.Send(send, send.Length, iep);
          recv = udp.Receive(ref iep2); // Does not receive anything.
          Console.WriteLine(recv.Length);
        }
      }
    } 

    Please help in writing this program

    Friday, March 11, 2011 6:22 PM