diff --git a/src/aprs_is.c b/src/aprs_is.c index fa4da9b..bf10265 100644 --- a/src/aprs_is.c +++ b/src/aprs_is.c @@ -320,24 +320,30 @@ ssize_t patty_ax25_aprs_is_send(patty_ax25_aprs_is *aprs, size_t len) { patty_ax25_frame frame; - size_t offset = 0; + size_t i = 0, + o = 0, + hop; + ssize_t decoded; - int formatted, - i; + int formatted; char call[PATTY_AX25_ADDRSTRLEN+1]; if ((decoded = patty_ax25_frame_decode_address(&frame, buf, len)) < 0) { goto error; + } else { + i += decoded; } - if (patty_ax25_frame_decode_control(&frame, - PATTY_AX25_FRAME_NORMAL, - buf, - decoded, - len) < 0) { + if ((decoded = patty_ax25_frame_decode_control(&frame, + PATTY_AX25_FRAME_NORMAL, + buf, + i, + len)) < 0) { goto error; + } else { + i += decoded; } 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) { goto error; } else { - offset += formatted; + o += formatted; } if (patty_ax25_ntop(&frame.dest, call, sizeof(call)) < 0) { goto error; } - if ((formatted = snprintf(aprs->tx_buf + offset, - aprs->tx_bufsz - offset, + if ((formatted = snprintf(aprs->tx_buf + o, + aprs->tx_bufsz - o, "%s", call)) < 0) { goto error; } else { - offset += formatted; + o += formatted; } - for (i=0; itx_buf + offset, - aprs->tx_bufsz - offset, + if ((formatted = snprintf(aprs->tx_buf + o, + aprs->tx_bufsz - o, ",%s", call)) < 0) { goto error; } else { - offset += formatted; + o += formatted; } } - if (aprs->tx_bufsz - offset < frame.infolen + 3) { + if (aprs->tx_bufsz < o + frame.infolen + 3) { errno = EOVERFLOW; 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[offset++] = '\n'; + aprs->tx_buf[o++] = '\r'; + 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: return -1;