@@ -152,7 +152,7 @@ class SInfo {
152
152
{
153
153
assert (sock);
154
154
}
155
- SInfo (Socket* sock, bool delete_on_exit= true ):
155
+ SInfo (Socket * sock, bool delete_on_exit = true ):
156
156
_id (id_count++),
157
157
_sock (sock),
158
158
_type (SInfo::OTHER),
@@ -408,31 +408,42 @@ static void print_data_as_hex(const uint8_t *buf, int len, int col_width);
408
408
* \param offset Start pattern from offset
409
409
* \param len Length of pattern to generate.
410
410
*/
411
- static void generate_RFC_864_pattern (size_t offset, uint8_t *buf, size_t len)
411
+ static void generate_RFC_864_pattern (size_t offset, uint8_t *buf, size_t len, bool is_xinetd )
412
412
{
413
+ const int row_size = 74 ; // Number of chars in single row
414
+ const int row_count = 95 ; // Number of rows in pattern after which pattern start from beginning
415
+ const int chars_scope = is_xinetd ? 93 : 95 ; // Number of chars from ASCII table used in pattern
416
+ const char first_char = is_xinetd ? ' !' : ' ' ; // First char from ASCII table used in pattern
413
417
while (len--) {
414
- if (offset % 74 == 72 ) {
418
+ if (offset % row_size == (row_size - 2 ) ) {
415
419
*buf++ = ' \r ' ;
416
- } else if (offset % 74 == 73 ) {
420
+ } else if (offset % row_size == (row_size - 1 ) ) {
417
421
*buf++ = ' \n ' ;
418
422
} else {
419
- *buf++ = ' ' + (offset % 74 + offset / 74 ) % 95 ;
423
+ *buf++ = first_char + (offset % row_size + (( offset / row_size ) % row_count)) % chars_scope ;
420
424
}
421
425
offset++;
422
426
}
423
427
}
424
428
425
429
bool SInfo::check_pattern (void *buffer, size_t len)
426
430
{
431
+ static bool is_xinetd = false ;
427
432
if (!_check_pattern) {
428
433
return true ;
429
434
}
430
435
void *buf = malloc (len);
431
436
if (!buf) {
432
437
return false ;
433
438
}
439
+
434
440
size_t offset = _receivedTotal;
435
- generate_RFC_864_pattern (offset, (uint8_t *)buf, len);
441
+
442
+ if (offset == 0 ) {
443
+ is_xinetd = ((uint8_t *)buffer)[0 ] == ' !' ;
444
+ }
445
+
446
+ generate_RFC_864_pattern (offset, (uint8_t *)buf, len, is_xinetd);
436
447
bool match = memcmp (buf, buffer, len) == 0 ;
437
448
if (!match) {
438
449
cmd_printf (" Pattern check failed\r\n WAS:%.*s\r\n REF:%.*s\r\n " , len, (char *)buffer, len, (char *)buf);
@@ -1162,11 +1173,11 @@ static int cmd_socket(int argc, char *argv[])
1162
1173
cmd_printf (" Invalid socket id\r\n " );
1163
1174
return CMDLINE_RETCODE_FAIL;
1164
1175
}
1165
- TCPSocket *new_sock = static_cast <TCPSocket*>(&new_info->socket ());
1166
- nsapi_error_t ret = static_cast <TCPServer&>(info->socket ()).accept (new_sock, &addr);
1176
+ TCPSocket *new_sock = static_cast <TCPSocket *>(&new_info->socket ());
1177
+ nsapi_error_t ret = static_cast <TCPServer &>(info->socket ()).accept (new_sock, &addr);
1167
1178
if (ret == NSAPI_ERROR_OK) {
1168
1179
cmd_printf (" TCPServer::accept() new socket sid: %d connection from %s port %d\r\n " ,
1169
- new_info->id (), addr.get_ip_address (), addr.get_port ());
1180
+ new_info->id (), addr.get_ip_address (), addr.get_port ());
1170
1181
}
1171
1182
return handle_nsapi_error (" TCPServer::accept()" , ret);
1172
1183
}
0 commit comments