mirror of
https://github.com/eclipse/paho.mqtt-sn.embedded-c.git
synced 2025-12-15 16:36:52 +01:00
@@ -202,14 +202,19 @@ int LGwProxy::getConnectResponce(void)
|
||||
_gwId = _mqttsnMsg[1];
|
||||
|
||||
#if defined(DTLS) || defined(DTLS6)
|
||||
if (_network.sslConnect() < 0)
|
||||
for (int i = 0; i < MQTTSN_RETRY_COUNT; i++)
|
||||
{
|
||||
DISPLAY(
|
||||
"\033[0m\033[0;32m\n\nLGwProxy::getConnectResponce Can't connect the Gateway via SSL.\033[0m\033[0;37m\n\n");
|
||||
return 0;
|
||||
if (_network.sslConnect() > 0)
|
||||
{
|
||||
_status = GW_CONNECTING;
|
||||
DISPLAY(
|
||||
"\033[0m\033[0;32m\n\nLGwProxy::getConnectResponce Can't connect the Gateway via SSL.\033[0m\033[0;37m\n\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
_status = GW_CONNECTING;
|
||||
#endif
|
||||
}
|
||||
else if (_mqttsnMsg[0] == MQTTSN_TYPE_WILLTOPICREQ && _status == GW_WAIT_WILLTOPICREQ)
|
||||
{
|
||||
|
||||
@@ -52,15 +52,15 @@ int main(int argc, char** argv)
|
||||
printf("\n%s", PAHO_COPYRIGHT4);
|
||||
printf("\n%s", PAHO_COPYRIGHT0);
|
||||
#if defined(UDP)
|
||||
printf(" UDP\n");
|
||||
printf("UDP ClientId:%s PortNo:%d\n", theNetcon.clientId, theNetcon.uPortNo);
|
||||
#elif defined(UDP6)
|
||||
printf(" UDP6\n");
|
||||
#elif defined(RFCOMM)
|
||||
printf(" RFCOMM\n");
|
||||
printf("UDP6 ClientId:%s PortNo:%d\n", theNetcon.clientId, theNetcon.uPortNo);
|
||||
#elif defined(DTLS)
|
||||
printf(" DTLS\n");
|
||||
printf("DTLS ClientId:%s PortNo:%d\n", theNetcon.clientId, theNetcon.uPortNo);
|
||||
#elif defined(DTLS6)
|
||||
printf(" DTLS6\n");
|
||||
printf("DTLS6 ClientId:%s PortNo:%d\n", theNetcon.clientId, theNetcon.uPortNo);
|
||||
#elif defined(RFCOMM)
|
||||
printf("RFCOMM ClientId:%s channel:%d\n", theNetcon.clientId, theNetcon.channel);
|
||||
#else
|
||||
printf("\n");
|
||||
#endif
|
||||
|
||||
@@ -471,6 +471,7 @@ int LDtlsPort::sslConnect(uint32_t ipAddress, in_port_t portNo)
|
||||
int reuse = 1;
|
||||
if (_ssl != 0)
|
||||
{
|
||||
D_NWLOG("LDtlsPort::sslConnect SSL exists.\n");
|
||||
SSL_shutdown(_ssl);
|
||||
SSL_free(_ssl);
|
||||
_sockfdSsl = 0;
|
||||
@@ -489,7 +490,7 @@ int LDtlsPort::sslConnect(uint32_t ipAddress, in_port_t portNo)
|
||||
D_NWLOG("LDtlsPort::sslConnect Can't create a socket\n");
|
||||
return -1;
|
||||
}
|
||||
setsockopt(_sockfdSsl, SOL_SOCKET, SO_REUSEADDR || SO_REUSEPORT, &reuse, sizeof(reuse));
|
||||
setsockopt(_sockfdSsl, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse));
|
||||
|
||||
struct sockaddr_in addr;
|
||||
addr.sin_family = AF_INET;
|
||||
@@ -497,6 +498,8 @@ int LDtlsPort::sslConnect(uint32_t ipAddress, in_port_t portNo)
|
||||
addr.sin_addr.s_addr = INADDR_ANY;
|
||||
if (::bind(_sockfdSsl, (struct sockaddr*) &addr, sizeof(addr)) < 0)
|
||||
{
|
||||
::close(_sockfdSsl);
|
||||
_sockfdSsl = 0;
|
||||
D_NWLOG("LDtlsPort::sslConnect Can't bind a socket\n");
|
||||
return -1;
|
||||
}
|
||||
@@ -514,6 +517,12 @@ int LDtlsPort::sslConnect(uint32_t ipAddress, in_port_t portNo)
|
||||
SSL_set_bio(_ssl, cbio, cbio);
|
||||
|
||||
D_NWLOG("LDtlsPort::sslConnect connect to %-15s:%-6u\n", inet_ntoa(dest.sin_addr), htons(dest.sin_port));
|
||||
|
||||
timeval timeout;
|
||||
timeout.tv_sec = 5;
|
||||
timeout.tv_usec = 0;
|
||||
BIO_ctrl(cbio, BIO_CTRL_DGRAM_SET_RECV_TIMEOUT, 0, &timeout);
|
||||
|
||||
int stat = SSL_connect(_ssl);
|
||||
if (stat != 1)
|
||||
{
|
||||
@@ -522,6 +531,7 @@ int LDtlsPort::sslConnect(uint32_t ipAddress, in_port_t portNo)
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = 1;
|
||||
D_NWLOG("SSL connected\n");
|
||||
}
|
||||
return rc;
|
||||
|
||||
Reference in New Issue
Block a user