/* This file is part of Lcrzo.
*/

#if defined LCRZODEF_SYSTEM_Unix
 /* do no need these functions */
#elif defined LCRZODEF_SYSTEM_Windows

/*-------------------------------------------------------------*/
int lcrzo_priv_iphlpapidll_init(lcrzo_priv_iphlpapidll *piphlpapidll)
{ 
  /* load the DLL */
  piphlpapidll->hinstance=LoadLibrary("iphlpapi.dll");
  if ( piphlpapidll->hinstance==NULL )
  { return(LCRZO_ERR_FULOADLIBRARY);
  }

  /* init functions */
  piphlpapidll->GetIpAddrTable=(pGetIpAddrTable)GetProcAddress(piphlpapidll->hinstance, "GetIpAddrTable");
  if ( piphlpapidll->GetIpAddrTable==NULL )
  { FreeLibrary(piphlpapidll->hinstance);
    return(LCRZO_ERR_FUGETPROCADDRESS);
  }

  piphlpapidll->GetIpNetTable=(pGetIpNetTable)GetProcAddress(piphlpapidll->hinstance, "GetIpNetTable");
  if ( piphlpapidll->GetIpNetTable==NULL )
  { FreeLibrary(piphlpapidll->hinstance);
    return(LCRZO_ERR_FUGETPROCADDRESS);
  }

  piphlpapidll->GetIpForwardTable=(pGetIpForwardTable)GetProcAddress(piphlpapidll->hinstance, "GetIpForwardTable");
  if ( piphlpapidll->GetIpForwardTable==NULL )
  { FreeLibrary(piphlpapidll->hinstance);
    return(LCRZO_ERR_FUGETPROCADDRESS);
  }

  piphlpapidll->GetIfEntry=(pGetIfEntry)GetProcAddress(piphlpapidll->hinstance, "GetIfEntry");
  if ( piphlpapidll->GetIfEntry==NULL )
  { FreeLibrary(piphlpapidll->hinstance);
    return(LCRZO_ERR_FUGETPROCADDRESS);
  }

  piphlpapidll->SendARP=(pSendARP)GetProcAddress(piphlpapidll->hinstance, "SendARP");
  if ( piphlpapidll->SendARP==NULL )
  { FreeLibrary(piphlpapidll->hinstance);
    return(LCRZO_ERR_FUGETPROCADDRESS);
  }
  
  piphlpapidll->GetIfTable=(pGetIfTable)GetProcAddress(piphlpapidll->hinstance, "GetIfTable");
  if ( piphlpapidll->GetIfTable==NULL )
  { FreeLibrary(piphlpapidll->hinstance);
    return(LCRZO_ERR_FUGETPROCADDRESS);
  }

  return(LCRZO_ERR_OK);
}

/*-------------------------------------------------------------*/
int lcrzo_priv_iphlpapidll_close(lcrzo_priv_iphlpapidll *piphlpapidll)
{ int ret;

  /* unload the DLL */
  ret=FreeLibrary(piphlpapidll->hinstance);
  if (!ret) return(LCRZO_ERR_FUFREELIBRARY);

  return(LCRZO_ERR_OK);
}


#else
 #error "Unknown value for LCRZODEF_SYSTEM"
#endif
