Commit f58812b3 authored by Claes Sjofors's avatar Claes Sjofors

NodeConfig and Modbus TCP, hostname instead of address

parent 305c155b
......@@ -58,6 +58,7 @@
#include "rt_io_bus.h"
#include "rt_io_msg.h"
#include "rt_errh.h"
#include "rt_net.h"
#include "co_cdh.h"
#include "co_time.h"
#include "rt_mb_msg.h"
......@@ -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_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 */
......
......@@ -1238,9 +1238,9 @@ Volume OtherIO $ClassVolume 0.0.250.10
! IP-address for the remote node. Dynamic change is not possible.
!*/
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 TypeRef = "pwrs:Type-$String32"
Attr TypeRef = "pwrs:Type-$String80"
EndBody
EndObject
!/**
......
......@@ -89,7 +89,7 @@ SObject Remote:Class
!*/
Object RemoteHostname $Attribute 4
Body SysBody
Attr TypeRef = "pwrs:Type-$String32"
Attr TypeRef = "pwrs:Type-$String80"
EndBody
EndObject
!/**
......
......@@ -89,7 +89,7 @@ SObject Remote:Class
!*/
Object RemoteHostname $Attribute 4
Body SysBody
Attr TypeRef = "pwrs:Type-$String32"
Attr TypeRef = "pwrs:Type-$String80"
EndBody
EndObject
!/**
......
......@@ -59,6 +59,10 @@
# include <stddef.h>
# include <string.h>
# include <pthread.h>
# include <sys/types.h>
# include <sys/socket.h>
# include <arpa/inet.h>
# include <netdb.h>
#endif
#include "pwr.h"
......@@ -813,3 +817,35 @@ int net_GetTime( net_sTime *nt)
nt->tv_nsec = t.tv_nsec;
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 {
%net_sTime net_DeltaTimeToNetTime( const pwr_tDeltaTime *t);
%net_sTime net_DeltaTimeToNetTime( const pwr_tDeltaTime *t);
%int net_GetTime( net_sTime *nt);
%int net_StringToAddr( char *str, struct in_addr *naddr);
%
%#endif
%
......
......@@ -35,6 +35,8 @@
*/
/* rt_qini.c -- Queue Communication, initiation */
#include <string.h>
#include <stdlib.h>
#include "pwr.h"
#include "rt_errh.h"
......@@ -45,6 +47,7 @@
#include "co_cdh.h"
#include "rt_qini.h"
#include "rt_inet.h"
#include "rt_net.h"
static qdb_sNode *
......@@ -156,16 +159,46 @@ qini_ParseFile (
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);
#if defined(OS_VMS)
if (naddr.s_addr == (in_addr_t)-1) {
#else
if (naddr.s_addr == (unsigned int)-1) {
#endif
errh_Error("error in line, <network address>, skip to next line.\n>> %s", s);
(*errors)++;
continue;
/* 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);
(*errors)++;
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);
if (nep != NULL) {
......
......@@ -132,7 +132,7 @@ SObject pwrb:Class
!*/
Object Address $Attribute 6
Body SysBody
Attr TypeRef = "pwrs:Type-$String16"
Attr TypeRef = "pwrs:Type-$String80"
EndBody
EndObject
!/**
......
......@@ -96,7 +96,7 @@ public:
pwr_tOid oid;
pwr_tEnum operatingsystem;
pwr_tString80 nodename;
pwr_tString16 address;
pwr_tString80 address;
pwr_tUInt32 port;
pwr_tVid vid;
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