Fix invalid return in patty_ax25_aprs_is_send()

Fix invalid return in patty_ax25_aprs_is_send() wherein the number of
bytes written to APRS-IS was returned, rather than the number of AX.25
packet bytes; the number of bytes read is the more important value as it
is used later for repeating the frame to promiscuous mode SOCK_RAW
sockets
This commit is contained in:
XANTRONIX Development 2020-09-23 09:12:14 -05:00 committed by XANTRONIX Industrial
parent 9f6f775ee4
commit 54d6324dea

View file

@ -320,24 +320,30 @@ ssize_t patty_ax25_aprs_is_send(patty_ax25_aprs_is *aprs,
size_t len) { size_t len) {
patty_ax25_frame frame; patty_ax25_frame frame;
size_t offset = 0; size_t i = 0,
o = 0,
hop;
ssize_t decoded; ssize_t decoded;
int formatted, int formatted;
i;
char call[PATTY_AX25_ADDRSTRLEN+1]; char call[PATTY_AX25_ADDRSTRLEN+1];
if ((decoded = patty_ax25_frame_decode_address(&frame, buf, len)) < 0) { if ((decoded = patty_ax25_frame_decode_address(&frame, buf, len)) < 0) {
goto error; goto error;
} else {
i += decoded;
} }
if (patty_ax25_frame_decode_control(&frame, if ((decoded = patty_ax25_frame_decode_control(&frame,
PATTY_AX25_FRAME_NORMAL, PATTY_AX25_FRAME_NORMAL,
buf, buf,
decoded, i,
len) < 0) { len)) < 0) {
goto error; goto error;
} else {
i += decoded;
} }
if (!PATTY_AX25_FRAME_CONTROL_UI(frame.control)) { if (!PATTY_AX25_FRAME_CONTROL_UI(frame.control)) {
@ -354,55 +360,59 @@ ssize_t patty_ax25_aprs_is_send(patty_ax25_aprs_is *aprs,
call)) < 0) { call)) < 0) {
goto error; goto error;
} else { } else {
offset += formatted; o += formatted;
} }
if (patty_ax25_ntop(&frame.dest, call, sizeof(call)) < 0) { if (patty_ax25_ntop(&frame.dest, call, sizeof(call)) < 0) {
goto error; goto error;
} }
if ((formatted = snprintf(aprs->tx_buf + offset, if ((formatted = snprintf(aprs->tx_buf + o,
aprs->tx_bufsz - offset, aprs->tx_bufsz - o,
"%s", "%s",
call)) < 0) { call)) < 0) {
goto error; goto error;
} else { } else {
offset += formatted; o += formatted;
} }
for (i=0; i<frame.hops; i++) { for (hop=0; hop<frame.hops; hop++) {
if (patty_ax25_ntop(&frame.repeaters[i], if (patty_ax25_ntop(&frame.repeaters[hop],
call, call,
sizeof(call)) < 0) { sizeof(call)) < 0) {
goto error; goto error;
} }
if ((formatted = snprintf(aprs->tx_buf + offset, if ((formatted = snprintf(aprs->tx_buf + o,
aprs->tx_bufsz - offset, aprs->tx_bufsz - o,
",%s", ",%s",
call)) < 0) { call)) < 0) {
goto error; goto error;
} else { } else {
offset += formatted; o += formatted;
} }
} }
if (aprs->tx_bufsz - offset < frame.infolen + 3) { if (aprs->tx_bufsz < o + frame.infolen + 3) {
errno = EOVERFLOW; errno = EOVERFLOW;
goto error; goto error;
} }
aprs->tx_buf[offset++] = ':'; aprs->tx_buf[o++] = ':';
memcpy(aprs->tx_buf + offset, frame.info, frame.infolen); memcpy(aprs->tx_buf + o, frame.info, frame.infolen);
offset += frame.infolen; o += frame.infolen;
aprs->tx_buf[offset++] = '\r'; aprs->tx_buf[o++] = '\r';
aprs->tx_buf[offset++] = '\n'; aprs->tx_buf[o++] = '\n';
return write(aprs->fd, aprs->tx_buf, offset); if (write(aprs->fd, aprs->tx_buf, o) < 0) {
goto error;
}
return i;
error: error:
return -1; return -1;