Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Initiating Win NT DHCP client operation programmatically

Posted on 2004-10-23
Medium Priority
Last Modified: 2013-12-03

Are any APIs for Win NT 4.0 that can be used by an application to trigger DHCP client operation on specified network interface ? I know there are DHCP client APIs (or DHCP options) but i guess they r primarily for requesting DHCP options from the server. Can they be used somehow to request an address (along with standard options) ? Also IP helper SDK only has IpReleaseAddress & IpRenewAddress APIs but no APIs to initiate DHCP client process. Am i missing anything ?

Question by:asgrewal
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5

Expert Comment

ID: 12402005

>> Also IP helper SDK only has IpReleaseAddress & IpRenewAddress APIs but no APIs to initiate DHCP client process. Am i missing anything ?
     What you mean by "initialize DHCP client process" ? I don't think you have to explicitly initialize it.

>> Can they be used somehow to request an address ?
     I thought that is what IpRenewAddress() does .

If you are on XP or earlier, there are special API's for DHCP. But looks like you are on NT4.0


Author Comment

ID: 12402351
>> What you mean by "initialize DHCP client process" ? I don't think you have to explicitly initialize it.

i meant "initiate" or "start"  DHCP address allocation procedure on client using APIs.

>> I thought that is what IpRenewAddress() does .

As per MSDN docs IpRenewAddress renews a lease on an IP address previously obtained through DHCP. From this i make out that DHCP client would send a DHCP REQUEST message to renew lease instead of DHCP DISCOVER to obtain a new address. Although i must admit that i haven't carried out any exps with this API. Maybe if no address has been obtained previously it might kick-off a new process. but atleast from the docs it doesn't sound this way.

Expert Comment

ID: 12402573

Yes, you are right, IpRenewAddress doc doesn't say anything about DHCPDiscover. However there is another article in MSDN KB which explains the DHCP ipaddress lease process as follows.


How the Lease Process Works :

1 ) The DHCP client requests an IP address by broadcasting a DHCPDiscover message to the local subnet.

2 ) The client is offered an address when a DHCP server responds with a DHCPOffer message containing an
IP address and configuration information for lease to the client. If no DHCP server responds to the client request,
the client can proceed in two ways:
      1) If it is a Windows 2000–based client, and IP auto-configuration has not been disabled, the client self-configures
          an IP address for its interface.
       2) If the client is not a Windows 2000–based client, or IP auto-configuration has been disabled, the client network
          initialization fails. The client continues to resend DHCPDiscover messages in the background (four times, every 5 minutes)
          until it receives a DHCPOffer message from a DHCP server.

3) The client indicates acceptance of the offer by selecting the offered address and replying to the server with a DHCPRequest message.
4) The client is assigned the address and the DHCP server sends a DHCPAck message, approving the lease. Other DHCP option
information might be included in the message.

5) Once the client receives acknowledgment, it configures its TCP/IP properties using any DHCP option information in the reply, and
joins the network.

In rare cases, a DHCP server might return a negative acknowledgment to the client. This can happen if a client requests an
invalid or duplicate address. If a client receives a negative acknowledgment (DHCPNak), the client must begin the entire lease process again.


Note in Step 1) that the client sends its own address (no matter a valid address or not) with DHCP DISCOVER. And  it sends DHCP REQUEST
as an indication of acceptence of the address supplied by the server. May be it is a little confusing that the term "DHCP REQUEST" is not
actually a "request" but it is an "note of acceptance"

Hope that helped.

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.


Author Comment

ID: 12402941
well..u described the "new DHCP lease acquisition" process..Iam looking for APIs which can initiate this very "new lease acquisition" process..On other hand IpRenewAddress seems to be (as per MSDN) for lease "renewal" process and NOT for new lease "acquisition" process. i apologize if iam confusing u..but i dono how to put it more clearly.

Expert Comment

ID: 12403109

>> Iam looking for APIs which can initiate this very "new lease acquisition" process
      Well, I thought I was trying to explain the same thing too :).

I haven't done the experiments but -
from the documents what I understood is: the "renew" process will work even at the very first time.
Even thought the interface IP address is not initialized, there will be some default address with it.
So even if the interface starts with a address, it can do a "renew" process to get a all new address.

