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);
|
size_t len);
|
||||||
|
|
||||||
ssize_t patty_ax25_frame_encode_reply_to(patty_ax25_frame *frame,
|
ssize_t patty_ax25_frame_encode_reply_to(patty_ax25_frame *frame,
|
||||||
void *buf,
|
patty_ax25_frame *reply,
|
||||||
enum patty_ax25_frame_format format,
|
enum patty_ax25_frame_format format,
|
||||||
uint16_t control,
|
void *buf,
|
||||||
uint8_t proto,
|
|
||||||
void *info,
|
|
||||||
size_t infolen,
|
|
||||||
size_t len);
|
size_t len);
|
||||||
|
|
||||||
enum patty_ax25_version patty_ax25_frame_version(patty_ax25_frame *frame);
|
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,
|
ssize_t patty_ax25_frame_encode_reply_to(patty_ax25_frame *frame,
|
||||||
void *buf,
|
patty_ax25_frame *reply,
|
||||||
enum patty_ax25_frame_format format,
|
enum patty_ax25_frame_format format,
|
||||||
uint16_t control,
|
void *buf,
|
||||||
uint8_t proto,
|
|
||||||
void *info,
|
|
||||||
size_t infolen,
|
|
||||||
size_t len) {
|
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) {
|
switch (format) {
|
||||||
case PATTY_AX25_FRAME_NORMAL:
|
case PATTY_AX25_FRAME_NORMAL:
|
||||||
((uint8_t *)buf)[offset++] = control;
|
((uint8_t *)buf)[offset++] = reply->control;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PATTY_AX25_FRAME_EXTENDED:
|
case PATTY_AX25_FRAME_EXTENDED:
|
||||||
((uint8_t *)buf)[offset++] = (control & 0xff00) >> 8;
|
((uint8_t *)buf)[offset++] = (reply->control & 0xff00) >> 8;
|
||||||
((uint8_t *)buf)[offset++] = control & 0xf00ff;
|
((uint8_t *)buf)[offset++] = reply->control & 0xf00ff;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PATTY_AX25_CONTROL_INFO(control)) {
|
if (PATTY_AX25_CONTROL_INFO(reply->control)) {
|
||||||
if (1 + offset + infolen > len) {
|
if (len < 1 + offset + reply->infolen) {
|
||||||
goto error_toobig;
|
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;
|
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;
|
sock->hops = hops;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int reply_to(patty_ax25_frame *frame,
|
static int reply_to(patty_ax25_if *iface,
|
||||||
patty_ax25_if *iface,
|
patty_ax25_frame *frame,
|
||||||
enum patty_ax25_frame_format format,
|
patty_ax25_frame *reply,
|
||||||
uint16_t control,
|
enum patty_ax25_frame_format format) {
|
||||||
uint8_t proto,
|
|
||||||
void *info,
|
|
||||||
size_t infolen) {
|
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
|
|
||||||
if ((len = patty_ax25_frame_encode_reply_to(frame,
|
if ((len = patty_ax25_frame_encode_reply_to(frame,
|
||||||
iface->tx_buf,
|
reply,
|
||||||
PATTY_AX25_FRAME_NORMAL,
|
PATTY_AX25_FRAME_NORMAL,
|
||||||
control,
|
iface->tx_buf,
|
||||||
proto,
|
|
||||||
NULL,
|
|
||||||
0,
|
|
||||||
iface->tx_bufsz)) < 0) {
|
iface->tx_bufsz)) < 0) {
|
||||||
goto error_toobig;
|
goto error_toobig;
|
||||||
}
|
}
|
||||||
|
@ -1095,28 +1089,30 @@ error_toobig:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int reply_dm(patty_ax25_frame *frame,
|
static int reply_dm(patty_ax25_if *iface,
|
||||||
patty_ax25_if *iface,
|
patty_ax25_frame *frame,
|
||||||
enum patty_ax25_frame_u_flags flags) {
|
enum patty_ax25_frame_u_flags flags) {
|
||||||
return reply_to(frame,
|
patty_ax25_frame reply = {
|
||||||
iface,
|
.control = PATTY_AX25_FRAME_U_DM | flags,
|
||||||
PATTY_AX25_FRAME_NORMAL,
|
.proto = PATTY_AX25_PROTO_NONE,
|
||||||
PATTY_AX25_FRAME_U_DM | flags,
|
.info = NULL,
|
||||||
PATTY_AX25_PROTO_NONE,
|
.infolen = 0
|
||||||
NULL,
|
};
|
||||||
0);
|
|
||||||
|
return reply_to(iface, frame, &reply, PATTY_AX25_FRAME_NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int reply_ua(patty_ax25_frame *frame,
|
static int reply_ua(patty_ax25_if *iface,
|
||||||
patty_ax25_if *iface,
|
patty_ax25_frame *frame,
|
||||||
enum patty_ax25_frame_u_flags flags) {
|
enum patty_ax25_frame_u_flags flags) {
|
||||||
return reply_to(frame,
|
patty_ax25_frame reply = {
|
||||||
iface,
|
.control = PATTY_AX25_FRAME_U_UA | flags,
|
||||||
PATTY_AX25_FRAME_NORMAL,
|
.proto = PATTY_AX25_PROTO_NONE,
|
||||||
PATTY_AX25_FRAME_U_UA | flags,
|
.info = NULL,
|
||||||
PATTY_AX25_PROTO_NONE,
|
.infolen = 0
|
||||||
NULL,
|
};
|
||||||
0);
|
|
||||||
|
return reply_to(iface, frame, &reply, PATTY_AX25_FRAME_NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int handle_frame(patty_ax25_server *server,
|
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,
|
if ((sock = sock_by_addr(server->socks_pending_accept,
|
||||||
&frame.dest)) == NULL) {
|
&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;
|
goto error_io;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue