2

I have been searching for quite a while and cannot seem to find a working DHCP Client implementation example in C#. I am brand spankin' new to Network Programming, but am doing some research that requires me to write a manual DHCP client and to implement Auto-IP if there is no DHCP server.

Any code examples, or names of built-in C# classes that can help me with this would be appreciated.

Curtis
  • 5,794
  • 8
  • 50
  • 77
  • 1
    I don't know how to do it in C#, but you should probably look up "raw sockets". – Some programmer dude Sep 07 '12 at 06:10
  • I ended up realizing that Microsoft's OS's don't let us make the low level calls to broadcast our IP to the DHCPs. The OS handles that for us and we just ask it what our IP is. Doing it manually can only be accomplished on other OS's. At least that's my current understanding of it. Again, I'm really new to all things involved with networking. I've somehow been able to avoid programming networks for the past 15 years :-) – Curtis Sep 26 '12 at 17:04

2 Answers2

1

You are not going to find that; the reason is “security”.

Regular net APIs allow you to handle Level-3 and up but a DHCP client must be able to handle Level-2; i.e. for broadcasting to MAC FF:FF:FF:FF:FF:FF on DHCP DISCOVERY packets

For security reasons Microsoft today does not allow you to craft Ethernet packages at such a low level.

You cannot use raw sockets; read here why:

Limitations on Raw Sockets

http://msdn.microsoft.com/en-us/library/ms740548(v=vs.85).aspx

Pat
  • 2,670
  • 18
  • 27
  • Ok, so what's the answer to my original question? – Curtis Sep 14 '12 at 13:44
  • 1
    I think my answer is clear; I'm afraid you are not going to find what you are looking for because it does not exists... Forget about finding any C#/C++ class solving your DHCP client needs from userland – Pat Sep 14 '12 at 15:30
  • Ah.. This may explain why I have been unable to find out how to do this. It can't be done... However, I am guessing that I could be a DHCP server. My guess is that microsoft sens out a DHCP request for you, but you cannot do it programatically. I could, however, probably listen for such a request, and then respond to the IP that requested it. – Curtis Sep 14 '12 at 19:32
  • 1
    The whole thing of DHCP vs the predecessor BOOTP is that DHCP is asymmetrical; you need handling Level-2 on the client but you only need handling Level-3 on the server. BOOTP needed Level-2 for both. You can code a DHCP Server just with a Level-3 API (winsockets) but for coding a DHCP client you need kernel support. – Pat Sep 14 '12 at 19:44
0

You can install the pccap driver on your pc and use that apI to send raw packets

malaugh
  • 167
  • 6