views:

580

answers:

2

Hi, I'm developing an application of multiple socket connections (a TCP alarm watcher). Currently, in order to mock the alarms, i made small applications running on a VM Machine (that is, because the Vm have a different IP) that simulate the alarm endpoints.

What I want to do is to mock the alarms in the same machine I'm running my "server" (i.e. the first application), except that I want these mock alarms to have a different IP. I don't want my mocks running with the same IP that the first App (e.g. The server is 192.168.1.4; I want a mock to be 192.168.1.10, other being 192.168.1.11, etc.; all living in the same machine, just the way VM's can do that).

Virtual Machines in 'bridged network' mode can get a different IP from the DHCP server (that's where I get this idea). So, I'm a little dissoriented on where to investigate to complete the task, my question is:

How Can I make , programaticaly, my mock applications to get its own IP addresses via DHCP? (or, Is it impossible, given the .NET Framework?)

Haj.-

+3  A: 

You can certainly talk to the DHCP server -- the packet format is documented in RFC 2131. Doing this from C# is relatively simple.

However, all this does is "steal" an IP address from the DHCP server's pool. It doesn't actually bind it to the network stack.

It sounds like you still need to get your application to listen on this IP address. Unless this IP address is assigned to the network adapter on the machine, this won't work.

In short: you need multiple network adapters, or a multi-homed network adapter. In which case, you'd be better off letting it sort itself out with DHCP.

On the other hand, if all of your traffic is local, install the "Microsoft Loopback Adapter", and assign a bunch of IP addresses to that.

Roger Lipscombe
Thanks for the idea. I was really completely lost ("what do I read next" situation).I'm going to read about Microsoft Loopback Adapter, and then accept the answer. Thank you again.
HJ42
A: 

You will certainly be able to do this in C#, but I doubt that there is an existing class for doing this (its not a normal thing to do!)

You will probably end up having to do it yourself by recieving / sending the packets yourself.

I managed to find the following link which might be useful:

http://social.msdn.microsoft.com/Forums/en-US/wsk/thread/836c2150-583c-43a6-93b3-0e3202c2e2f5

(I know it says creating a DHCP server, but it could be a good place to start in terms of looking up the DHCP protocol workings)

Having said that I suppose you might have some problems requesting a lease for an IP address from a different IP address.

Kragen