1 /** @file libradsec-base.h
2 @brief Low level API for libradsec. */
4 /* FIXME: License blurb goes here. */
8 #include <sys/socket.h>
11 /* Function prototypes. */
15 /** Establish a connection.
16 @param type Connection type.
17 @param addr Network address to connect to.
18 @param cred Credentials, or NULL.
19 @return A file descriptor or -1 if an error occurred, in which
20 case errno is set appropriately. */
21 int rs_connect(const struct rs_handle *conf, const struct sockaddr *addr,
25 @param fd File descriptor to close.
26 @return 0 on success or -1 if an error occurred, in which case
27 errno is set appropriately. */
28 int rs_disconnect(const struct rs_handle *conf, int fd);
30 /** Allocate and initialize a packet from a buffer containing a RADIUS
31 message header. The packet should be freed using @a
34 @param buf Buffer with on-the-wire data with RADIUS message
36 @param count Optionally a pointer to a size_t where the number of
37 additional octets needed to complete the RADIUS message will be
39 @return A pointer to a newly allocated packet or NULL on error.
41 struct rs_packet *rs_packet_new(const struct rs_handle *ctx,
42 const uint8_t buf[RS_HEADER_LEN],
45 /** Parse an on wire RADIUS packet and store it in @a packet.
47 @param packet A pointer to the address of a struct rs_packet
48 allocated by @a rs_packet_new(). Will be freed if an error
50 @param buf Buffer with on-the-wire data with RADIUS message, not
51 including the four octet RADIUS header.
52 @param buflen Number of octets in @a buf.
53 @return *packet or NULL on error. If NULL, the packet has been
54 freed and *packet is no longer valid.
56 struct rs_packet *rs_packet_parse(const struct rs_handle *ctx,
57 struct rs_packet **packet,
61 /** Free @a packet, previously allocated by @a rs_packet_new().
63 @param packet Packet to free.
65 void rs_packet_free(const struct rs_handle *ctx, struct rs_packet **packet);
67 /** Serialize @a packet into @a buf.
68 @param packet Packet to serialize.
69 @param buf Buffer to store the serialized packet in.
70 @param buflen Length of buffer.
71 @return Number of bytes written to buf or 0 if the buffer wasn't
72 large enough to hold the packet or < 0 in case the packet couldn't
73 be serialized for some other reason (FIXME: elaborate) */
75 ssize_t rs_packet_serialize(const struct rs_packet *packet,
76 uint8_t *buf, size_t buflen);
79 /** Add an attribute to a packet.
80 @param packet The packet.
81 @param attribute Attribute to add to packet. */
82 int rs_packet_add_attr(struct rs_packet *packet,
83 const struct rs_attribute *attribute);