Mohammad Hedayati at
Tue Dec 21 09:32:39 UTC 2010

I'm about to use a char device for a kind of distributed processing,
so I've coded the open function as follows. The problem is that
soaccept returns 0 without populating the raddr. I've checked netstat,
everything seems to be fine, the socket is created, bound and the
state is LISTENING. Even the remote is connection is ESTABLISHED. But,
it cannot receive anything.
open(struct cdev *dev, int flag, int otyp, struct thread *td)
	uprintf("in open...\n");
	int error = -1;	
	socktd = td;
	error = socreate(AF_INET, &sock, SOCK_STREAM, IPPROTO_TCP,
td->td_proc->p_ucred, socktd);
	if(error != 0)
		return error;
	sockaddr.sin_len = sizeof(struct sockaddr_in);
	sockaddr.sin_family = AF_INET;
	sockaddr.sin_port = htons(1234);
	sockaddr.sin_addr.s_addr = INADDR_ANY;
	error = sobind(sock, (struct sockaddr *)&sockaddr, socktd);
	uprintf("sobind error = %d\n", error);
	error = solisten(sock, 5, socktd);
	uprintf("solisten error = %d\n", error);
	error = soaccept(sock, (struct sockaddr **)&raddr);
	uprintf("soaccept error = %d, ip=%s\n", error, inet_ntoa(raddr->sin_addr));
	uprintf("out open...\n");

read(struct cdev *dev, struct uio *uio, int ioflag)
	int error = 0;
	error = soreceive(sock, (struct sockaddr **)&raddr, uio, NULL, NULL, NULL);

More information about the freebsd-questions mailing list