Huh, I managed to make something nice
This commit is contained in:
parent
d5ee0c7a9e
commit
7fd05f607a
3 changed files with 43 additions and 51 deletions
|
@ -71,12 +71,9 @@ ssize_t patty_ax25_frame_encode(patty_ax25_frame *frame,
|
|||
size_t len);
|
||||
|
||||
ssize_t patty_ax25_frame_encode_reply_to(patty_ax25_frame *frame,
|
||||
void *buf,
|
||||
patty_ax25_frame *reply,
|
||||
enum patty_ax25_frame_format format,
|
||||
uint16_t control,
|
||||
uint8_t proto,
|
||||
void *info,
|
||||
size_t infolen,
|
||||
void *buf,
|
||||
size_t len);
|
||||
|
||||
enum patty_ax25_version patty_ax25_frame_version(patty_ax25_frame *frame);
|
||||
|
|
29
src/frame.c
29
src/frame.c
|
@ -335,40 +335,39 @@ error_toobig:
|
|||
}
|
||||
|
||||
ssize_t patty_ax25_frame_encode_reply_to(patty_ax25_frame *frame,
|
||||
void *buf,
|
||||
patty_ax25_frame *reply,
|
||||
enum patty_ax25_frame_format format,
|
||||
uint16_t control,
|
||||
uint8_t proto,
|
||||
void *info,
|
||||
size_t infolen,
|
||||
void *buf,
|
||||
size_t len) {
|
||||
size_t offset = 0;
|
||||
size_t offset;
|
||||
|
||||
offset = encode_reply_address(frame, buf, len);
|
||||
if ((offset = encode_reply_address(frame, buf, len)) < 0) {
|
||||
goto error_toobig;
|
||||
}
|
||||
|
||||
switch (format) {
|
||||
case PATTY_AX25_FRAME_NORMAL:
|
||||
((uint8_t *)buf)[offset++] = control;
|
||||
((uint8_t *)buf)[offset++] = reply->control;
|
||||
|
||||
break;
|
||||
|
||||
case PATTY_AX25_FRAME_EXTENDED:
|
||||
((uint8_t *)buf)[offset++] = (control & 0xff00) >> 8;
|
||||
((uint8_t *)buf)[offset++] = control & 0xf00ff;
|
||||
((uint8_t *)buf)[offset++] = (reply->control & 0xff00) >> 8;
|
||||
((uint8_t *)buf)[offset++] = reply->control & 0xf00ff;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (PATTY_AX25_CONTROL_INFO(control)) {
|
||||
if (1 + offset + infolen > len) {
|
||||
if (PATTY_AX25_CONTROL_INFO(reply->control)) {
|
||||
if (len < 1 + offset + reply->infolen) {
|
||||
goto error_toobig;
|
||||
}
|
||||
|
||||
((uint8_t *)buf)[offset++] = proto;
|
||||
((uint8_t *)buf)[offset++] = reply->proto;
|
||||
|
||||
memcpy((uint8_t *)buf + offset, info, infolen);
|
||||
memcpy((uint8_t *)buf + offset, reply->info, reply->infolen);
|
||||
|
||||
offset += infolen;
|
||||
offset += reply->infolen;
|
||||
}
|
||||
|
||||
return offset;
|
||||
|
|
58
src/server.c
58
src/server.c
|
@ -1069,22 +1069,16 @@ static void save_reply_addr(patty_ax25_sock *sock,
|
|||
sock->hops = hops;
|
||||
}
|
||||
|
||||
static int reply_to(patty_ax25_frame *frame,
|
||||
patty_ax25_if *iface,
|
||||
enum patty_ax25_frame_format format,
|
||||
uint16_t control,
|
||||
uint8_t proto,
|
||||
void *info,
|
||||
size_t infolen) {
|
||||
static int reply_to(patty_ax25_if *iface,
|
||||
patty_ax25_frame *frame,
|
||||
patty_ax25_frame *reply,
|
||||
enum patty_ax25_frame_format format) {
|
||||
ssize_t len;
|
||||
|
||||
if ((len = patty_ax25_frame_encode_reply_to(frame,
|
||||
iface->tx_buf,
|
||||
reply,
|
||||
PATTY_AX25_FRAME_NORMAL,
|
||||
control,
|
||||
proto,
|
||||
NULL,
|
||||
0,
|
||||
iface->tx_buf,
|
||||
iface->tx_bufsz)) < 0) {
|
||||
goto error_toobig;
|
||||
}
|
||||
|
@ -1095,28 +1089,30 @@ error_toobig:
|
|||
return -1;
|
||||
}
|
||||
|
||||
static int reply_dm(patty_ax25_frame *frame,
|
||||
patty_ax25_if *iface,
|
||||
static int reply_dm(patty_ax25_if *iface,
|
||||
patty_ax25_frame *frame,
|
||||
enum patty_ax25_frame_u_flags flags) {
|
||||
return reply_to(frame,
|
||||
iface,
|
||||
PATTY_AX25_FRAME_NORMAL,
|
||||
PATTY_AX25_FRAME_U_DM | flags,
|
||||
PATTY_AX25_PROTO_NONE,
|
||||
NULL,
|
||||
0);
|
||||
patty_ax25_frame reply = {
|
||||
.control = PATTY_AX25_FRAME_U_DM | flags,
|
||||
.proto = PATTY_AX25_PROTO_NONE,
|
||||
.info = NULL,
|
||||
.infolen = 0
|
||||
};
|
||||
|
||||
return reply_to(iface, frame, &reply, PATTY_AX25_FRAME_NORMAL);
|
||||
}
|
||||
|
||||
static int reply_ua(patty_ax25_frame *frame,
|
||||
patty_ax25_if *iface,
|
||||
static int reply_ua(patty_ax25_if *iface,
|
||||
patty_ax25_frame *frame,
|
||||
enum patty_ax25_frame_u_flags flags) {
|
||||
return reply_to(frame,
|
||||
iface,
|
||||
PATTY_AX25_FRAME_NORMAL,
|
||||
PATTY_AX25_FRAME_U_UA | flags,
|
||||
PATTY_AX25_PROTO_NONE,
|
||||
NULL,
|
||||
0);
|
||||
patty_ax25_frame reply = {
|
||||
.control = PATTY_AX25_FRAME_U_UA | flags,
|
||||
.proto = PATTY_AX25_PROTO_NONE,
|
||||
.info = NULL,
|
||||
.infolen = 0
|
||||
};
|
||||
|
||||
return reply_to(iface, frame, &reply, PATTY_AX25_FRAME_NORMAL);
|
||||
}
|
||||
|
||||
static int handle_frame(patty_ax25_server *server,
|
||||
|
@ -1137,7 +1133,7 @@ static int handle_frame(patty_ax25_server *server,
|
|||
|
||||
if ((sock = sock_by_addr(server->socks_pending_accept,
|
||||
&frame.dest)) == NULL) {
|
||||
if (reply_dm(&frame, iface, PATTY_AX25_FRAME_U_FINAL) < 0) {
|
||||
if (reply_dm(iface, &frame, PATTY_AX25_FRAME_U_FINAL) < 0) {
|
||||
goto error_io;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue