The "reprint" GetAdaptersInfo function returns error_noaccess on a 64-bit system

Source: Internet
Author: User
Tags hosting

From:http://www.educity.cn/wenda/351190.html

GetAdaptersInfo function returns the error_noaccess problem on a 64-bit system

In the actual application of a program in the long run after a high memory consumption crash, from the dump information, found that the getadaptersinfo function returned a strange error code 998 (error_noaccess), Baidu Search does not have the relevant information. The error code for the getadaptersinfo function on MSDN normally has only 5 types. And a total of two crashes occurred on a Win7 64-bit machine, the other test machines are normal.

The problematic code is as follows:

  void Getmacaddr (char *buf) {BOOL bnewstate = TRUE;//pip_adapter_info struct pointer stores the native NIC information pip_adapter_info pipadapterinfo = NE W (std::nothrow) Ip_adapter_info; if (Pipadapterinfo = = NULL) {return;}//Get struct size for getadaptersinfo parameter unsigned long stsize = sizeof (Ip_adapter_info); Call the GetAdaptersInfo function, populate the Pipadapterinfo pointer variable, where the Stsize parameter is both an input and an output of ULONG Ulrel = GetAdaptersInfo (Pipadapterinfo, &stsize); if (Error_buffer_overflow = = Ulrel) {bnewstate = FALSE; Delete pipadapterinfo;//re-request memory space to store all nic information pipadapterinfo = (PIP _adapter_info) New (Std::nothrow) byte[stsize]; if (Pipadapterinfo = = NULL) {return;}//Call GetAdaptersInfo function again, fill pipadapterinfo pointer variable ulrel = getadaptersinfo (pipadapteri NFO, &stsize); } string Stripmac; if (Error_success==ulrel) {//Output NIC information//may have more than one network card, so through the loop to determine pip_adapter_info pipadapterinfotmp = Pipadapterinfo; while ( Pipadapterinfotmp! = NULL) {char szmac[10] = {0}; for (UINT i =0; i < pipadapterinfotmp->addresslength; i++) {if ( I==pipadapterinfotmp->addresslength-1) {_snprintf_s (Szmac, "%02x;", Pipadapterinfotmp->address[i]); Stripmac + = Szmac;} else {_snprintf_s (szMa C, ten, "%02x-", Pipadapterinfotmp->address[i]); Stripmac + = Szmac; }} pipadapterinfotmp = pipadapterinfotmp->next; }}//Free memory space if (pipadapterinfo! = NULL) {if (bnewstate = = FALSE) {delete[] pipadapterinfo;} else {delete Pipadapterin Fo }} if (Stripmac[stripmac.length ()-1] = = '; ') {stripmac[stripmac.length ()-1] = ' + ';} sprintf (buf, "%s", Stripmac.c_str ()); Return }

  Return Code

  Description

Error_buffer_overflow

The buffer to receive the adapter information is too small. This value was returned if the buffer size indicated by the Poutbuflen parameter was too small to the adapter Informati On or the Padapterinfo parameter is a NULL pointer. When this error code was returned, the Poutbuflen parameter points to the required buffer size.

Error_invalid_data

Invalid adapter information was retrieved.

Error_invalid_parameter

One of the parameters is invalid. This error is returned if the Poutbuflen parameter are a NULL pointer, or the calling process does not having read/write acce SS to the memory pointed into Poutbuflen or the calling process does not having write access to the memory pointed to by th e padapterinfo parameter.

Error_no_data

No Adapter information exists for the local computer.

error_not_supported

The getadaptersinfo function is not a supported by the operating system running on the local computer.

Other

If The function fails, use formatmessage to obtain the message string for the returned error.

So we locked the problem into a Win7 64-bit machine with a high memory footprint and agetadaptersinfo function that returned 998 errors.

For this we have written a test program that creates two threads, one thread constantly requesting memory, one request for 500KB, and another thread looping through the getadaptersinfo function until a 998 error is returned.

The test results validate our guesses.

From this point of view, the program code in the return of the 998 is not judged, the application of the memory of the delete operation caused a crash, and 998 representative error_noaccess is not accessible, so should be judged.

Shortly after this issue was resolved, Microsoft found an article on the bug report and recommendations website, $amp;<lt; $strong >getadaptersaddresses API incorrectly returns no adapters for A process with high memory consumption> Rrectly-returns-no-adapters-for-a-process-with-high-memory-consumption. A foreign programmer has also reproduced this issue, but Microsoft has yet to give a solution, only to confirm that this belongs to Windows a bug in the operating system . The conditions of occurrence are indicated in more detail in his description:

1.32-bit Application

2.64-bit operating system OR/3GB feature enabled on 32-bit operating system

3.hosting process is linked With/largeaddressaware flag or have otherwise set it in binary header

4.over 2GB of RAM (in terms of Private bytes/virtual Size performance counters) consumed by the hosting process

The 32-bit program, which runs on 64-bit operating systems and consumes more than 2GB of process memory, also proves our guess.

The "reprint" GetAdaptersInfo function returns error_noaccess on a 64-bit system

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.