summaryrefslogtreecommitdiffstats
path: root/lib/libnetgraph/sock.c
diff options
context:
space:
mode:
authorru <ru@FreeBSD.org>2004-01-27 20:25:14 +0000
committerru <ru@FreeBSD.org>2004-01-27 20:25:14 +0000
commitadc82a1e80759afba2cfae432d4ee1ca190be1f4 (patch)
tree92ee6204e54cff03c751ded7b2d193159acbf5f2 /lib/libnetgraph/sock.c
parentf24f6452fe6f2143c7c182fae610d62cfa8994b8 (diff)
downloadFreeBSD-src-adc82a1e80759afba2cfae432d4ee1ca190be1f4.zip
FreeBSD-src-adc82a1e80759afba2cfae432d4ee1ca190be1f4.tar.gz
- Added three new interfaces, NgAllocRecvMsg(), NgAllocRecvAsciiMsg(),
and NgAllocRecvData(), that dynamically allocate buffer for a binary message, an ascii message, and a data packet, respectively. The size of the allocated buffer is equal to the socket's receive buffer size to guarantee that a message or a data packet is not truncated. - Get rid of the static size buffer in NgSendAsciiMsg(). OK'ed by: archie, julian
Diffstat (limited to 'lib/libnetgraph/sock.c')
-rw-r--r--lib/libnetgraph/sock.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/libnetgraph/sock.c b/lib/libnetgraph/sock.c
index 7485baa..070abea 100644
--- a/lib/libnetgraph/sock.c
+++ b/lib/libnetgraph/sock.c
@@ -243,6 +243,24 @@ NgRecvData(int ds, u_char * buf, size_t len, char *hook)
}
/*
+ * Identical to NgRecvData() except buffer is dynamically allocated.
+ */
+int
+NgAllocRecvData(int ds, u_char **buf, char *hook)
+{
+ int len;
+ socklen_t optlen;
+
+ optlen = sizeof(len);
+ if (getsockopt(ds, SOL_SOCKET, SO_RCVBUF, &len, &optlen) == -1 ||
+ (*buf = malloc(len)) == NULL)
+ return (-1);
+ if ((len = NgRecvData(ds, *buf, len, hook)) < 0)
+ free(*buf);
+ return (len);
+}
+
+/*
* Write a packet to a data socket. The packet will be sent
* out the corresponding node on the specified hook.
* Returns -1 if error and sets errno.
OpenPOWER on IntegriCloud