OpenBSD manual page server

Manual Page Search Parameters

SOCKATMARK(3) Library Functions Manual SOCKATMARK(3)

sockatmarkdetermine whether the read pointer is at the out-of-band data mark

#include <sys/socket.h>

int
sockatmark(int s);

The () function returns 1 if the read pointer for the socket s is currently at the out-of-band data mark. Otherwise, it returns 0 if the socket doesn't have an out-of-band data mark or if there is normal data to be received before the mark.

Upon successful completion, the sockatmark() function returns the value 1 if the read pointer is pointing at the out-of-band data mark, 0 if it is not. Otherwise the value -1 is returned and the global variable errno is set to indicate the error.

The routine used in the historical remote login process to flush output on receipt of an interrupt or quit signal is shown below. It reads the normal data up to the mark (to discard it), then reads the out-of-band byte.

#include <sys/socket.h>
...
oob()
{
	int mark;
	char waste[BUFSIZ];

	for (;;) {
		if ((mark = sockatmark(rem)) < 0) {
			perror("sockatmark");
			break;
		}
		if (mark)
			break;
		(void) read(rem, waste, sizeof (waste));
	}
	if (recv(rem, &mark, 1, MSG_OOB) < 0) {
		perror("recv");
		...
	}
	...
}

The sockatmark() call fails if:

[]
s is not a valid descriptor.
[]
s is valid but does not refer to a socket.

recv(2), send(2)

The sockatmark() function conforms to IEEE Std 1003.1-2008 (“POSIX.1”).

The sockatmark() function was introduced by IEEE Std 1003.1-2001 (“POSIX.1”) to standardize the historical SIOCATMARK ioctl(2). The sockatmark() function appeared in OpenBSD 5.7.

The ENOTTY error is returned instead of the usual ENOTSOCK error to match the historical behavior of SIOCATMARK.

August 31, 2014 OpenBSD-6.4