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

jeffrey j donovan donovan at beth.k12.pa.us
Tue Jun 28 14:39:42 UTC 2011


On Jun 28, 2011, at 9:05 AM, Johnson koil Raj wrote:

> Hi All,
> 
>    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.
> 
>    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;
> }
> 
> Whether like ip address ( example provided in man page)  we need to convert mac-address also to any valid format. We can't pass the value just like string. What I am doing wrong. Any help will be grateful for me.
> 
> 
> Thanks,
> Johnson
> 

greetings
The host declaration is global irregardless of scope, so if you assign a static the pool won't matter. try matching from a class then you can at least assign a range for known hostnames


#first define the class lets say the clients hostname is " FOO21"

class "FOO" {
        match if substring (option host-name,0,3) = "FOO";        
}

next create a subnet with two pools, one for foo and the other for others :)

subnet 10.1.0.0 netmask 255.255.0.0 {

  	pool {
		allow members of "FOO";
		range 10.1.7.1 10.1.7.254;
		option routers 10.1.1.1;
		option domain-name-servers 10.1.1.21;
  		option domain-name "foo.com";
		}

	pool {
		deny members of "FOO";
  		range 10.1.12.1 10.135.12.254;
  		option routers 10.1.1.1;
  		option domain-name-servers 10.1.1.2;
  		option domain-name "nofoo.com";
  		
		}#close pool
}#close subnet

group {
		option routers 10.1.1.1;
		option domain-name-servers 10.1.1.21;
  		option domain-name "foo.com";
		host recon77 { fixed-address 10.1.1.77; hardware ethernet 00:21:77:df:b0:8c; }
		host fooprinter { fixed-address 10.1.1.78; hardware ethernet 00:21:ff:22:b9:3h; }
}#close group

#statics outside of group receive global
		host clientbob { fixed-address 10.1.1.79; hardware ethernet 00:21:gg:xf:34:8f; }
		host bobsstuff { fixed-address 10.1.1.80; hardware ethernet 00:21:aa:ff:b9:99; }


you may be able to embed into a pool only allowed by hostname foo.
ill have to try that.

reference thread
https://lists.isc.org/pipermail/dhcp-users/2006-September/001705.html





More information about the dhcp-users mailing list