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

📄 omapi.3

📁 DHCP服务器源码
💻 3
字号:
.\"	omapi.3.\".\" Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC").\" Copyright (c) 2000-2003 by Internet Software Consortium.\".\" 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/.\".\" This software has been written for Internet Systems Consortium.\" by Ted Lemon in cooperation with Vixie Enterprises and Nominum, Inc..\" To learn more about Internet Systems Consortium, see.\" ``http://www.isc.org/''.  To learn more about Vixie Enterprises,.\" see ``http://www.vix.com''.   To learn more about Nominum, Inc., see.\" ``http://www.nominum.com''..TH omapi 3.SH NAMEOMAPI - Object Management Application Programming Interface.SH DESCRIPTION.PPOMAPI is an programming layer designed for controlling remoteapplications, and for querying them for their state. It is currentlyused by the ISC DHCP server and this outline addresses the parts ofOMAPI appropriate to the clients of DHCP server. It does this by alsodescribing the use of a thin API layered on top of OMAPI called'dhcpctl'.PPOMAPI uses TCP/IP as the transport for server communication, andsecurity can be imposed by having the client and servercryptographically sign messages using a shared secret..PPdhcpctl works by presenting the client with handles to objects thatact as surrogates for the real objects in the server. For example aclient will create a handle for a lease object, and will request theserver to fill the lease handle's state. The client application canthen pull details such as the lease expiration time from the leasehandle. .PPModifications can be made to the server state by creating handles tonew objects, or by modifying attributes of handles to existingobjects, and then instructing the server to update itself according tothe changes made..SH USAGE.PPThe client application must always call dhcpctl_initialize() beforemaking calls to any other dhcpctl functions. This initializes various internal data structures. .PPTo create the connection to the server the client must usedhcpctl_connect() function. As well as making the physical connectionit will also set up the connection data structures to doauthentication on each message, if that is required..PPAll the dhcpctl functions return an integer value of typeisc_result_t. A successful call will yield a result ofISC_R_SUCCESS. If the call fails for a reason local to the client(e.g. insufficient local memory, or invalid arguments to the call)then the return value of the dhcpctl function will show that. If thecall succeeds but the server couldn't process the request the errorvalue from the server is returned through another way, shown below..PPThe easiest way to understand dhcpctl is to see it in action. Thefollowing program is fully functional, but almost all error checkinghas been removed to make is shorter and easier to understand. Thisprogram will query the server running on the localhost for the detailsof the lease for IP address 10.0.0.101. It will then print out the timethe lease ends..PP.nf		#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;.fi.PPAll modifications of handles and all accesses of handle data happenvia dhcpctl_data_string objects..PP.nf			dhcpctl_handle connection = NULL;			dhcpctl_handle lease = NULL;			isc_result_t waitstatus;			struct in_addr convaddr;			time_t thetime;			dhcpctl_initialize ();.fi.PPRequired first step..PP.nf			dhcpctl_connect (&connection, "127.0.0.1",					 7911, 0);.fi.PPSets up the connection to the server. The server normally listens onport 7911 unless configured to do otherwise..PP.nf			dhcpctl_new_object (&lease, connection,					    "lease");.fi.PPHere we create a handle to a lease. This call just sets up local datastructure. The server hasn't yet made any association between theclient's data structure and any lease it has..PP.nf			memset (&ipaddrstring, 0, sizeof				ipaddrstring);			inet_pton(AF_INET, "10.0.0.101",				  &convaddr);			omapi_data_string_new (&ipaddrstring,					       4, MDL);.fi.PPCreate a new data string to storing in the handle..PP.nf			memcpy(ipaddrstring->value, &convaddr.s_addr, 4);			dhcpctl_set_value (lease, ipaddrstring,					   "ip-address");.fi.PPWe're setting the ip-address attribute of the lease handle to thegiven address. We've not set any other attributes so when the servermakes the association the ip address will be all it uses to look upthe lease in its tables..PP.nf			dhcpctl_open_object (lease, connection, 0);.fi.PPHere we prime the connection with the request to look up the lease inthe server and fill up the local handle with the attributes the serverwill send over in its answer..PP.nf			dhcpctl_wait_for_completion (lease,						     &waitstatus);.fi.PPThis call causes the message to get sent to the server (the message tolook up the lease and send back the attribute values in theanswer). The value in the variable waitstatus when the functionreturns will be the result from the server. If the message couldnot be processed properly by the server then the error will bereflected here..PP.nf			if (waitstatus != ISC_R_SUCCESS) {				/* server not authoritative */				exit (0);			}			dhcpctl_data_string_dereference(&ipaddrstring,							MDL);.fi.PPClean-up memory we no longer need..PP.nf			dhcpctl_get_value (&value, lease, "ends");.fi.PPGet the attribute named ``ends'' from the lease handle. This is a4-byte integer of the time (in unix epoch seconds) that the leasewill expire..PP.nf				memcpy(&thetime, value->value, value->len);			dhcpctl_data_string_dereference(&value, MDL);			fprintf (stdout, "ending time is %s",				 ctime(&thetime));		}.fi.SH AUTHENTICATIONIf the server demands authenticated connections then before openingthe connection the user must call dhcpctl_new_authenticator..PP.nf		dhcpctl_handle authenticator = NULL;		const char *keyname = "a-key-name";		const char *algorithm = "hmac-md5";		const char *secret = "a-shared-secret";		dhcpctl_new_authenticator (&authenticator,                                            keyname,                                           algorithm,                                           secret,					   strlen(secret) + 1);.fi.PPThe keyname, algorithm and secret must all match what is specified inthe server's dhcpd.conf file:.PP.nf		key "a-key-name" {			algorithm hmac-md5;			secret "a-shared-secret";		};		# Set the omapi-key value to use		# authenticated connections		omapi-key "a-key-name";.fi.PPThe authenticator handle that is created by the call todhcpctl_new_authenticator must be given as the last (the 4th) argumentto the call to dhcpctl_connect(). All messages will then be signedwith the given secret string using the specified algorithm..SH SEE ALSOdhcpctl(3), omapi(3), dhcpd(8), dhclient(8), dhcpd.conf(5), dhclient.conf(5)..SH AUTHOR.B omapiwas created by Ted Lemon of Nominum, Inc.  Information about Nominumand support contracts for DHCP and BIND can be found at.B http://www.nominum.com.   This documentation was written by JamesBrister of Nominum, Inc. 

⌨️ 快捷键说明

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