Wednesday, October 31, 2012

bind: Address family not supported by protocol

Trying to get ROLF running on a Raspberry Pi, I installed Debian Wheezy, but then found that my vnc server version of ROLF doesn't start up.

I've boiled the problem down to a minimal program that works fine on 2.6.32.6, but not on "Linux raspberrypi 3.2.27+ #250 PREEMPT Thu Oct 18 19:03:02 BST 2012 armv6l GNU/Linux" or "Linux Microknoppix 3.4.9 #34 SMP PREEMPT Fri Aug 17 06:30:04 CEST 2012 i686 GNU/Linux", so presumably there's a change in a major version.  All I have to do is find out what it is...

Update: It seems someone turned on the "check for idiot programmers" flag in the kernel; fix: addr.sin_family = AF_INET;

#include <sys/types.h>
#include <sys socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>

int main()
{
    int vnc_server;
    int port = 2008;

    struct sockaddr_in addr = { 0 };
    addr.sin_family = htons( AF_INET );
    addr.sin_port = htons( port );
    
    if (-1 == (vnc_server = socket( AF_INET, SOCK_STREAM, 0 )))
        perror( "socket" );

    if (0 != bind( vnc_server, (struct sockaddr*) &addr, sizeof( addr ) ))
        perror( "bind" );

    return 0;
}