Esempio n. 1
0
nvlist_t *
nvlist_recv(int sock, int flags)
{
	struct nvlist_header nvlhdr;
	nvlist_t *nvl, *ret;
	unsigned char *buf;
	size_t nfds, size, i;
	int *fds;

	if (buf_recv(sock, &nvlhdr, sizeof(nvlhdr)) == -1)
		return (NULL);

	if (!nvlist_check_header(&nvlhdr))
		return (NULL);

	nfds = (size_t)nvlhdr.nvlh_descriptors;
	size = sizeof(nvlhdr) + (size_t)nvlhdr.nvlh_size;

	buf = nv_malloc(size);
	if (buf == NULL)
		return (NULL);

	memcpy(buf, &nvlhdr, sizeof(nvlhdr));

	ret = NULL;
	fds = NULL;

	if (buf_recv(sock, buf + sizeof(nvlhdr), size - sizeof(nvlhdr)) == -1)
		goto out;

	if (nfds > 0) {
		fds = nv_malloc(nfds * sizeof(fds[0]));
		if (fds == NULL)
			goto out;
		if (fd_recv(sock, fds, nfds) == -1)
			goto out;
	}

	nvl = nvlist_xunpack(buf, size, fds, nfds, flags);
	if (nvl == NULL) {
		ERRNO_SAVE();
		for (i = 0; i < nfds; i++)
			close(fds[i]);
		ERRNO_RESTORE();
		goto out;
	}

	ret = nvl;
out:
	ERRNO_SAVE();
	nv_free(buf);
	nv_free(fds);
	ERRNO_RESTORE();

	return (ret);
}
Esempio n. 2
0
nvlist_t *
nvlist_recv(int sock)
{
	struct nvlist_header nvlhdr;
	nvlist_t *nvl, *ret;
	unsigned char *buf;
	size_t nfds, size;
	int serrno, *fds;

	if (buf_recv(sock, &nvlhdr, sizeof(nvlhdr)) == -1)
		return (NULL);

	if (!nvlist_check_header(&nvlhdr))
		return (NULL);

	nfds = (size_t)nvlhdr.nvlh_descriptors;
	size = sizeof(nvlhdr) + (size_t)nvlhdr.nvlh_size;

	buf = malloc(size);
	if (buf == NULL)
		return (NULL);

	memcpy(buf, &nvlhdr, sizeof(nvlhdr));

	ret = NULL;
	fds = NULL;

	if (buf_recv(sock, buf + sizeof(nvlhdr), size - sizeof(nvlhdr)) == -1)
		goto out;

	if (nfds > 0) {
		fds = malloc(nfds * sizeof(fds[0]));
		if (fds == NULL)
			goto out;
		if (fd_recv(sock, fds, nfds) == -1)
			goto out;
	}

	nvl = nvlist_xunpack(buf, size, fds, nfds);
	if (nvl == NULL)
		goto out;

	ret = nvl;
out:
	serrno = errno;
	free(buf);
	free(fds);
	errno = serrno;

	return (ret);
}
Esempio n. 3
0
status_t
msg_recv (int fd, msg_t * msg)
{
  mr_rarray_t rarray;
  memset (&rarray, 0, sizeof (rarray));
  
  status_t status = buf_recv (fd, &rarray.MR_SIZE, sizeof (rarray.MR_SIZE));
  if (ST_SUCCESS != status)
    return (ST_FAILURE);
  
  char data[rarray.MR_SIZE];
  status = buf_recv (fd, data, rarray.MR_SIZE);
  if (ST_SUCCESS != status)
    return (ST_FAILURE);
  
  rarray.data.ptr = data;
  mr_status_t mr_status = DESERIALIZE (msg_t, &rarray, msg);
  return ((MR_SUCCESS == mr_status) ? ST_SUCCESS : ST_FAILURE);
}