diff --git a/src/lancode.c b/src/lancode.c index d392c67a..e2fb7184 100644 --- a/src/lancode.c +++ b/src/lancode.c @@ -269,62 +269,24 @@ static int lan_send(char *lanbuffer) { /* ----------------- send lan message ----------*/ +#define MAX_MESSAGE_LEN 98 + void send_lan_message(int opcode, char *message) { - char sendbuffer[102]; + char sendbuffer[MAX_MESSAGE_LEN + 4]; /* + node + opcode + NL + \0 */ - sendbuffer[0] = thisnode; - sendbuffer[1] = opcode; - sendbuffer[2] = '\0'; - strncat(sendbuffer, message, 98); if (opcode == CLUSTERMSG) { - if (!cl_send_inhibit) { - strcat(sendbuffer, "\n"); - lan_send(sendbuffer); + if (cl_send_inhibit) { + return; } } - if (opcode == LOGENTRY) { - strcat(sendbuffer, "\n"); - lan_send(sendbuffer); - } + sendbuffer[0] = thisnode; + sendbuffer[1] = opcode; + sendbuffer[2] = '\0'; + strncat(sendbuffer, message, MAX_MESSAGE_LEN); - if (opcode == TLFSPOT) { - sendbuffer[82] = '\0'; - strcat(sendbuffer, "\n"); - lan_send(sendbuffer); - } - if (opcode == TLFMSG) { - sendbuffer[82] = '\0'; - strcat(sendbuffer, "\n"); - lan_send(sendbuffer); - } - if (opcode == FREQMSG) { - strcat(sendbuffer, "\n"); - lan_send(sendbuffer); - } - if (opcode == INCQSONUM) { - strcat(sendbuffer, "\n"); - lan_send(sendbuffer); - } - if (opcode == TIMESYNC) { - strcat(sendbuffer, "\n"); - sendbuffer[14] = '\0'; - lan_send(sendbuffer); - } - if (opcode == QTCRENTRY) { - strcat(sendbuffer, "\n"); - sendbuffer[94] = '\0'; - lan_send(sendbuffer); - } - if (opcode == QTCSENTRY) { - strcat(sendbuffer, "\n"); - sendbuffer[100] = '\0'; - lan_send(sendbuffer); - } - if (opcode == QTCFLAG) { - strcat(sendbuffer, "\n"); - lan_send(sendbuffer); - } + strcat(sendbuffer, "\n"); + lan_send(sendbuffer); return; } diff --git a/test/test_lancode.c b/test/test_lancode.c index c193f90b..009ffe22 100644 --- a/test/test_lancode.c +++ b/test/test_lancode.c @@ -68,6 +68,7 @@ void test_lan_send_message_all_codes(void **state) { void test_lan_send_message_inhibit_cluster(void **state) { cl_send_inhibit = true; + send_lan_message(CLUSTERMSG, "DX de ..."); assert_int_equal(sendto_call_count, 0); assert_null(sendto_last_message); @@ -75,7 +76,6 @@ void test_lan_send_message_inhibit_cluster(void **state) { send_lan_message(LOGENTRY, "160...."); assert_int_equal(sendto_call_count, 1); check_line_format(LOGENTRY, "160...."); - }