diff --git a/src/utils/proto.c b/src/utils/proto.c
index d049144ca2716c7a493cab1be92f9fb698bde274..29783efd5aefb3db7cd09037f6f534fa4363b020 100644 (file)
--- a/src/utils/proto.c
+++ b/src/utils/proto.c
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include "utils/error.h"
#include "utils/proto.h"
-#include "core/error.h"
#include <arpa/inet.h>
#include <errno.h>
+#include <limits.h>
+
#include <string.h>
#include <unistd.h>
return sdb_proto_send(fd, len, buffer);
} /* sdb_proto_send_msg */
+uint32_t
+sdb_proto_get_int(sdb_strbuf_t *buf, size_t offset)
+{
+ const char *data;
+ uint32_t n;
+
+ if (! buf)
+ return UINT32_MAX;
+
+ /* not enough data to read */
+ if (offset + sizeof(uint32_t) > sdb_strbuf_len(buf))
+ return UINT32_MAX;
+
+ data = sdb_strbuf_string(buf);
+ data += offset;
+ memcpy(&n, data, sizeof(n));
+ return ntohl(n);
+} /* sdb_proto_get_int */
+
/* vim: set tw=78 sw=4 ts=4 noexpandtab : */