FreeBSD/sys/dev/hyperv/utilities/hv_kvp.c
/*
 * Convert ip related info in hmsg from utf16 to utf8 and store in umsg
 */
Convert ip related info in hmsg from utf16 to utf8 and store in umsg
Convert ip related info in hmsg from utf16 to utf8 and store in umsg
static int
hv_kvp_convert_utf16_ipinfo_to_utf8(struct hv_kvp_ip_msg *host_ip_msg,
				    struct hv_kvp_msg *umsg)
{
	int err_ip, err_subnet, err_gway, err_dns, err_adap;
	int UNUSED_FLAG = 1;
	struct hv_device *hv_dev;       
	hn_softc_t *sc;                 
	char buf[HYPERV_GUID_STRLEN];
	device_t *devs;
	int devcnt;
	utf16_to_utf8((char *)umsg->body.kvp_ip_val.ip_addr,
	    MAX_IP_ADDR_SIZE,
	    (uint16_t *)host_ip_msg->kvp_ip_val.ip_addr,
	    MAX_IP_ADDR_SIZE,
	    UNUSED_FLAG,
	    &err_ip);
	utf16_to_utf8((char *)umsg->body.kvp_ip_val.adapter_id,
	    MAX_ADAPTER_ID_SIZE,
	    (uint16_t *)host_ip_msg->kvp_ip_val.adapter_id,
	    MAX_ADAPTER_ID_SIZE,
	    UNUSED_FLAG,
	    &err_adap);
	if (devclass_get_devices(devclass_find("hn"), &devs, &devcnt) == 0) {
		for (devcnt = devcnt - 1; devcnt >= 0; devcnt--) {
			sc = device_get_softc(devs[devcnt]);
			hv_dev = sc->hn_dev_obj;
			hyperv_guid2str(&hv_dev->device_id, buf, sizeof(buf));
			if (strncmp(buf, (char *)umsg->body.kvp_ip_val.adapter_id,
			    HYPERV_GUID_STRLEN - 1) == 0) {
				strlcpy((char *)umsg->body.kvp_ip_val.adapter_id,
				    sc->hn_ifp->if_xname, MAX_ADAPTER_ID_SIZE);
				break;
			}
		}
		free(devs, M_TEMP);
	}
	umsg->kvp_hdr.operation = host_ip_msg->operation;
	umsg->body.kvp_ip_val.addr_family = host_ip_msg->kvp_ip_val.addr_family;
	umsg->body.kvp_ip_val.dhcp_enabled = host_ip_msg->kvp_ip_val.dhcp_enabled;
	utf16_to_utf8((char *)umsg->body.kvp_ip_val.sub_net, MAX_IP_ADDR_SIZE,
	    (uint16_t *)host_ip_msg->kvp_ip_val.sub_net,
	    MAX_IP_ADDR_SIZE,
	    UNUSED_FLAG,
	    &err_subnet);
	utf16_to_utf8((char *)umsg->body.kvp_ip_val.gate_way, MAX_GATEWAY_SIZE,
	    (uint16_t *)host_ip_msg->kvp_ip_val.gate_way,
	    MAX_GATEWAY_SIZE,
	    UNUSED_FLAG,
	    &err_gway);
	utf16_to_utf8((char *)umsg->body.kvp_ip_val.dns_addr, MAX_IP_ADDR_SIZE,
	    (uint16_t *)host_ip_msg->kvp_ip_val.dns_addr,
	    MAX_IP_ADDR_SIZE,
	    UNUSED_FLAG,
	    &err_dns);
	return (err_ip | err_subnet | err_gway | err_dns | err_adap);
}
static int hv_kvp_convert_utf16_ipinfo_to_utf8 ( struct hv_kvp_ip_msg * host_ip_msg , struct hv_kvp_msg * umsg ) { int err_ip , err_subnet , err_gway , err_dns , err_adap ; int UNUSED_FLAG = 1 ; struct hv_device * hv_dev ; hn_softc_t * sc ; char buf [ HYPERV_GUID_STRLEN ] ; device_t * devs ; int devcnt ; utf16_to_utf8 ( ( char * ) umsg -> body . kvp_ip_val . ip_addr , MAX_IP_ADDR_SIZE , ( uint16_t * ) host_ip_msg -> kvp_ip_val . ip_addr , MAX_IP_ADDR_SIZE , UNUSED_FLAG , & err_ip ) ; utf16_to_utf8 ( ( char * ) umsg -> body . kvp_ip_val . adapter_id , MAX_ADAPTER_ID_SIZE , ( uint16_t * ) host_ip_msg -> kvp_ip_val . adapter_id , MAX_ADAPTER_ID_SIZE , UNUSED_FLAG , & err_adap ) ; if ( devclass_get_devices ( devclass_find ( " " ) , & devs , & devcnt ) == 0 ) { for ( devcnt = devcnt - 1 ; devcnt >= 0 ; devcnt -- ) { sc = device_get_softc ( devs [ devcnt ] ) ; hv_dev = sc -> hn_dev_obj ; hyperv_guid2str ( & hv_dev -> device_id , buf , sizeof ( buf ) ) ; if ( strncmp ( buf , ( char * ) umsg -> body . kvp_ip_val . adapter_id , HYPERV_GUID_STRLEN - 1 ) == 0 ) { strlcpy ( ( char * ) umsg -> body . kvp_ip_val . adapter_id , sc -> hn_ifp -> if_xname , MAX_ADAPTER_ID_SIZE ) ; break ; } } free ( devs , M_TEMP ) ; } umsg -> kvp_hdr . operation = host_ip_msg -> operation ; umsg -> body . kvp_ip_val . addr_family = host_ip_msg -> kvp_ip_val . addr_family ; umsg -> body . kvp_ip_val . dhcp_enabled = host_ip_msg -> kvp_ip_val . dhcp_enabled ; utf16_to_utf8 ( ( char * ) umsg -> body . kvp_ip_val . sub_net , MAX_IP_ADDR_SIZE , ( uint16_t * ) host_ip_msg -> kvp_ip_val . sub_net , MAX_IP_ADDR_SIZE , UNUSED_FLAG , & err_subnet ) ; utf16_to_utf8 ( ( char * ) umsg -> body . kvp_ip_val . gate_way , MAX_GATEWAY_SIZE , ( uint16_t * ) host_ip_msg -> kvp_ip_val . gate_way , MAX_GATEWAY_SIZE , UNUSED_FLAG , & err_gway ) ; utf16_to_utf8 ( ( char * ) umsg -> body . kvp_ip_val . dns_addr , MAX_IP_ADDR_SIZE , ( uint16_t * ) host_ip_msg -> kvp_ip_val . dns_addr , MAX_IP_ADDR_SIZE , UNUSED_FLAG , & err_dns ) ; return ( err_ip | err_subnet | err_gway | err_dns | err_adap ) ; }
Convert ip related info in hmsg from utf16 to utf8 and store in umsg
Convert ip related info in hmsg from utf16 to utf8 and store in umsg
/* GUID Data Structure */ /* hn softc structure  */ /* IP Address */ /* Adapter ID : GUID */ /* Trying to find GUID of Network Device */ /* Address Family , DHCP , SUBNET, Gateway, DNS */