Initiating Win NT DHCP client operation programmatically

Hi,

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 ?

Thanks
asgrewalAsked:
Who is Participating?
 
mxjijoCommented:

>>  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.
0
 
mxjijoCommented:

>> 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

0
 
asgrewalAuthor Commented:
>> 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.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
mxjijoCommented:

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.

<msdn-quote>

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.

</msdn-quote>

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.

0
 
asgrewalAuthor Commented:
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.
0
 
mxjijoCommented:

>> 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 0.0.0.0 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

0
 
asgrewalAuthor Commented:
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.
0
 
mxjijoCommented:

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.
0
 
asgrewalAuthor Commented:
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..
0
 
asgrewalAuthor Commented:
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.

0
 
mxjijoCommented:

good luck buddy ;-
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.