Prettification, set errno on errors
This commit is contained in:
parent
3074af45c1
commit
dc55a7fc6c
1 changed files with 18 additions and 6 deletions
24
src/frame.c
24
src/frame.c
|
@ -3,7 +3,9 @@
|
|||
|
||||
#include <patty/ax25.h>
|
||||
|
||||
static ssize_t frame_decode_station(patty_ax25_address *address, void *data, off_t offset) {
|
||||
static ssize_t frame_decode_station(patty_ax25_address *address,
|
||||
void *data,
|
||||
off_t offset) {
|
||||
int i, space = 0;
|
||||
uint8_t ssid = ((uint8_t *)data + offset)[6];
|
||||
|
||||
|
@ -59,7 +61,9 @@ error:
|
|||
return -1;
|
||||
}
|
||||
|
||||
static ssize_t frame_decode_hops(patty_ax25_frame *frame, void *data, off_t start) {
|
||||
static ssize_t frame_decode_hops(patty_ax25_frame *frame,
|
||||
void *data,
|
||||
off_t start) {
|
||||
ssize_t decoded;
|
||||
off_t offset = start;
|
||||
|
||||
|
@ -101,7 +105,9 @@ error:
|
|||
return -1;
|
||||
}
|
||||
|
||||
static ssize_t frame_decode_address(patty_ax25_frame *frame, void *data, off_t start) {
|
||||
static ssize_t frame_decode_address(patty_ax25_frame *frame,
|
||||
void *data,
|
||||
off_t start) {
|
||||
off_t offset = start;
|
||||
ssize_t decoded;
|
||||
|
||||
|
@ -153,7 +159,9 @@ error:
|
|||
return -1;
|
||||
}
|
||||
|
||||
static ssize_t frame_decode_payload(patty_ax25_frame *frame, void *data, off_t offset) {
|
||||
static ssize_t frame_decode_payload(patty_ax25_frame *frame,
|
||||
void *data,
|
||||
off_t offset) {
|
||||
uint8_t control = ((uint8_t *)data + offset)[0];
|
||||
size_t decoded = 0;
|
||||
|
||||
|
@ -206,7 +214,7 @@ error:
|
|||
|
||||
int patty_ax25_frame_decode(patty_ax25_frame *frame, void *data, size_t size) {
|
||||
ssize_t decoded;
|
||||
off_t offset = 0;
|
||||
off_t offset = 0;
|
||||
|
||||
memset(frame, '\0', sizeof(*frame));
|
||||
|
||||
|
@ -216,16 +224,20 @@ int patty_ax25_frame_decode(patty_ax25_frame *frame, void *data, size_t size) {
|
|||
* First, decode the variable-length Address field.
|
||||
*/
|
||||
if ((decoded = frame_decode_address(frame, data, offset)) < 0) {
|
||||
errno = EIO;
|
||||
|
||||
goto error_decode;
|
||||
} else {
|
||||
offset += decoded;
|
||||
}
|
||||
|
||||
/*
|
||||
* Now, decode the remaining Control Field, optional Protocol Identifier
|
||||
* Next, decode the remaining Control Field, optional Protocol Identifier
|
||||
* field, and payload that may follow.
|
||||
*/
|
||||
if ((decoded = frame_decode_payload(frame, data, offset)) < 0) {
|
||||
errno = EIO;
|
||||
|
||||
goto error_decode;
|
||||
} else {
|
||||
offset += decoded;
|
||||
|
|
Loading…
Add table
Reference in a new issue