aboutsummaryrefslogtreecommitdiff
path: root/lib/libnetgraph/sock.c
diff options
context:
space:
mode:
authorRuslan Ermilov <ru@FreeBSD.org>2004-01-27 20:25:14 +0000
committerRuslan Ermilov <ru@FreeBSD.org>2004-01-27 20:25:14 +0000
commitd15ff417789ca1926d26a34db3d6c0137178cda6 (patch)
tree92ee6204e54cff03c751ded7b2d193159acbf5f2 /lib/libnetgraph/sock.c
parenta753b14687c3a4c97ed982a6e9349e8eecc8b73b (diff)
- 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
Notes
Notes: svn path=/head/; revision=125113
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 7485baa6830f..070abea9852d 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.