Thats what I was saying in my previous comment, that the lease process actually starts with a DHCPDiscover command,
not with a DHCPRequest command.
But you shold definitly make sure if thats what happens when you call IpRenewAddress() on an un-initialized interface.
You can do it by capturing packets using ethereal or MS network Monitor. As you night know, both tools will parse the packets
and you can examine the message protocol contents.

But interms of DHCP client service start / stop , you can use "net start/stop DHCP" command
or equivallent Service Control Manager API's


Author Comment

ID: 12403712
well..i guess i need to carry out exps..was thinking of getting a definite answer without firing up the compiler; )..but hey thanks for ur help..actually this is a part of a bigger problem..i've a static address already assigned on an interface..i want to assign it another address (IP aliasing) but this time the second one would be obtained thru DHCP. so i was looking for APIs which can return me (the application) a dynamic address which i can then configure on the interface using IP helper APIs. sounds weird ? basically the machine has only one NIC but is on two IP subnets..on one it has static address and on other it needs a dynamic address.. Any ideas. In any case, iam gonna give u the points for ur effort. thanks again.

Expert Comment

ID: 12404195

As you know IP Address is for the interface, not for the NIC. So if you are able to create a second interface for the same NIC,
You should be able to assign an IP address to the new interface with DHCP or static IP no matter whether the first interface
uses DHCP or not. That is why we pass PIP_ADAPTER_INDEX_MAP to IpReleaseAddress call.

>> sounds weird ? basically the machine has only one NIC but is on two IP subnets..on one it has static address and on other it needs a dynamic address..
   No, its not weird, this is usually the case when you use VPN. You got one NIC and 2 IP address. One from your ISP, which can be static.
When you connect to the VPN, you get another IP address which is of another subnet and it would be DHCP. SO, I don't know what exactly
confuses you. May be it si a good idea to write a simple program (which u have to do at some point:) and get better grip on it.

good luck.

Author Comment

ID: 12404411
wo..ow...sir u got me there...yes i know IP address is for an interface..but what i didn;t know was that u can have multiple interfaces for same NIC (adapter). How do u do that ?? i always thought one adapter (either pseudo or physical (NIC) ) presented ONE interface to IP stack layer. If thats possible u might have solved my bigger problem. Also let me know how do u enable/disable DHCP on a per interface basis..waiting anxiously..in the meantime iam going to do some r&d of my own..

Accepted Solution

mxjijo earned 1500 total points
ID: 12404929

>>  can have multiple interfaces for same NIC (adapter).
     Yes, you can, as I said, thats is happens when you add a new network connection (say VPN)  from
my networks window. However don't get confused this with adding another IP address to the same IP.
When  you add a new network connection like VPN you are adding a new interface. (I'm sorry I dont know hot to do it porgramatically :)
The other side is, you can add a second Ip address to the same interface (you can do it programatically or from the TCP/IP settings).
But the problem here is on the same interface the DHCP settings remains the same for all IP address - and I guess that is the real
problem you 're trying to solve.

      To my best knowledge, creating a new interface needs some NDIS level stuff. (I am not very sure about this).
However, we could solve your problem in a different way. Do the DHCP by yourself. Meaning, let the first IP address be unchanged.
Let your application do a DHCP discover/request for the same NIC and get a new IP address. The add that IP address as the second
IP address to the NIC (AddIPAddress() call). Note that both IP addresses will be static in this case. I dont know if this solves your problem,
but it will work. I am sorry I could not help you with adding a new adapter stuff - I know it works but I dont know the easy way.

Author Comment

ID: 12405137
well now u get my problem..u cannot just create more than one configurable interface on a NIC..an interface and adapter(NIC) r synonymous.. VPN is a different beast..as u already know it is a "virtual connection" (and not an interface !) that operates on a same physical connection and VPN app makes it possible..Thats why writing custom DHCP client seems to be the only solution..i know it coz i had done it for linux long time back..but iam not much into windows..so was trying to exhaust all the options before diving into it..Yep u r right, to create an network interface u need to write NDIS miniport driver (either controlling an ethernet NIC or as just a pseudo adapter ). well thankyou for ur time and answers.


Expert Comment

ID: 12405165

good luck buddy ;-

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question