diff --git a/src/node/socket.cc b/src/node/socket.cc index 768fdd170..18a15b0e9 100644 --- a/src/node/socket.cc +++ b/src/node/socket.cc @@ -130,6 +130,14 @@ Socket::Recv (void) return Recv (std::numeric_limits::max(), 0); } +int +Socket::Recv (uint8_t* buf, uint32_t size, uint32_t flags) +{ + Ptr p = Recv (size, flags); // read up to "size" bytes + memcpy (buf, p->PeekData (), p->GetSize()); + return p->GetSize (); +} + int Socket::SendTo (const uint8_t* buf, uint32_t size, const Address &address) { NS_LOG_FUNCTION_NOARGS (); diff --git a/src/node/socket.h b/src/node/socket.h index d0705762f..b0f53e8eb 100644 --- a/src/node/socket.h +++ b/src/node/socket.h @@ -328,6 +328,19 @@ public: * 0 if the socket cannot return a next in-sequence packet. */ Ptr Recv (void); + /** + * \brief Recv data (or dummy data) from the remote host + * \param buf A pointer to a raw byte buffer to write the data to. + * If the underlying packet was carring null (fake) data, this buffer + * will be zeroed up to the length specified by the return value. + * \param size Number of bytes (at most) to copy to buf + * \param flags any flags to pass to the socket + * \returns number of bytes copied into buf + * + * This is provided so as to have an API which is closer in appearance + * to that of real network or BSD sockets. + */ + int Recv (uint8_t* buf, uint32_t size, uint32_t flags); /** * Return number of bytes which can be returned from one or * multiple calls to Recv.