setting mac address for a host in C (dhcpctl.h)

Johnson koil Raj johnson.raj at wipro.com
Wed Jun 29 14:12:37 UTC 2011


Hi Peter,

     Thanks for correcting me.

  I have changed and tried as you suggestion.

   memset (&macaddrstring, 0, sizeof macaddrstring);
   omapi_data_string_new (&macaddrstring, 18, MDL);
   memcpy(macaddrstring->value, "00:0c:26:22:bf:c3", 18);
   dhcpctl_set_string_value (host, macaddrstring, "hardware-address");

But still the mac address is not getting set proper.

host testomapihost {
   dynamic;
   hardware ethernet 01;
   fixed-address 192.168.10.123;
}

  Still I am missing some thing.


Thanks,
Johnson

----------------------------------------------------------------------
> Message: 1
> Date: Wed, 29 Jun 2011 00:01:42 +0200
> From: Peter Rathlev<peter at rathlev.dk>
> Subject: Re: setting mac address for a host in C (dhcpctl.h)
> To: Users of ISC DHCP<dhcp-users at lists.isc.org>
> Message-ID:<1309298502.11298.10.camel at abehat.dyn.net.rm.dk>
> Content-Type: text/plain; charset="UTF-8"
>
> On Tue, 2011-06-28 at 18:35 +0530, Johnson koil Raj wrote:
>> I am working on dhcpd api by using dhcpctl.h. I am trying to assign
>> static IPs for machines when its hostname and mac-address was provided.
>> I have tried so far. When I tried to add a new host detail. The
>> mac-address alone not assigned properly. Some junk value it is giving.
>> The code what I have used is below.
> I don't want to sound harsh, but have you considered if you're really
> doing the right thing here? Trying to hack together some C code yourself
> can be dangerous if you don't master the basic concepts.
>
>>       dhcpctl_data_string macaddrstring = NULL;
>>       memset (&macaddrstring, 0, sizeof macaddrstring);
>>       omapi_data_string_new (&macaddrstring, 16, MDL);
>>       memcpy(macaddrstring->value, "00:0c:26:22:bf:c3", 16);
>>       status = dhcpctl_set_value (host, macaddrstring, "hardware-address");
>>
>> I am seeing following value in lease file.
>>
>> host testomapihost {
>>     dynamic;
>>     hardware ethernet 31:30:30:3a:30:63:3a:32:36:3a:32:32:3a:62:66:3a;
>>     fixed-address 192.168.10.123;
>> }
> This should give you the clue. Look at what the string "00:0c:26..."
> translates to in hex: "30 30 3a 30 63 3a 32 36 ...". That's probably not
> a coincidence.
>
> Looking closer at the lines above:
>
>       memcpy(macaddrstring->value, "00:0c:26:22:bf:c3", 16);
>
> That string isn't 16 bytes. It's 18 bytes including the terminating nul
> character. And keep in mind that "correcting" the length parameter will
> not help you.
>
>       status = dhcpctl_set_value (host, macaddrstring, "hardware-address");
>
> You probably want to use dhcpctl_set_string_value instead.
>
> Beware that you're probably in the process of creating a piece of
> software that you should never ever try to run as root on anything.


Please do not print this email unless it is absolutely necessary. 

The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. 

WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email. 

www.wipro.com



More information about the dhcp-users mailing list