iam trying to write a C++ program for the MAC and IP addresses,,,but i need help on what exactly the program will do regarding those two addresses..if any body has a code which can help.

9 Years
Discussion Span
Last Post by CrazyDieter

Well, this is heavily dependant on your OS and compiler.. this works in XP and MSVC .NET 03:

#include <windows.h>
#include <Iphlpapi.h>

#pragma comment ( lib, "Iphlpapi.lib" )

static void GetMACaddress(void)
  IP_ADAPTER_INFO AdapterInfo[16];       // Allocate information
                                         // for up to 16 NICs
  DWORD dwBufLen = sizeof(AdapterInfo);  // Save memory size of buffer
  DWORD dwStatus = GetAdaptersInfo(      // Call GetAdapterInfo
    AdapterInfo,                 // [out] buffer to receive data
    &dwBufLen);                  // [in] size of receive data buffer
  if(dwStatus == ERROR_SUCCESS) {  // Verify return value is
                                      // valid, no buffer overflow

    PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo; // Contains pointer to
                                                // current adapter info

    do {
      std::cout<< &pAdapterInfo->Address; // Print MAC address
      pAdapterInfo = pAdapterInfo->Next;    // Progress through
                                            // linked list
    while(pAdapterInfo);                    // Terminate if last adapter


int main( void ) {

  return 0;

Don't know if it's what you want. Searching always helps. http://www.codeguru.com/Cpp/I-N/network/networkinformation/article.php/c5451


thank you that was so helpfull,but one more thing i wannd do a program that deal with all the contents of the MAC frame like,,the destenation address, lenght of PDU,source address, SFD...so how can i implement those things in a C++ program?????????



1) please try to ask more a more precize question next time

2) MAC address and MAC Frames are two different things. The Media Access Control protocol (IEEE 802.x) defines a way for defining, delimiting and adressing logical frames for other protocols (Ethernet, wifi, token ring, etc...) . It is not directly related with IP.

3) If you want to dissect MAC (or other prototocols) network packets, you may have a look at the norm, or find a library that parses network stream.

4) have a look to the ethereal program http://www.ethereal.com

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.