Only need one of those memcpy() around
This commit is contained in:
parent
3759469611
commit
0decdda086
1 changed files with 8 additions and 11 deletions
19
src/frame.c
19
src/frame.c
|
@ -3,8 +3,9 @@
|
||||||
|
|
||||||
#include <patty/ax25.h>
|
#include <patty/ax25.h>
|
||||||
|
|
||||||
static ssize_t validate_station(void *data,
|
static ssize_t decode_station(patty_ax25_addr *addr,
|
||||||
off_t offset) {
|
void *data,
|
||||||
|
off_t offset) {
|
||||||
int i, space = 0;
|
int i, space = 0;
|
||||||
|
|
||||||
for (i=0; i<PATTY_AX25_CALLSIGN_LEN; i++) {
|
for (i=0; i<PATTY_AX25_CALLSIGN_LEN; i++) {
|
||||||
|
@ -26,6 +27,8 @@ static ssize_t validate_station(void *data,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memcpy(addr, ((uint8_t *)data) + offset, sizeof(*addr));
|
||||||
|
|
||||||
return PATTY_AX25_ADDRESS_SIZE;
|
return PATTY_AX25_ADDRESS_SIZE;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
@ -49,11 +52,9 @@ static ssize_t decode_hops(patty_ax25_frame *frame,
|
||||||
for (i=0; i<PATTY_AX25_MAX_HOPS; i++) {
|
for (i=0; i<PATTY_AX25_MAX_HOPS; i++) {
|
||||||
addr = (patty_ax25_addr *)((uint8_t *)data + offset);
|
addr = (patty_ax25_addr *)((uint8_t *)data + offset);
|
||||||
|
|
||||||
if ((decoded = validate_station(data, offset)) < 0) {
|
if ((decoded = decode_station(&frame->repeaters[i], data, offset)) < 0) {
|
||||||
goto error;
|
goto error;
|
||||||
} else {
|
} else {
|
||||||
memcpy(&frame->repeaters[i], addr, sizeof(*addr));
|
|
||||||
|
|
||||||
offset += decoded;
|
offset += decoded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,19 +87,15 @@ static ssize_t decode_address(patty_ax25_frame *frame,
|
||||||
off_t offset = start;
|
off_t offset = start;
|
||||||
ssize_t decoded;
|
ssize_t decoded;
|
||||||
|
|
||||||
if ((decoded = validate_station(data, offset)) < 0) {
|
if ((decoded = decode_station(&frame->dest, data, offset)) < 0) {
|
||||||
goto error;
|
goto error;
|
||||||
} else {
|
} else {
|
||||||
memcpy(&frame->dest, ((uint8_t *)data) + offset, sizeof(frame->dest));
|
|
||||||
|
|
||||||
offset += decoded;
|
offset += decoded;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((decoded = validate_station(data, offset)) < 0) {
|
if ((decoded = decode_station(&frame->src, data, offset)) < 0) {
|
||||||
goto error;
|
goto error;
|
||||||
} else {
|
} else {
|
||||||
memcpy(&frame->src, ((uint8_t *)data) + offset, sizeof(frame->src));
|
|
||||||
|
|
||||||
offset += decoded;
|
offset += decoded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue