⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dhcpctl.3

📁 DHCP服务器源码
💻 3
字号:
.\" -*- nroff -*-.\".\" Project:      DHCP.\" File:         dhcpctl.3.\" RCSId:        $Id: dhcpctl.3,v 1.3.2.4 2004/06/10 17:59:23 dhankins Exp $.\" .\" Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC").\" Copyright (c) 2000-2003 by Internet Software Consortium.\" Copyright (c) 2000 Nominum, Inc..\".\" Permission to use, copy, modify, and distribute this software for any.\" purpose with or without fee is hereby granted, provided that the above.\" copyright notice and this permission notice appear in all copies..\".\" THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF.\" MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT.\" OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE..\".\"   Internet Systems Consortium, Inc..\"   950 Charter Street.\"   Redwood City, CA 94063.\"   <info@isc.org>.\"   http://www.isc.org/.\"     .\" Description:	dhcpctl man page..\" .\".Dd Nov 15, 2000.Dt DHCPCTL 3.Os DHCP 3.ds vT DHCP Programmer's Manual.\".\".\".Sh NAME.Nm dhcpctl_initialize.Nd dhcpctl library initialization..\".\".\".Sh SYNOPSIS.Fd #include <dhcpctl/dhcpctl.h>.Ft dhcpctl_status.Fo dhcpctl_initialize.Fa void.Fc.\".Ft dhcpctl_status.Fo dhcpctl_connect.Fa "dhcpctl_handle *cxn".Fa "const char *host".Fa "int port".Fa "dhcpctl_handle auth".Fc.\".\".\".Ft dhcpctl_status.Fo dhcpctl_wait_for_completion.Fa "dhcpctl_handle object".Fa "dhcpctl_status *status".Fc.\".\".\".Ft dhcpctl_status.Fo dhcpctl_get_value.Fa "dhcpctl_data_string *value".Fa "dhcpctl_handle object".Fa "const char *name".Fc.\".\".\".Ft dhcpctl_status.Fo dhcpctl_get_boolean.Fa "int *value".Fa "dhcpctl_handle object".Fa "const char *name".Fc.\".\".\".Ft dhcpctl_status.Fo dhcpctl_set_value.Fa "dhcpctl_handle object".Fa "dhcpctl_data_string value".Fa "const char *name".Fc.\".\".\".Ft dhcpctl_status.Fo dhcpctl_set_string_value.Fa "dhcpctl_handle object".Fa "const char *value".Fa "const char *name".Fc.\".\".\".Ft dhcpctl_status.Fo dhcpctl_set_boolean_value.Fa "dhcpctl_handle object".Fa "int value".Fa "const char *name".Fc.\".\".\".Ft dhcpctl_status.Fo dhcpctl_set_int_value.Fa "dhcpctl_handle object".Fa "int value".Fa "const char *name".Fc.\".\".\".Ft dhcpctl_status.Fo dhcpctl_object_update.Fa "dhcpctl_handle connection".Fa "dhcpctl_handle object".Fc.\".\".\".Ft dhcpctl_status.Fo dhcpctl_object_refresh.Fa "dhcpctl_handle connection".Fa "dhcpctl_handle object".Fc.\".\".\".Ft dhcpctl_status.Fo dhcpctl_object_remove.Fa "dhcpctl_handle connection".Fa "dhcpctl_handle object".Fc.\".\".\".Ft dhcpctl_status.Fo dhcpctl_set_callback.Fa "dhcpctl_handle object".Fa "void *data".Fa "void (*function) (dhcpctl_handle, dhcpctl_status, void *)".Fc.\".\".\".Ft dhcpctl_status.Fo dhcpctl_new_authenticator.Fa "dhcpctl_handle *object".Fa "const char *name".Fa "const char *algorithm".Fa "const char *secret".Fa "unsigned secret_len".Fc.\".\".\".Ft dhcpctl_status.Fo dhcpctl_new_object.Fa "dhcpctl_handle *object".Fa "dhcpctl_handle connection".Fa "const char *object_type".Fc.\".\".\".Ft dhcpctl_status.Fo dhcpctl_open_object.Fa "dhcpctl_handle object".Fa "dhcpctl_handle connection".Fa "int flags".Fc.\".\".\".Ft isc_result_t.Fo omapi_data_string_new.Fa dhcpctl_data_string *data.Fa unsigned int length.Fa const char *filename,.Fa int lineno.Fc.\".\".\".Ft isc_result_t.Fo dhcpctl_data_string_dereference.Fa "dhcpctl_data_string *".Fa "const char *".Fa "int".Fc.Sh DESCRIPTIONThe dhcpctl set of functions provide an API that can be used to communicatewith and manipulate a running ISC DHCP server. All functions return a value of.Dv isc_result_t .The return values reflects the result of operations to local datastructures. If an operation fails on the server for any reason, then the errorresult will be returned through thesecond parameter of the .Fn dhcpctl_wait_for_completion call..\".\".\".Pp.Fn dhcpctl_initializesets up the data structures the library needs to do its work. This functionmust be called once before any other..Pp.Fn dhcpctl_connectopens a connection to the DHCP server at the given host and port. If anauthenticator has been created for the connection, then it is given as the 4thargument. On a successful return the address pointed at by the firstargument will have a new connection object assigned to it..PpFor example:.Bd -literal -offset indents = dhcpctl_connect(&cxn, "127.0.0.1", 7911, NULL);.Ed.Ppconnects to the DHCP server on the localhost via port 7911 (the standardOMAPI port). No authentication is used for the connection..\".\".\".Pp.Fn dhcpctl_wait_for_completionflushes a pending message to the server and waits for the response. The resultof the request as processed on the server is returned via the secondparameter..Bd -literal -offset indents = dhcpctl_wait_for_completion(cxn, &wv);if (s != ISC_R_SUCCESS) 	local_failure(s);else if (wv != ISC_R_SUCCESS)	server_failure(wc);.Ed.PpThe call to .Fn dhcpctl_wait_for_completionwon't return until the remote message processing completes or the connectionto the server is lost..\".\".\".Pp.Fn dhcpctl_get_valueextracts a value of an attribute from the handle. The value can be of anylength and is treated as a sequence of bytes.  The handle must have beencreated first with.Fn dhcpctl_new_objectand opened with.Fn dhcpctl_open_object .The value is returned via the parameter named.Dq value .The last parameter is the name of attribute to retrieve..Bd -literal -offset indentdhcpctl_data_string value = NULL;dhcpctl_handle lease;time_t thetime;s = dhcpctl_get_value (&value, lease, "ends");assert(s == ISC_R_SUCCESS && value->len == sizeof(thetime));memcpy(&thetime, value->value, value->len);.Ed.\".\".\".Pp.Fn dhcpctl_get_booleanextracts a boolean valued attribute from the object handle..\".\".\".PpThe.Fn dhcpctl_set_value ,.Fn dhcpctl_set_string_value ,.Fn dhcpctl_set_boolean_value ,and.Fn dhcpctl_set_int_valuefunctions all set a value on the object handle. .\".\".\".Pp.Fn dhcpctl_object_updatefunction queues a request forall the changes made to the object handle be be sent to the remotefor processing. The changes made to the atributes on the handle will beapplied to remote object if permitted..\".\".\".Pp.Fn dhcpctl_object_refreshqueues up a request for a fresh copy of all the attribute values to be sentfrom the remote torefresh the values in the local object handle..\".\".\".Pp.Fn dhcpctl_object_removequeues a request for the removal on the server of the object referenced by thehandle..\".\".\".PpThe .Fn dhcpctl_set_callbackfunction sets up a user-defined function to be called when an event completeson the given object handle. This is needed for asynchronous handling ofevents, versus the synchronous handling given by.Fn dhcpctl_wait_for_completion .When the function is called the first parameter is the object the eventarrived for, the second is the status of the message that was processed, thethird is the same value as the second parameter given to .Fn dhcpctl_set_callback ..\".\".\".PpThe .Fn dhcpctl_new_authenticatorcreates a new authenticator object to be used for signing the messagesthat cross over the network. The .Dq name ,.Dq algorithm ,and .Dq secretvalues must all match what the server uses and are defined in itsconfiguration file. The created object is returned through the first parameterand must be used as the 4th parameter to .Fn dhcpctl_connect ..\".\".\".Pp.Fn dhcpctl_new_objectcreates a local handle for an object on the the server. The .Dq object_typeparameter is the ascii name of the type of object being accessed. e.g. .Qq lease .This function only sets up local data structures, it does not queue any messagesto be sent to the remote side,.Fn dhcpctl_open_objectdoes that..\".\".\".Pp.Fn dhcpctl_open_objectbuilds and queues the request to the remote side. This function is used withhandle created via.Fn dhcpctl_new_object .The flags argument is a bit mask with the following values available forsetting:.Bl -tag -offset indent -width 20.It DHCPCTL_CREATEif the object does not exist then the remote will create it.It DHCPCTL_UPDATEupdate the object on the remote side using theattributes already set in the handle..It DHCPCTL_EXCLreturn and error if the object exists and DHCPCTL_CREATEwas also specified.El.\".\".\".PpThe .Fn omapi_data_string_newfunction allocates a new.Ft dhcpctl_data_stringobject. The data string will be large enough to hold .Dq lengthbytes of data. The.Dq file and.Dq linenoarguments are the source file location the call is made from, typically byusing the .Dv __FILE__and.Dv __LINE__macros or the .Dv MDLmacro defined in..\".\".\".Pp.Fn dhcpctl_data_string_dereferencedeallocates a data string created by.Fn omapi_data_string_new .The memory for the object won't be freed until the last reference isreleased..Sh EXAMPLES.Pp The following program will connect to the DHCP server running on the localhost and will get the details of the existing lease for IP address10.0.0.101. It will then print out the time the lease is due to expire. Notethat most error checking has been ommitted for brevity..Bd -literal -offset indent#include <stdarg.h>#include <sys/time.h>#include <sys/socket.h>#include <stdio.h>#include <netinet/in.h>#include <isc/result.h>#include <dhcpctl/dhcpctl.h>int main (int argc, char **argv) {	dhcpctl_data_string ipaddrstring = NULL;	dhcpctl_data_string value = NULL;	dhcpctl_handle connection = NULL;	dhcpctl_handle lease = NULL;	isc_result_t waitstatus;	struct in_addr convaddr;	time_t thetime;        dhcpctl_initialize ();        dhcpctl_connect (&connection, "127.0.0.1",			 7911, 0);	        dhcpctl_new_object (&lease, connection,			    "lease");        memset (&ipaddrstring, 0, sizeof		ipaddrstring);        inet_pton(AF_INET, "10.0.0.101",		  &convaddr);	omapi_data_string_new (&ipaddrstring,			       4, MDL);	memcpy(ipaddrstring->value, &convaddr.s_addr, 4);	dhcpctl_set_value (lease, ipaddrstring,			   "ip-address");	dhcpctl_open_object (lease, connection, 0);	dhcpctl_wait_for_completion (lease,				     &waitstatus);        if (waitstatus != ISC_R_SUCCESS) {		/* server not authoritative */		exit (0);        }	dhcpctl_data_string_dereference(&ipaddrstring,					MDL);        dhcpctl_get_value (&value, lease, "ends");	memcpy(&thetime, value->value, value->len);	dhcpctl_data_string_dereference(&value, MDL);	fprintf (stdout, "ending time is %s",		 ctime(&thetime));}.Ed.Sh SEE ALSOomapi(3), omshell(3), dhcpd(8), dhclient(8), dhcpd.conf(5), dhclient.conf(5)..Sh AUTHOR.Em dhcpctlwas written by Ted Lemon of Nominum, Inc.This preliminary documentation was written by James Brister of Nominum, Inc.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -