title: Arm Development of a Client Server program
body: <p>I have an old program from class that was a 1 client, 1 server written super basic 'chat' program in c, the code is below.  I'm trying to compile it now for angstrom (running on an ARM chip), and am getting these errors.  I installed the angstrom tool chain, do I need a special versions of sys/socket.h (or a different header, forgot which header the read/write/close functions were located in) etc that are made for arm?</p>
  
  <p>Error:</p>
  
  <pre><code>~/Desktop/test $ arm-angstrom-linux-gnueabi-g++ main.c -o main -lnsl
  main.c: In function 'int main()':
  main.c:66: error: invalid conversion from 'int*' to 'socklen_t*'
  main.c:66: error:   initializing argument 3 of 'int accept(int, sockaddr*, socklen_t*)'
  main.c:75: error: 'read' was not declared in this scope
  main.c:77: error: 'write' was not declared in this scope
  main.c:79: error: 'close' was not declared in this scope
  main.c:81: error: 'unlink' was not declared in this scope
  </code></pre>
  
  <p>I directly copied the code from the class, so the first error may just be something silly, but the last couple say they can't even find a lot of the functions I need...but then somehow it recognizes the accept command, and tells me I'm using the wrong arguments :/  Any ideas?</p>
  
  <p>Code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/socket.h&gt;  /* define socket */
  #include &lt;netinet/in.h&gt;  /* define internet socket */
  #include &lt;netdb.h&gt;       /* define internet socket */
  
  #define SERVER_PORT 9999        /* define a server port number */
  
  int main()
  {
      int sd, ns, k;
      struct sockaddr_in server_addr = { AF_INET, htons( SERVER_PORT ) };
      struct sockaddr_in client_addr = { AF_INET };
      int client_len = sizeof( client_addr );
      char buf[512], *host;
  
      /* create a stream socket */
      if( ( sd = socket( AF_INET, SOCK_STREAM, 0 ) ) == -1 )
      {
      perror( "server: socket failed" );
      exit( 1 );
      }
  
      /* bind the socket to an internet port */
      if( bind(sd, (struct sockaddr*)&amp;server_addr, sizeof(server_addr)) == -1 )
      {
      perror( "server: bind failed" );
      exit( 1 );
      }
  
      /* listen for clients */
      if( listen( sd, 1 ) == -1 )
      {
      perror( "server: listen failed" );
      exit( 1 );
      }
  
      printf("SERVER is listening for clients to establish a connection\n");
  
      if( ( ns = accept( sd, (struct sockaddr*)&amp;client_addr,
                         &amp;client_len ) ) == -1 )
      {
          perror( "server: accept failed" );
          exit( 1 );
      }
  
      printf("accept() successful.. a client has connected! waiting for a message\n");
  
      /* data transfer on connected socket ns */
      while( (k = read(ns, buf, sizeof(buf))) != 0)
      {    printf("SERVER RECEIVED: %s\n", buf);
           write(ns, buf, k);
      }
      close(ns);
      close(sd);
      unlink(server_addr.sin_addr);
  
      return(0);
  }
  </code></pre>