17 #include <sys/ioctl.h>
18 #include <sys/socket.h>
21 #include <netinet/in.h>
26 #include <arpa/inet.h>
29 #define LOOPBACK_BINARY 0x7f000001
33 size_t if_name_len = strlen(interface);
34 if(if_name_len <
sizeof(ifr.ifr_name) ) {
35 memcpy(ifr.ifr_name, interface, if_name_len);
36 ifr.ifr_name[if_name_len] = 0;
42 int fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
44 if(ioctl(fd, SIOCGIFHWADDR, &ifr) == 0) {
54 size_t if_name_len = strlen(network_interface);
55 if(if_name_len <
sizeof(ifr.ifr_name) ) {
56 memcpy(ifr.ifr_name, network_interface, if_name_len);
57 ifr.ifr_name[if_name_len] = 0;
63 int fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
66 if(ioctl(fd, SIOCGIFADDR, &ifr) == 0) {
67 ipaddr = ( (
struct sockaddr_in *) &ifr.ifr_addr )->sin_addr.s_addr;
73 if(ioctl(fd, SIOCGIFNETMASK, &ifr) == 0) {
74 netaddr = ( (
struct sockaddr_in *) &ifr.ifr_netmask )->sin_addr.s_addr;
83 char route_location[] =
"/proc/net/route";
85 FILE *file_handle = fopen(route_location,
"r");
86 char file_buffer[100] = { 0 };
87 char *gateway_string = NULL;
91 char *needle_start = NULL;
95 network_interface) ) &&
96 fgets(file_buffer,
sizeof(file_buffer), file_handle) ) {
99 if(NULL != needle_start) {
100 char *strtok_save = NULL;
101 strtok_r(needle_start,
" \t", &strtok_save);
102 strtok_r(needle_start,
" \t", &strtok_save);
103 gateway_string = strtok_r(needle_start,
"\t", &strtok_save);
112 if(inet_pton(AF_INET, gateway_string, &gateway) == 1) {
131 htonl(ntohl(inet_addr(
"239.192.1.0") ) + (host_id << 5) );
140 char resolv_conf_file[] =
"/etc/resolv.conf";
141 FILE *file_handle = fopen(resolv_conf_file,
"r");
142 char *file_buffer = NULL;
144 char *domain_name_string = NULL;
145 char *dns1_string = NULL;
146 char *dns2_string = NULL;
149 fseek(file_handle, 0, SEEK_END);
150 file_length = ftell(file_handle);
151 fseek(file_handle, 0, SEEK_SET);
152 file_buffer = malloc(file_length);
154 fread(file_buffer, 1, file_length, file_handle);
168 if(strstr(file_buffer,
"domain") ) {
169 char *strtok_save = NULL;
170 strtok_r(file_buffer,
" ", &strtok_save);
171 domain_name_string = strtok_r(file_buffer,
"\n", &strtok_save);
196 if(strstr(file_buffer,
"nameserver") ) {
197 char *strtok_save = NULL;
198 strtok_r(file_buffer,
" ", &strtok_save);
199 dns1_string = strtok_r(NULL,
"\n", &strtok_save);
204 if(strstr(file_buffer,
"nameserver ") ) {
205 char *strtok_save = NULL;
206 strtok_r(file_buffer,
" ", &strtok_save);
207 dns2_string = strtok_r(file_buffer,
"\n", &strtok_save);
216 char name[1024] = { 0 };
217 gethostname(name,
sizeof(name) );
CipEthernetLinkObject g_ethernet_link
Tracing infrastructure for OpENer.
EipUint8 physical_address[6]
#define OPENER_TRACE_ERR(...)
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.
void ConfigureMacAddress(const char *interface)
Configure the MAC address of the device.
#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_
uint8_t EipByte
EIP Data type definitions.
EipStatus ConfigureNetworkInterface(const char *const network_interface)
Configure the data of the network interface of the device.
void ConfigureDomainName()
Configure the domain name of the device.
void CloseSocket(const int socket_handle)
Close the given socket and clean up the stack.
void ConfigureHostName(void)
Configure the host name of the device.
CipUdint starting_multicast_address