summaryrefslogtreecommitdiff
path: root/lib/packet.c
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordu.net>2010-10-01 11:29:12 +0200
committerLinus Nordberg <linus@nordu.net>2010-10-01 11:29:12 +0200
commit7ec20f4101e5a1ef0b5f2537f25a4f8d74ad1104 (patch)
treee452775bb08b4c3fae7cef827834aeef21a6cfd8 /lib/packet.c
parentb1437bde86daa8826a8eeb1437cca11dda88283e (diff)
WIP
Diffstat (limited to 'lib/packet.c')
-rw-r--r--lib/packet.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/lib/packet.c b/lib/packet.c
index c90511b..5f7293c 100644
--- a/lib/packet.c
+++ b/lib/packet.c
@@ -1,3 +1,5 @@
+/* See the file COPYING for licensing information. */
+
#include <string.h>
#include <assert.h>
#include <freeradius/libradius.h>
@@ -128,8 +130,8 @@ _read_cb (struct bufferevent *bev, void *ctx)
assert (pkt->conn);
if (!pkt->hdr_read_flag)
{
- n = bufferevent_read (pkt->conn->bev, pkt->hdr, 4);
- if (n == 4)
+ n = bufferevent_read (pkt->conn->bev, pkt->hdr, RS_HEADER_LEN;
+ if (n == RS_HEADER_LEN)
{
uint16_t len = (pkt->hdr[2] << 8) + pkt->hdr[3];
uint8_t *buf = rs_malloc (pkt->conn->ctx, len);
@@ -143,7 +145,8 @@ _read_cb (struct bufferevent *bev, void *ctx)
}
pkt->rpkt->data = buf;
pkt->rpkt->data_len = len;
- bufferevent_setwatermark (pkt->conn->bev, EV_READ, len - 4, 0);
+ bufferevent_setwatermark (pkt->conn->bev, EV_READ,
+ len - RS_HEADER_LEN, 0);
#if defined (DEBUG)
fprintf (stderr, "%s: packet header read, pkt len=%d\n", __func__,
len);
@@ -153,15 +156,16 @@ _read_cb (struct bufferevent *bev, void *ctx)
return; /* Buffer frozen, i suppose. Let's hope it thaws. */
else
{
- assert (n < 4);
+ assert (n < RS_HEADER_LEN);
return; /* Need more to complete header. */
}
}
- printf ("%s: trying to read %d octets of packet data\n", __func__, pkt->rpkt->data_len - 4);
- n = bufferevent_read (pkt->conn->bev, pkt->rpkt->data, pkt->rpkt->data_len - 4);
+ printf ("%s: trying to read %d octets of packet data\n", __func__, pkt->rpkt->data_len - RS_HEADER_LEN;
+ n = bufferevent_read (pkt->conn->bev, pkt->rpkt->data,
+ pkt->rpkt->data_len - RS_HEADER_LEN);
printf ("%s: read %d octets of packet data\n", __func__, n);
- if (n == pkt->rpkt->data_len - 4)
+ if (n == pkt->rpkt->data_len - RS_HEADER_LEN)
{
bufferevent_disable (pkt->conn->bev, EV_READ);
pkt->hdr_read_flag = 0;
@@ -305,7 +309,7 @@ rs_packet_receive(struct rs_connection *conn, struct rs_packet **pkt_out)
assert (conn->active_peer);
assert (conn->active_peer->s >= 0);
- bufferevent_setwatermark (conn->bev, EV_READ, 4, 0);
+ bufferevent_setwatermark (conn->bev, EV_READ, RS_HEADER_LEN, 0);
bufferevent_enable (conn->bev, EV_READ);
event_base_dispatch (conn->evb);
#if defined (DEBUG)