#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/prctl.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>

void main()
{
        int mysocket,connectd;
        uint8_t buf[1024];
        int cnt,len;
        struct sockaddr_in serveraddr;
        struct sockaddr_in client;
        int opt;
        int i;
        mysocket = socket(AF_INET, SOCK_STREAM,0);

        memset(&serveraddr, 0, sizeof(serveraddr));
        serveraddr.sin_family = AF_INET;
        serveraddr.sin_port = htons(10000);
        serveraddr.sin_addr.s_addr = htonl(INADDR_ANY);

        opt = SO_REUSEADDR;
        setsockopt(mysocket, SOL_SOCKET,SO_REUSEADDR,&opt,sizeof(opt));

        if(-1 == bind(mysocket, (struct sockaddr*)&serveraddr, sizeof(serveraddr))) printf("bind error\n");
        if(-1 == listen(mysocket, 10)) printf("listen error\n");

        if (-1==(connectd=accept(mysocket,(struct sockaddr*)&client,&len)))
        {
                printf("create connect socket error\n");
        }
        else
                printf("connected!\n");

        while(1)
        {
                cnt = recv(connectd, buf, 10000, 0);
                printf("\nrecv %d:", cnt);
                for(i=0;i<cnt;i++)
                {
                        if(i%16 == 0) printf("\n");
                        printf("%#x ", buf[i]);
                }
        }
}

                      
