Allocate a socket buffer. */
| 1644 | |
| 1645 | /* Allocate a socket buffer. */ |
| 1646 | struct socketbuf *alloc_socketbuf(char *buffer, size_t size, int copy, struct sockaddr_storage *dest) |
| 1647 | { |
| 1648 | struct socketbuf *socketbuf; |
| 1649 | |
| 1650 | socketbuf = (struct socketbuf *)malloc(sizeof(struct socketbuf)); |
| 1651 | if (!socketbuf) { |
| 1652 | ERROR("Could not allocate socket buffer!"); |
| 1653 | } |
| 1654 | memset(socketbuf, 0, sizeof(struct socketbuf)); |
| 1655 | if (copy) { |
| 1656 | socketbuf->buf = (char *)malloc(size); |
| 1657 | if (!socketbuf->buf) { |
| 1658 | ERROR("Could not allocate socket buffer data!"); |
| 1659 | } |
| 1660 | memcpy(socketbuf->buf, buffer, size); |
| 1661 | } else { |
| 1662 | socketbuf->buf = buffer; |
| 1663 | } |
| 1664 | socketbuf->len = size; |
| 1665 | socketbuf->offset = 0; |
| 1666 | if (dest) { |
| 1667 | memcpy(&socketbuf->addr, dest, sizeof(*dest)); |
| 1668 | } |
| 1669 | socketbuf->next = nullptr; |
| 1670 | |
| 1671 | return socketbuf; |
| 1672 | } |
| 1673 | |
| 1674 | /* Free a poll buffer. */ |
| 1675 | void free_socketbuf(struct socketbuf *socketbuf) |
no test coverage detected