About DhcpGetClientInfoV6 function in dhcpsapi.h

陶海洋 0 Reputation points
2024-12-09T08:15:46.13+00:00

When I used the DhcpGetClientInfoV6 function in dhcpsapi.h, it returned code 2. After searching, I found the content, but I couldn't understand it.


$ .\Err_6.4.5.exe 2             

# for hex 0x2 / decimal 2 

  BTH_ERROR_NO_CONNECTION                                        bthdef.h 

  DEVICE_QUEUE_NOT_BUSY                                          bugcodes.h 

  CDERR_INITIALIZATION                                           cderr.h 

  CR_OUT_OF_MEMORY                                               cfgmgr32.h 

  DHCP_DROP_NOMEM                                                dhcpssdk.h 

  MD_ERROR_SUB400_INVALID_DEPTH                                  iiscnfg.h 

  MD_ERROR_SUB401_LOGON_CONFIG                                   iiscnfg.h 

  MD_ERROR_SUB403_READ_ACCESS_DENIED                             iiscnfg.h 

  MD_ERROR_SUB404_DENIED_BY_POLICY                               iiscnfg.h 

  MD_ERROR_SUB423_NO_CONFLICTING_LOCK                            iiscnfg.h 

  MD_ERROR_SUB502_PREMATURE_EXIT                                 iiscnfg.h 

  MD_ERROR_SUB503_APP_CONCURRENT                                 iiscnfg.h 

  IME_RS_NOIME                                                   ime.h 

# IME is not installed 

  RSVP_Err_POLICY                                                lpmapi.h 

  RSVP_Erv_Bandwidth                                             lpmapi.h 

# /* Insufficient bandwidth   */ 

  RSVP_Erv_No_Serv                                               lpmapi.h 

# /* Unknown Service      */ 

  RSVP_Erv_API                                                   lpmapi.h 

# /* API logic error */ 

  POLICY_ERRV_UNSUPPORTED_CREDENTIAL_TYPE                        lpmapi.h 

  POLICY_ERRV_GLOBAL_GRP_FLOW_COUNT                              lpmapi.h 

  MSIDBERROR_REQUIRED                                            msiquery.h 

# non-nullable column no null values allowed 

  NMERR_INVALID_HFILTER                                          netmon.h 

  SMART_INVALID_FLAG                                             ntdddisk.h 

# Invalid command flag 

  DS_NAME_ERROR_NOT_FOUND                                        ntdsapi.h 

  STATUS_WAIT_2                                                  ntstatus.h 

  ODBC_ERROR_INVALID_BUFF_LEN                                    odbcinst.h 

  MSDRI_S_MMI_PENDING                                            pbdaerrors.h 

  MFE_NOT_FORWARDING                                             routprot.h 

# not fwding for an unspecified reason 

  SCESTATUS_RECORD_NOT_FOUND                                     scesvc.h 

  SE_ERR_FNF                                                     shellapi.h 

# file not found 

  SNMP_ERRORSTATUS_NOSUCHNAME                                    snmp.h 

  SNMP_GENERICTRAP_LINKDOWN                                      snmp.h 

  ICERR_NEWPALETTE                                               vfw.h 

  WDSMCCLIENT_CATEGORY                                           wdsmcerr.h 

# WDS Multicast Client 

  WINBIO_FP_TOO_LOW                                              winbio_err.h 

# Position your finger higher on the fingerprint reader. 

  CMC_STATUS_FAILED                                              wincrypt.h 

  CMC_FAIL_BAD_REQUEST                                           wincrypt.h 

  DRM_S_MORE_DATA                                                windowsplayready.h 

  ERROR_FILE_NOT_FOUND                                           winerror.h 

# The system cannot find the file specified. 

  ERROR_LABEL_QUESTIONABLE                                       winioctl.h 

# Label could be invalid due to unit attention condition. 

  LDAP_PROTOCOL_ERROR                                            winldap.h 

  SNMP_ERROR_NOSUCHNAME                                          winsnmp.h 

# as an HRESULT: Severity: SUCCESS (0), FACILITY_NONE (0x0), Code 0x2 

# for hex 0x2 / decimal 2 

  WINBIO_FP_TOO_LOW                                              winbio_err.h 

# Position your finger higher on the fingerprint reader. 

# as an HRESULT: Severity: SUCCESS (0), FACILITY_NULL (0x0), Code 0x2 

  ERROR_FILE_NOT_FOUND                                           winerror.h 

# The system cannot find the file specified. 

# 43 matches found for "2"

The possible code is ERROR_FILE_NOT_FOUND in winerror.h.

However, after I changed the corresponding code in winerror.h and recompiled, the return code was still 2. I can't determine where the problem occurred. Please help.

This my code:


std::string LookupIPv6(const std::string& ip) {

	struct in6_addr addr;

	if (inet_pton(AF_INET6, ip.c_str(), &addr) != 1) {

		throw std::invalid_argument("Invalid IPv6 address");

	}

	DHCP_SEARCH_INFO_V6 query;

	ZeroMemory(&query, sizeof(query));

	query.SearchType = Dhcpv6ClientIpAddress;

	memcpy(&query.SearchInfo.ClientIpAddress, &addr, sizeof(addr));

	LPDHCP_CLIENT_INFO_V6 result = nullptr;

	DWORD ret = DhcpGetClientInfoV6(nullptr, &query, &result);

	if (ret != ERROR_SUCCESS || !result) {

		FreeClientInfoMemoryV6(result);

		throw std::runtime_error("Failed to get DHCP client info, error code: " + std::to_string(ret));

	}

	char mac[64];

	BYTE* macData = result->ClientDUID.Data;

	snprintf(mac, sizeof(mac), "%02x:%02x:%02x:%02x:%02x:%02x",

		macData[0], macData[1], macData[2], macData[3], macData[4], macData[5]);

	FreeClientInfoMemoryV6(result);

	return std::string(mac);

}

Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
13,467 questions
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,700 questions
Windows DHCP
Windows DHCP
Windows: A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.DHCP: Dynamic Host Configuration Protocol (DHCP). A communications protocol that lets network administrators manage centrally and automate the assignment of Internet Protocol (IP) addresses in an organization's network.
1,044 questions
{count} votes

1 answer

Sort by: Most helpful
  1. 陶海洋 0 Reputation points
    2024-12-18T02:22:48.19+00:00

    about-dhcpgetclientinfov6-function-in-dhcpsapi-h (this is me too)

    I later found a solution to the problem myself.

    When ServerIpAddres is NULL, it will use the local DHCP server for query. I have verified that this is feasible.

    thanks everyone !!🫡

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.