title: bind: Address family not supported by protocol
body: <p>This code works on my other vps, but with linode it doesn't.</p>
  
  <pre><code>#include &lt;sys/types.h&gt;
  #include &lt;sys/socket.h&gt;
  #include &lt;sys/wait.h&gt;
  #include &lt;netinet/in.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;errno.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;netdb.h&gt;
  #include &lt;time.h&gt;
  #include &lt;string.h&gt;
  
  #ifdef STRERROR
  extern char *sys_errlist[];
  extern int sys_nerr;
  char *undef = "Undefined error";
  
  char *strerror(error)
  int error;
  {
      if (error &gt; sys_nerr)
          return undef;
      return sys_errlist[error];
  }
  #endif
  #define CIAO_PS "bfi_2"
  
  main(argc, argv)
      int argc;
      char **argv;
  {
      int lsock, csock, osock;
      FILE *cfile;
      char buf[4096];
      struct sockaddr_in laddr, caddr, oaddr;
      int caddrlen = sizeof(caddr);
      fd_set fdsr, fdse;
      struct hostent *h;
      struct servent *s;
      int nbyt;
      unsigned long a;
      unsigned short oport;
      int i, j, argvlen;
      char *bfiargv[argc+1];
      char *fintops = CIAO_PS ;
  
      if( argc &lt; 4 )
      {
          fprintf(stderr,"Usage: %s localport remoteport remotehost fakeps\n",argv[0]);
          return 30;
      }
  
      for( i = 0; i &lt; argc; i++ )
      {
          bfiargv[i] = malloc(strlen(argv[i]) + 1);
          strncpy(bfiargv[i], argv[i], strlen(argv[i]) + 1);
      }
  
      bfiargv[argc] = NULL;
      argvlen = strlen(argv[0]);
  
      if( argvlen &lt; strlen(CIAO_PS) )
      {
          printf("Se vuoi fregare davvero ps vedi di lanciarmi almeno come superFunkyDataPipe !\n") ;
          abort();
      }
  
      if(bfiargv[4]) fintops=bfiargv[4] ;
      strncpy(argv[0], fintops, strlen(fintops));
  
      for( i = strlen(fintops); i &lt; argvlen; i++ )
          argv[0][i] = '\0';
  
      for( i = 1; i &lt; argc; i++ )
      {
          argvlen = strlen(argv[i]);
          for(j=0; j &lt;= argvlen; j++)
              argv[i][j] = '\0';
      }
  
      a = inet_addr(argv[3]);
  
      if( !(h = gethostbyname(bfiargv[3])) &amp;&amp; !(h = gethostbyaddr(&amp;a, 4, AF_INET)) )
      {
          perror(bfiargv[3]);
          return 25;
      }
  
      oport = atol(bfiargv[2]);
      laddr.sin_port = htons((unsigned short)(atol(bfiargv[1])));
  
      if( (lsock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1 )
      {
          perror("socket");
          return 20;
      }
  
      laddr.sin_family = htons(AF_INET);
      // laddr.sin_addr.s_addr = htonl(0);
      laddr.sin_addr.s_addr = inet_addr("ip address here");
  
      if( bind(lsock, &amp;laddr, sizeof(laddr)) )
      {
          perror("bind");
          return 20;
      }
  
      if( listen(lsock, 1) )
      {
          perror("listen");
          return 20;
      }
  
      if( (nbyt = fork()) == -1 )
      {
          perror("fork");
          return 20;
      }
  
      if (nbyt &gt; 0)
          return 0;
  
      setsid();
      while( (csock = accept(lsock, &amp;caddr, &amp;caddrlen)) != -1 )
      {
          cfile = fdopen(csock,"r+");
          if( (nbyt = fork()) == -1 )
          {
              fprintf(cfile, "500 fork: %s\n", strerror(errno));
              shutdown(csock,2);
              fclose(cfile);
              continue;
          }
  
          if (nbyt == 0)
              goto gotsock;
  
          fclose(cfile);
          while (waitpid(-1, NULL, WNOHANG) &gt; 0);
      }
  
      return 20;
  
  gotsock:
      if( (osock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1 )
      {
          fprintf(cfile, "500 socket: %s\n", strerror(errno));
          goto quit1;
      }
  
      oaddr.sin_family = h-&gt;h_addrtype;
      oaddr.sin_port = htons(oport);
      memcpy(&amp;oaddr.sin_addr, h-&gt;h_addr, h-&gt;h_length);
      if( connect(osock, &amp;oaddr, sizeof(oaddr)) )
      {
          fprintf(cfile, "500 connect: %s\n", strerror(errno));
          goto quit1;
      }
  
      while( 1 )
      {
          FD_ZERO(&amp;fdsr);
          FD_ZERO(&amp;fdse);
          FD_SET(csock,&amp;fdsr);
          FD_SET(csock,&amp;fdse);
          FD_SET(osock,&amp;fdsr);
          FD_SET(osock,&amp;fdse);
  
          if( select(20, &amp;fdsr, NULL, &amp;fdse, NULL) == -1 )
          {
              fprintf(cfile, "500 select: %s\n", strerror(errno));
              goto quit2;
          }
  
          if( FD_ISSET(csock,&amp;fdsr) || FD_ISSET(csock,&amp;fdse) )
          {
              if ((nbyt = read(csock,buf,4096)) &lt;= 0)
                  goto quit2;
              if ((write(osock,buf,nbyt)) &lt;= 0)
                  goto quit2;
          }
          else if( FD_ISSET(osock,&amp;fdsr) || FD_ISSET(osock,&amp;fdse) )
          {
              if ((nbyt = read(osock,buf,4096)) &lt;= 0)
                  goto quit2;
              if ((write(csock,buf,nbyt)) &lt;= 0)
                  goto quit2;
          }
      }
  
  quit2:
      shutdown(osock,2);
      close(osock);
  
  quit1:
      fflush(cfile);
      shutdown(csock,2);
  
  quit0:
      fclose(cfile);
      return 0;
  }
  </code></pre>