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

📄 discover.c

📁 DHCP服务器源码
💻 C
📖 第 1 页 / 共 3 页
字号:
	if (result == 0)		return ISC_R_UNEXPECTED;	/* If we didn't at least get the fixed portion of the BOOTP	   packet, drop the packet.  We're allowing packets with no	   sname or filename, because we're aware of at least one	   client that sends such packets, but this definitely falls	   into the category of being forgiving. */	if (result < DHCP_FIXED_NON_UDP - DHCP_SNAME_LEN - DHCP_FILE_LEN)		return ISC_R_UNEXPECTED;	if (bootp_packet_handler) {		ifrom.len = 4;		memcpy (ifrom.iabuf, &from.sin_addr, ifrom.len);		(*bootp_packet_handler) (ip, &u.packet, (unsigned)result,					 from.sin_port, ifrom, &hfrom);	}	/* If there is buffered data, read again.    This is for, e.g.,	   bpf, which may return two packets at once. */	if (ip -> rbuf_offset != ip -> rbuf_len)		goto again;	return ISC_R_SUCCESS;}isc_result_t dhcp_interface_set_value  (omapi_object_t *h,					omapi_object_t *id,					omapi_data_string_t *name,					omapi_typed_data_t *value){	struct interface_info *interface;	isc_result_t status;	int foo;	if (h -> type != dhcp_type_interface)		return ISC_R_INVALIDARG;	interface = (struct interface_info *)h;	if (!omapi_ds_strcmp (name, "name")) {		if ((value -> type == omapi_datatype_data ||		     value -> type == omapi_datatype_string) &&		    value -> u.buffer.len < sizeof interface -> name) {			memcpy (interface -> name,				value -> u.buffer.value,				value -> u.buffer.len);			interface -> name [value -> u.buffer.len] = 0;		} else			return ISC_R_INVALIDARG;		return ISC_R_SUCCESS;	}	/* Try to find some inner object that can take the value. */	if (h -> inner && h -> inner -> type -> set_value) {		status = ((*(h -> inner -> type -> set_value))			  (h -> inner, id, name, value));		if (status == ISC_R_SUCCESS || status == ISC_R_UNCHANGED)			return status;	}			  	return ISC_R_NOTFOUND;}isc_result_t dhcp_interface_get_value (omapi_object_t *h,				       omapi_object_t *id,				       omapi_data_string_t *name,				       omapi_value_t **value){	return ISC_R_NOTIMPLEMENTED;}isc_result_t dhcp_interface_destroy (omapi_object_t *h,					 const char *file, int line){	struct interface_info *interface;	isc_result_t status;	if (h -> type != dhcp_type_interface)		return ISC_R_INVALIDARG;	interface = (struct interface_info *)h;	if (interface -> ifp) {		dfree (interface -> ifp, file, line);		interface -> ifp = 0;	}	if (interface -> next)		interface_dereference (&interface -> next, file, line);	if (interface -> rbuf) {		dfree (interface -> rbuf, file, line);		interface -> rbuf = (unsigned char *)0;	}	if (interface -> client)		interface -> client = (struct client_state *)0;	if (interface -> shared_network)		omapi_object_dereference ((omapi_object_t **)					  &interface -> shared_network, MDL);	return ISC_R_SUCCESS;}isc_result_t dhcp_interface_signal_handler (omapi_object_t *h,					    const char *name, va_list ap){	struct interface_info *ip, *interface;	struct client_config *config;	struct client_state *client;	isc_result_t status;	if (h -> type != dhcp_type_interface)		return ISC_R_INVALIDARG;	interface = (struct interface_info *)h;	/* If it's an update signal, see if the interface is dead right	   now, or isn't known at all, and if that's the case, revive it. */	if (!strcmp (name, "update")) {		for (ip = dummy_interfaces; ip; ip = ip -> next)			if (ip == interface)				break;		if (ip && dhcp_interface_startup_hook)			return (*dhcp_interface_startup_hook) (ip);		for (ip = interfaces; ip; ip = ip -> next)			if (ip == interface)				break;		if (!ip && dhcp_interface_startup_hook)			return (*dhcp_interface_startup_hook) (ip);	}	/* Try to find some inner object that can take the value. */	if (h -> inner && h -> inner -> type -> get_value) {		status = ((*(h -> inner -> type -> signal_handler))			  (h -> inner, name, ap));		if (status == ISC_R_SUCCESS)			return status;	}	return ISC_R_NOTFOUND;}isc_result_t dhcp_interface_stuff_values (omapi_object_t *c,					  omapi_object_t *id,					  omapi_object_t *h){	struct interface_info *interface;	isc_result_t status;	if (h -> type != dhcp_type_interface)		return ISC_R_INVALIDARG;	interface = (struct interface_info *)h;	/* Write out all the values. */	status = omapi_connection_put_name (c, "state");	if (status != ISC_R_SUCCESS)		return status;	if (interface -> flags && INTERFACE_REQUESTED)	    status = omapi_connection_put_string (c, "up");	else	    status = omapi_connection_put_string (c, "down");	if (status != ISC_R_SUCCESS)		return status;	/* Write out the inner object, if any. */	if (h -> inner && h -> inner -> type -> stuff_values) {		status = ((*(h -> inner -> type -> stuff_values))			  (c, id, h -> inner));		if (status == ISC_R_SUCCESS)			return status;	}	return ISC_R_SUCCESS;}isc_result_t dhcp_interface_lookup (omapi_object_t **ip,				    omapi_object_t *id,				    omapi_object_t *ref){	omapi_value_t *tv = (omapi_value_t *)0;	isc_result_t status;	struct interface_info *interface;	if (!ref)		return ISC_R_NOKEYS;	/* First see if we were sent a handle. */	status = omapi_get_value_str (ref, id, "handle", &tv);	if (status == ISC_R_SUCCESS) {		status = omapi_handle_td_lookup (ip, tv -> value);		omapi_value_dereference (&tv, MDL);		if (status != ISC_R_SUCCESS)			return status;		/* Don't return the object if the type is wrong. */		if ((*ip) -> type != dhcp_type_interface) {			omapi_object_dereference (ip, MDL);			return ISC_R_INVALIDARG;		}	}	/* Now look for an interface name. */	status = omapi_get_value_str (ref, id, "name", &tv);	if (status == ISC_R_SUCCESS) {		char *s;		unsigned len;		for (interface = interfaces; interface;		     interface = interface -> next) {		    s = memchr (interface -> name, 0, IFNAMSIZ);		    if (s)			    len = s - &interface -> name [0];		    else			    len = IFNAMSIZ;		    if ((tv -> value -> u.buffer.len == len &&			 !memcmp (interface -> name,				  (char *)tv -> value -> u.buffer.value,				  len)))			    break;		}		if (!interface) {		    for (interface = dummy_interfaces;			 interface; interface = interface -> next) {			    s = memchr (interface -> name, 0, IFNAMSIZ);			    if (s)				    len = s - &interface -> name [0];			    else				    len = IFNAMSIZ;			    if ((tv -> value -> u.buffer.len == len &&				 !memcmp (interface -> name,					  (char *)					  tv -> value -> u.buffer.value,					  len)))				    break;		    }		}		omapi_value_dereference (&tv, MDL);		if (*ip && *ip != (omapi_object_t *)interface) {			omapi_object_dereference (ip, MDL);			return ISC_R_KEYCONFLICT;		} else if (!interface) {			if (*ip)				omapi_object_dereference (ip, MDL);			return ISC_R_NOTFOUND;		} else if (!*ip)			omapi_object_reference (ip,						(omapi_object_t *)interface,						MDL);	}	/* If we get to here without finding an interface, no valid key was	   specified. */	if (!*ip)		return ISC_R_NOKEYS;	return ISC_R_SUCCESS;}/* actually just go discover the interface */isc_result_t dhcp_interface_create (omapi_object_t **lp,				    omapi_object_t *id){ 	struct interface_info *hp;	isc_result_t status;		hp = (struct interface_info *)0;	status = interface_allocate (&hp, MDL); 	if (status != ISC_R_SUCCESS)		return status; 	hp -> flags = INTERFACE_REQUESTED;	status = interface_reference ((struct interface_info **)lp, hp, MDL);	interface_dereference (&hp, MDL);	return status;}isc_result_t dhcp_interface_remove (omapi_object_t *lp,				    omapi_object_t *id){ 	struct interface_info *interface, *ip, *last;	interface = (struct interface_info *)lp;	/* remove from interfaces */	last = 0;	for (ip = interfaces; ip; ip = ip -> next) {		if (ip == interface) {			if (last) {				interface_dereference (&last -> next, MDL);				if (ip -> next)					interface_reference (&last -> next,							     ip -> next, MDL);			} else {				interface_dereference (&interfaces, MDL);				if (ip -> next)					interface_reference (&interfaces,							     ip -> next, MDL);			}			if (ip -> next)				interface_dereference (&ip -> next, MDL);			break;		}		last = ip;	}	if (!ip)		return ISC_R_NOTFOUND;	/* add the interface to the dummy_interface list */	if (dummy_interfaces) {		interface_reference (&interface -> next,				     dummy_interfaces, MDL);		interface_dereference (&dummy_interfaces, MDL);	}	interface_reference (&dummy_interfaces, interface, MDL);	/* do a DHCPRELEASE */	if (dhcp_interface_shutdown_hook)		(*dhcp_interface_shutdown_hook) (interface);	/* remove the io object */	omapi_unregister_io_object ((omapi_object_t *)interface);	if_deregister_send (interface);	if_deregister_receive (interface);	return ISC_R_SUCCESS;}void interface_stash (struct interface_info *tptr){	struct interface_info **vec;	int delta;	/* If the registerer didn't assign an index, assign one now. */	if (tptr -> index == -1) {		tptr -> index = interface_count++;		while (tptr -> index < interface_max &&		       interface_vector [tptr -> index])			tptr -> index = interface_count++;	}	if (interface_max <= tptr -> index) {		delta = tptr -> index - interface_max + 10;		vec = dmalloc ((interface_max + delta) *			       sizeof (struct interface_info *), MDL);		if (!vec)			return;		memset (&vec [interface_max], 0,			(sizeof (struct interface_info *)) * delta);		interface_max += delta;		if (interface_vector) {		    memcpy (vec, interface_vector,			    (interface_count *			     sizeof (struct interface_info *)));		    dfree (interface_vector, MDL);		}		interface_vector = vec;	}	interface_reference (&interface_vector [tptr -> index], tptr, MDL);	if (tptr -> index >= interface_count)		interface_count = tptr -> index + 1;#if defined (TRACING)	trace_interface_register (interface_trace, tptr);#endif}void interface_snorf (struct interface_info *tmp, int ir){	tmp -> circuit_id = (u_int8_t *)tmp -> name;	tmp -> circuit_id_len = strlen (tmp -> name);	tmp -> remote_id = 0;	tmp -> remote_id_len = 0;	tmp -> flags = ir;	if (interfaces) {		interface_reference (&tmp -> next,				     interfaces, MDL);		interface_dereference (&interfaces, MDL);	}	interface_reference (&interfaces, tmp, MDL);}

⌨️ 快捷键说明

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