FreeBSD/contrib/bsnmp/snmpd/main.c
/*
 * Input from a stream socket.
 */
Input from a stream socket.
Input from a stream socket .
static int
recv_stream(struct port_input *pi)
{
	struct msghdr msg;
	struct iovec iov[1];
	ssize_t len;
	if (pi->buf == NULL) {
		if ((pi->buf = buf_alloc(0)) == NULL) {
			return (-1);
		}
		pi->buflen = buf_size(0);
		pi->consumed = 0;
		pi->length = 0;
	}
	msg.msg_name = pi->peer;
	msg.msg_namelen = pi->peerlen;
	msg.msg_iov = iov;
	msg.msg_iovlen = 1;
	msg.msg_control = NULL;
	msg.msg_controllen = 0;
	msg.msg_flags = 0;
	iov[0].iov_base = pi->buf + pi->length;
	iov[0].iov_len = pi->buflen - pi->length;
	len = recvmsg(pi->fd, &msg, 0);
	if (len == -1 || len == 0)
		return (-1);
	pi->length += len;
	if (pi->cred)
		check_priv_stream(pi);
	return (0);
}
static int recv_stream ( struct port_input * pi ) { struct msghdr msg ; struct iovec iov [ 1 ] ; ssize_t len ; if ( pi -> buf == NULL ) { if ( ( pi -> buf = buf_alloc ( 0 ) ) == NULL ) { return ( -1 ) ; } pi -> buflen = buf_size ( 0 ) ; pi -> consumed = 0 ; pi -> length = 0 ; } msg . msg_name = pi -> peer ; msg . msg_namelen = pi -> peerlen ; msg . msg_iov = iov ; msg . msg_iovlen = 1 ; msg . msg_control = NULL ; msg . msg_controllen = 0 ; msg . msg_flags = 0 ; iov [ 0 ] . iov_base = pi -> buf + pi -> length ; iov [ 0 ] . iov_len = pi -> buflen - pi -> length ; len = recvmsg ( pi -> fd , & msg , 0 ) ; if ( len == -1 || len == 0 ) return ( -1 ) ; pi -> length += len ; if ( pi -> cred ) check_priv_stream ( pi ) ; return ( 0 ) ; }
Input from a stream socket.
Input from a stream socket .
/* no buffer yet - allocate one */ /* ups - could not get buffer. Return an error
			 * the caller must close the transport. */ /* try to get a message */ /* receive error */