OS X doesn't offer the SO_PROTOCOL
socket option which allows the caller to "...retrieve the socket type as an integer." (http://linux.die.net/man/7/socket)
In other words the following program builds and works under linux but won't compile under OS X:
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
int main(int argc, char **argv)
{
int c, s, type, len;
len = sizeof(type);
s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (s < 0)
{
fprintf(stderr, "socket kaboom: %s\n", strerror(errno));
return 1;
}
if (getsockopt(s, SOL_SOCKET, SO_PROTOCOL, &type, &len) < 0)
{
fprintf(stderr, "getsosockopt kaboom: %s\n", strerror(errno));
return 1;
}
printf("socket type: %d\n", type);
return 0;
}
How to accomplish this under OS X?