1 /* Example usage of libradsec-base, using blocking i/o. */
10 next_packet (const struct rs_handle *ctx, int fd)
12 uint8_t hdr[RS_HEADER_LEN];
18 /* Read fixed length header. */
20 while (n < RS_HEADER_LEN)
21 n += read (fd, hdr, RS_HEADER_LEN - n);
23 p = rs_packet_new (ctx, hdr, &len);
24 fprintf (stderr, "DEBUG: got header, total packet len is %d\n",
27 /* Read the rest of the message. */
35 n += read (fd, buf, len - n);
36 p = rs_packet_parse (ctx, &p, buf, len);
40 rs_packet_free (ctx, &p);
47 send_packet(const struct rs_handle *ctx, int fd, struct rs_packet *p)
50 ssize_t n = -20; /* Arbitrary packet size -- a guess. */
54 buf = realloc (buf, -n);
57 n = rs_packet_serialize (p, buf, -n);
62 ssize_t count = write (fd, buf, n);
69 rs_packet_free (ctx, &p);