Commit f58812b3 authored by Claes Sjofors's avatar Claes Sjofors

NodeConfig and Modbus TCP, hostname instead of address

parent 305c155b
...@@ -58,6 +58,7 @@ ...@@ -58,6 +58,7 @@
#include "rt_io_bus.h" #include "rt_io_bus.h"
#include "rt_io_msg.h" #include "rt_io_msg.h"
#include "rt_errh.h" #include "rt_errh.h"
#include "rt_net.h"
#include "co_cdh.h" #include "co_cdh.h"
#include "co_time.h" #include "co_time.h"
#include "rt_mb_msg.h" #include "rt_mb_msg.h"
...@@ -103,7 +104,12 @@ static int connect_slave( io_sRackLocal *local, io_sRack *rp) ...@@ -103,7 +104,12 @@ static int connect_slave( io_sRackLocal *local, io_sRack *rp)
local->rem_addr.sin_family = AF_INET; local->rem_addr.sin_family = AF_INET;
local->rem_addr.sin_port = htons(port); local->rem_addr.sin_port = htons(port);
local->rem_addr.sin_addr.s_addr = inet_addr((char *) &(op->Address)); // local->rem_addr.sin_addr.s_addr = inet_addr((char *) &(op->Address));
sts = net_StringToAddr( op->Address, &local->rem_addr.sin_addr);
if ( EVEN(sts)) {
errh_Error( "Address error for IO modbus tcp slave %s %s", rp->Name, op->Address);
return sts;
}
/* Connect to remote address */ /* Connect to remote address */
......
...@@ -1238,9 +1238,9 @@ Volume OtherIO $ClassVolume 0.0.250.10 ...@@ -1238,9 +1238,9 @@ Volume OtherIO $ClassVolume 0.0.250.10
! IP-address for the remote node. Dynamic change is not possible. ! IP-address for the remote node. Dynamic change is not possible.
!*/ !*/
Object Address $Attribute 6 08-FEB-2008 10:44:42.47 Object Address $Attribute 6 08-FEB-2008 10:44:42.47
Body SysBody 08-FEB-2008 10:47:01.34 Body SysBody 14-MAY-2012 13:53:27.76
Attr PgmName = "Address" Attr PgmName = "Address"
Attr TypeRef = "pwrs:Type-$String32" Attr TypeRef = "pwrs:Type-$String80"
EndBody EndBody
EndObject EndObject
!/** !/**
......
...@@ -89,7 +89,7 @@ SObject Remote:Class ...@@ -89,7 +89,7 @@ SObject Remote:Class
!*/ !*/
Object RemoteHostname $Attribute 4 Object RemoteHostname $Attribute 4
Body SysBody Body SysBody
Attr TypeRef = "pwrs:Type-$String32" Attr TypeRef = "pwrs:Type-$String80"
EndBody EndBody
EndObject EndObject
!/** !/**
......
...@@ -89,7 +89,7 @@ SObject Remote:Class ...@@ -89,7 +89,7 @@ SObject Remote:Class
!*/ !*/
Object RemoteHostname $Attribute 4 Object RemoteHostname $Attribute 4
Body SysBody Body SysBody
Attr TypeRef = "pwrs:Type-$String32" Attr TypeRef = "pwrs:Type-$String80"
EndBody EndBody
EndObject EndObject
!/** !/**
......
...@@ -59,6 +59,10 @@ ...@@ -59,6 +59,10 @@
# include <stddef.h> # include <stddef.h>
# include <string.h> # include <string.h>
# include <pthread.h> # include <pthread.h>
# include <sys/types.h>
# include <sys/socket.h>
# include <arpa/inet.h>
# include <netdb.h>
#endif #endif
#include "pwr.h" #include "pwr.h"
...@@ -813,3 +817,35 @@ int net_GetTime( net_sTime *nt) ...@@ -813,3 +817,35 @@ int net_GetTime( net_sTime *nt)
nt->tv_nsec = t.tv_nsec; nt->tv_nsec = t.tv_nsec;
return sts; return sts;
} }
int net_StringToAddr( char *str, struct in_addr *naddr)
{
naddr->s_addr = inet_network( str);
if (naddr->s_addr == (unsigned int)-1) {
/* Try name instead */
struct addrinfo hints;
struct addrinfo *res;
int err;
memset((void*)&hints, 0, sizeof(hints));
hints.ai_socktype = SOCK_STREAM;
err = getaddrinfo(str, 0, &hints, &res);
if ( err < 0) {
return 0;
}
switch ( res->ai_family) {
case AF_INET:
memcpy( &naddr->s_addr, (char *)&res->ai_addr->sa_data + 2, 4);
naddr->s_addr = ntohl( naddr->s_addr);
break;
case AF_INET6:
/* Not yet implemented */
return 0;
break;
}
freeaddrinfo( res);
}
return 1;
}
...@@ -1629,6 +1629,7 @@ struct net_sUpdateCircBuffer { ...@@ -1629,6 +1629,7 @@ struct net_sUpdateCircBuffer {
%net_sTime net_DeltaTimeToNetTime( const pwr_tDeltaTime *t); %net_sTime net_DeltaTimeToNetTime( const pwr_tDeltaTime *t);
%net_sTime net_DeltaTimeToNetTime( const pwr_tDeltaTime *t); %net_sTime net_DeltaTimeToNetTime( const pwr_tDeltaTime *t);
%int net_GetTime( net_sTime *nt); %int net_GetTime( net_sTime *nt);
%int net_StringToAddr( char *str, struct in_addr *naddr);
% %
%#endif %#endif
% %
......
...@@ -35,6 +35,8 @@ ...@@ -35,6 +35,8 @@
*/ */
/* rt_qini.c -- Queue Communication, initiation */ /* rt_qini.c -- Queue Communication, initiation */
#include <string.h>
#include <stdlib.h>
#include "pwr.h" #include "pwr.h"
#include "rt_errh.h" #include "rt_errh.h"
...@@ -45,6 +47,7 @@ ...@@ -45,6 +47,7 @@
#include "co_cdh.h" #include "co_cdh.h"
#include "rt_qini.h" #include "rt_qini.h"
#include "rt_inet.h" #include "rt_inet.h"
#include "rt_net.h"
static qdb_sNode * static qdb_sNode *
...@@ -156,16 +159,46 @@ qini_ParseFile ( ...@@ -156,16 +159,46 @@ qini_ParseFile (
continue; continue;
} }
sts = net_StringToAddr( s_naddr, &naddr);
if ( EVEN(sts)) {
errh_Error("error in line, <network address>, skip to next line.\n>> %s", s);
(*errors)++;
continue;
}
#if 0
naddr.s_addr = inet_network(s_naddr); naddr.s_addr = inet_network(s_naddr);
#if defined(OS_VMS) #if defined(OS_VMS)
if (naddr.s_addr == (in_addr_t)-1) { if (naddr.s_addr == (in_addr_t)-1) {
#else #else
if (naddr.s_addr == (unsigned int)-1) { if (naddr.s_addr == (unsigned int)-1) {
#endif #endif
/* Try name instead */
struct addrinfo hints;
struct addrinfo *res;
int err;
memset((void*)&hints, 0, sizeof(hints));
hints.ai_socktype = SOCK_STREAM;
err = getaddrinfo(s_naddr, 0, &hints, &res);
if ( err < 0) {
errh_Error("error in line, <network address>, skip to next line.\n>> %s", s); errh_Error("error in line, <network address>, skip to next line.\n>> %s", s);
(*errors)++; (*errors)++;
continue; continue;
} }
switch ( res->ai_family) {
case AF_INET:
// memcpy( &naddr.s_addr, (char *)&res->ai_addr->sa_data + 2, 4);
memcpy( &naddr.s_addr, &((struct sock_addr_in *)res->ai_addr)->sin_addr, 4);
naddr.s_addr = ntohl( naddr.s_addr);
break;
case AF_INET6:
break;
}
freeaddrinfo( res);
}
#endif
nep = tree_Find(&sts, ntp, &nid); nep = tree_Find(&sts, ntp, &nid);
if (nep != NULL) { if (nep != NULL) {
......
...@@ -132,7 +132,7 @@ SObject pwrb:Class ...@@ -132,7 +132,7 @@ SObject pwrb:Class
!*/ !*/
Object Address $Attribute 6 Object Address $Attribute 6
Body SysBody Body SysBody
Attr TypeRef = "pwrs:Type-$String16" Attr TypeRef = "pwrs:Type-$String80"
EndBody EndBody
EndObject EndObject
!/** !/**
......
...@@ -96,7 +96,7 @@ public: ...@@ -96,7 +96,7 @@ public:
pwr_tOid oid; pwr_tOid oid;
pwr_tEnum operatingsystem; pwr_tEnum operatingsystem;
pwr_tString80 nodename; pwr_tString80 nodename;
pwr_tString16 address; pwr_tString80 address;
pwr_tUInt32 port; pwr_tUInt32 port;
pwr_tVid vid; pwr_tVid vid;
pwr_tEnum connection; pwr_tEnum connection;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment