dPaste

#include <sys/socket.h>

#include <arpa/inet.h>
#include <netinet/in.h>

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

void fail( char* str )   {

  perror( str );
  exit( EXIT_FAILURE );

}

int main( void )  {

  #define bsize 8192
  char buff[ bsize ];
  struct sockaddr_in6 sin6;

  memset( &sin6, 0, sizeof( sin6 ) );
  sin6.sin6_port = htons( 10000 );
  sin6.sin6_family = AF_INET6;
  sin6.sin6_addr = in6addr_any;

  int sockfd = socket( AF_INET6, SOCK_STREAM, 0 );

  if( sockfd < 0 )  fail( "sockfail" );
  if( bind( sockfd, ( struct sockaddr* ) &sin6, sizeof( sin6 ) ) < 0 )
    fail( "bindfail" );
  if( listen( sockfd, 5 ) < 0 )  fail( "listenfail" );
  
  puts( "Starting to accept sockets" );
  
  int connfd = accept( sockfd, NULL, NULL );
  if( connfd < 0 )  fail( "acceptfail" );

  close( sockfd );

  for(;;)  {
    
    memset( buff, 0, bsize );
    if( read( connfd, buff, bsize - 1 ) < 0 )  fail( "readfail" );
    puts( buff );

  }

  return 0;

}