Skip to content

Commit 7bcb2e7

Browse files
committed
- slave: added IMasterConnection_getPeerAddress function
1 parent 571bbff commit 7bcb2e7

4 files changed

Lines changed: 44 additions & 0 deletions

File tree

lib60870-C/src/iec60870/cs101/cs101_master_connection.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,11 @@ IMasterConnection_close(IMasterConnection self)
5454
self->close(self);
5555
}
5656

57+
int
58+
IMasterConnection_getPeerAddress(IMasterConnection self, char* addrBuf, int addrBufSize)
59+
{
60+
if (self->getPeerAddress)
61+
return self->getPeerAddress(self, addrBuf, addrBufSize);
62+
else
63+
return 0;
64+
}

lib60870-C/src/iec60870/cs101/cs101_slave.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ CS101_Slave_create(SerialPort serialPort, LinkLayerParameters llParameters, CS10
332332
self->iMasterConnection.sendACT_TERM = sendACT_TERM;
333333
self->iMasterConnection.getApplicationLayerParameters = getApplicationLayerParameters;
334334
self->iMasterConnection.close = NULL;
335+
self->iMasterConnection.getPeerAddress = NULL;
335336
self->iMasterConnection.object = self;
336337

337338
CS101_Queue_initialize(&(self->userDataClass1Queue), CS101_MAX_QUEUE_SIZE);

lib60870-C/src/iec60870/cs104/cs104_slave.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2578,6 +2578,28 @@ _IMasterConnection_close(IMasterConnection self)
25782578
MasterConnection_close(con);
25792579
}
25802580

2581+
static int
2582+
_IMasterConnection_getPeerAddress(IMasterConnection self, char* addrBuf, int addrBufSize)
2583+
{
2584+
MasterConnection con = (MasterConnection) self->object;
2585+
2586+
char buf[50];
2587+
2588+
char* addrStr = Socket_getPeerAddressStatic(con->socket, buf);
2589+
2590+
if (addrStr == NULL)
2591+
return 0;
2592+
2593+
int len = strlen(buf);
2594+
2595+
if (len < addrBufSize) {
2596+
strcpy(addrBuf, buf);
2597+
return len;
2598+
}
2599+
else
2600+
return 0;
2601+
}
2602+
25812603
static CS101_AppLayerParameters
25822604
_IMasterConnection_getApplicationLayerParameters(IMasterConnection self)
25832605
{
@@ -2632,6 +2654,7 @@ MasterConnection_create(CS104_Slave slave, Socket socket, MessageQueue lowPrioQu
26322654
self->iMasterConnection.sendACT_CON = _IMasterConnection_sendACT_CON;
26332655
self->iMasterConnection.sendACT_TERM = _IMasterConnection_sendACT_TERM;
26342656
self->iMasterConnection.close = _IMasterConnection_close;
2657+
self->iMasterConnection.getPeerAddress = _IMasterConnection_getPeerAddress;
26352658

26362659
resetT3Timeout(self);
26372660

lib60870-C/src/inc/api/iec60870_slave.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ struct sIMasterConnection {
6767
void (*sendACT_CON) (IMasterConnection self, CS101_ASDU asdu, bool negative);
6868
void (*sendACT_TERM) (IMasterConnection self, CS101_ASDU asdu);
6969
void (*close) (IMasterConnection self);
70+
int (*getPeerAddress) (IMasterConnection self, char* addrBuf, int addrBufSize);
7071
CS101_AppLayerParameters (*getApplicationLayerParameters) (IMasterConnection self);
7172
void* object;
7273
};
@@ -105,6 +106,17 @@ IMasterConnection_sendACT_CON(IMasterConnection self, CS101_ASDU asdu, bool nega
105106
void
106107
IMasterConnection_sendACT_TERM(IMasterConnection self, CS101_ASDU asdu);
107108

109+
/**
110+
* \brief Get the peer address of the master (only for CS 104)
111+
*
112+
* \param addrBuf buffer where to store the IP address as string
113+
* \param addrBufSize the size of the buffer where to store the IP address
114+
*
115+
* \return the number of bytes written to the buffer, 0 if function not supported
116+
*/
117+
int
118+
IMasterConnection_getPeerAddress(IMasterConnection self, char* addrBuf, int addrBufSize);
119+
108120
/**
109121
* \brief Close the master connection (only for CS 104)
110122
*

0 commit comments

Comments
 (0)