6 #define WIN32_LEAN_AND_MEAN
22 #define WORKING_BUFFER_SIZE 15000
25 #pragma comment(lib, "IPHLPAPI.lib")
26 #pragma comment(lib, "Ws2_32.lib")
31 PIP_ADAPTER_INFO pAdapterInfo;
32 PIP_ADAPTER_INFO pAdapter = NULL;
35 CipUdint ulOutBufLen =
sizeof(IP_ADAPTER_INFO);
36 pAdapterInfo = (IP_ADAPTER_INFO *)
CipCalloc(1,
sizeof(IP_ADAPTER_INFO) );
37 if (pAdapterInfo == NULL) {
38 printf(
"Error allocating memory needed to call GetAdaptersinfo\n");
43 if (GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW) {
46 if (pAdapterInfo == NULL) {
47 printf(
"Error allocating memory needed to call GetAdaptersinfo\n");
53 if ( (dwRetVal = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) ) == NO_ERROR ) {
54 pAdapter = pAdapterInfo;
56 if (pAdapter->Index == interface_index) {
57 for (
int i = 0; i < 6; i++) {
63 pAdapter->IpAddressList.IpAddress.String);
65 pAdapter->IpAddressList.IpMask.String);
67 pAdapter->GatewayList.IpAddress.String);
75 ntohl(inet_addr(
"239.192.1.0") ) + (host_id << 5) );
77 pAdapter = pAdapter->Next;
81 printf(
"GetAdaptersInfo failed with error: %d\n", dwRetVal);
93 CipUdint flags = GAA_FLAG_INCLUDE_PREFIX;
98 LPVOID lpMsgBuf = NULL;
100 PIP_ADAPTER_ADDRESSES pAddresses = NULL;
101 PIP_ADAPTER_ADDRESSES pCurrAddresses = NULL;
102 IP_ADAPTER_DNS_SERVER_ADDRESS *pDnServer = NULL;
112 pAddresses = (IP_ADAPTER_ADDRESSES *)
CipCalloc(1,outBufLen);
113 if (pAddresses == NULL) {
115 (
"Memory allocation failed for IP_ADAPTER_ADDRESSES struct\n");
120 GetAdaptersAddresses(family, flags, NULL, pAddresses, &outBufLen);
122 if (dwRetVal == ERROR_BUFFER_OVERFLOW) {
132 }
while ( (dwRetVal == ERROR_BUFFER_OVERFLOW) && (tries <
MAX_TRIES) );
134 if (dwRetVal == NO_ERROR) {
136 pCurrAddresses = pAddresses;
137 while (pCurrAddresses) {
138 if (interface_index == pCurrAddresses->IfIndex) {
139 pDnServer = pCurrAddresses->FirstDnsServerAddress;
141 for (i = 0; pDnServer != NULL; i++) {
142 pDnServer = pDnServer->Next;
146 char pStringBuf[INET_ADDRSTRLEN];
156 pCurrAddresses->DnsSuffix);
162 pCurrAddresses->DnsSuffix);
169 pCurrAddresses->FirstDnsServerAddress->Address.lpSockaddr->sa_data + 2,
173 pCurrAddresses->FirstDnsServerAddress->Next->Address.lpSockaddr->sa_data + 2,
180 pCurrAddresses = pCurrAddresses->Next;
186 if (dwRetVal == ERROR_NO_DATA) {
188 "\tNo addresses were found for the requested parameters\n");
192 if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
193 FORMAT_MESSAGE_FROM_SYSTEM |
194 FORMAT_MESSAGE_IGNORE_INSERTS,
196 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
198 (LPTSTR)&lpMsgBuf, 0, NULL) ) {
222 wVersionRequested = MAKEWORD(2, 2);
224 err = WSAStartup(wVersionRequested, &wsaData);
228 printf(
"WSAStartup failed with error: %d\n", err);
232 char hostname[256] =
"";
234 status = gethostname(hostname,
sizeof(hostname) );
#define WORKING_BUFFER_SIZE
CipEthernetLinkObject g_ethernet_link
Tracing infrastructure for OpENer.
EipUint8 physical_address[6]
MulticastAddressConfiguration g_multicast_configuration
#9 The multicast configuration for this device
void ConfigureIpMacAddress(const CipUint interface_index)
void * CipCalloc(size_t number_of_elements, size_t size_of_element)
Allocate memory for the CIP stack.
#define OPENER_TRACE_INFO(...)
void CipFree(void *data)
Free memory allocated by the OpENer.
Public interface of the TCP/IP Interface Object.
CipTcpIpNetworkInterfaceConfiguration interface_configuration_
void ConfigureDomainName()
Configure the domain name of the device.
void ConfigureHostName(void)
Configure the host name of the device.
CipUdint starting_multicast_address