6 #define WIN32_LEAN_AND_MEAN
23 #define WORKING_BUFFER_SIZE 15000
29 PIP_ADAPTER_INFO pAdapterInfo;
30 PIP_ADAPTER_INFO pAdapter = NULL;
33 CipUdint ulOutBufLen =
sizeof(IP_ADAPTER_INFO);
34 pAdapterInfo = (IP_ADAPTER_INFO *)
CipCalloc(1,
sizeof(IP_ADAPTER_INFO) );
35 if (pAdapterInfo == NULL) {
36 printf(
"Error allocating memory needed to call GetAdaptersinfo\n");
41 if (GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW) {
44 if (pAdapterInfo == NULL) {
45 printf(
"Error allocating memory needed to call GetAdaptersinfo\n");
51 if ( (dwRetVal = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) ) == NO_ERROR ) {
52 pAdapter = pAdapterInfo;
54 if (strcmp( pAdapter->IpAddressList.IpAddress.String, network_interface) == 0) {
55 for (
int i = 0; i < 6; i++) {
61 pAdapter->IpAddressList.IpAddress.String);
63 pAdapter->IpAddressList.IpMask.String);
65 pAdapter->GatewayList.IpAddress.String);
73 ntohl(inet_addr(
"239.192.1.0") ) + (host_id << 5) );
75 pAdapter = pAdapter->Next;
79 printf(
"GetAdaptersInfo failed with error: %d\n", dwRetVal);
89 int interface_index = 0;
94 CipUdint flags = GAA_FLAG_INCLUDE_PREFIX;
99 LPVOID lpMsgBuf = NULL;
101 PIP_ADAPTER_ADDRESSES pAddresses = NULL;
102 PIP_ADAPTER_ADDRESSES pCurrAddresses = NULL;
103 IP_ADAPTER_DNS_SERVER_ADDRESS *pDnServer = NULL;
113 pAddresses = (IP_ADAPTER_ADDRESSES *)
CipCalloc(1,outBufLen);
114 if (pAddresses == NULL) {
116 (
"Memory allocation failed for IP_ADAPTER_ADDRESSES struct\n");
121 GetAdaptersAddresses(family, flags, NULL, pAddresses, &outBufLen);
123 if (dwRetVal == ERROR_BUFFER_OVERFLOW) {
133 }
while ( (dwRetVal == ERROR_BUFFER_OVERFLOW) && (tries <
MAX_TRIES) );
135 if (dwRetVal == NO_ERROR) {
137 pCurrAddresses = pAddresses;
138 while (pCurrAddresses) {
139 if (interface_index == pCurrAddresses->IfIndex) {
140 pDnServer = pCurrAddresses->FirstDnsServerAddress;
142 for (i = 0; pDnServer != NULL; i++) {
143 pDnServer = pDnServer->Next;
147 char pStringBuf[INET_ADDRSTRLEN];
157 pCurrAddresses->DnsSuffix);
163 pCurrAddresses->DnsSuffix);
182 pCurrAddresses = pCurrAddresses->Next;
188 if (dwRetVal == ERROR_NO_DATA) {
190 "\tNo addresses were found for the requested parameters\n");
194 if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
195 FORMAT_MESSAGE_FROM_SYSTEM |
196 FORMAT_MESSAGE_IGNORE_INSERTS,
198 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
200 (LPTSTR)&lpMsgBuf, 0, NULL) ) {
224 wVersionRequested = MAKEWORD(2, 2);
226 err = WSAStartup(wVersionRequested, &wsaData);
230 printf(
"WSAStartup failed with error: %d\n", err);
234 char hostname[256] =
"";
235 gethostname(hostname,
sizeof(hostname) );
CipEthernetLinkObject g_ethernet_link
Tracing infrastructure for OpENer.
EipUint8 physical_address[6]
MulticastAddressConfiguration g_multicast_configuration
#9 The multicast configuration for this device
void * CipCalloc(size_t number_of_elements, size_t size_of_element)
Allocate memory for the CIP stack.
EipStatus
EIP stack status enum.
#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_
EipStatus ConfigureNetworkInterface(const char *const network_interface)
Configure the data of the network interface of the device.
#define WORKING_BUFFER_SIZE
void ConfigureDomainName()
Configure the domain name of the device.
void ConfigureHostName(void)
Configure the host name of the device.
CipUdint starting_multicast_address