{"action":"opened","issue":{"url":"https://api.github.com/repos/lkl/linux/issues/133","repository_url":"https://api.github.com/repos/lkl/linux","labels_url":"https://api.github.com/repos/lkl/linux/issues/133/labels{/name}","comments_url":"https://api.github.com/repos/lkl/linux/issues/133/comments","events_url":"https://api.github.com/repos/lkl/linux/issues/133/events","html_url":"https://github.com/lkl/linux/issues/133","id":141555788,"number":133,"title":"Client-Server program is not working when both sides are using LKL.","user":{"login":"subhrajitbiswal","id":17901010,"avatar_url":"https://avatars.githubusercontent.com/u/17901010?v=3","gravatar_id":"","url":"https://api.github.com/users/subhrajitbiswal","html_url":"https://github.com/subhrajitbiswal","followers_url":"https://api.github.com/users/subhrajitbiswal/followers","following_url":"https://api.github.com/users/subhrajitbiswal/following{/other_user}","gists_url":"https://api.github.com/users/subhrajitbiswal/gists{/gist_id}","starred_url":"https://api.github.com/users/subhrajitbiswal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/subhrajitbiswal/subscriptions","organizations_url":"https://api.github.com/users/subhrajitbiswal/orgs","repos_url":"https://api.github.com/users/subhrajitbiswal/repos","events_url":"https://api.github.com/users/subhrajitbiswal/events{/privacy}","received_events_url":"https://api.github.com/users/subhrajitbiswal/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-03-17T11:29:27Z","updated_at":"2016-03-17T11:29:27Z","closed_at":null,"body":"Client-Server program is not working when both sides are using LKL. But its working when only one side is LKL. Please find the logs for working case (only client side is using LKL here) below.\r\n\r\nSteps to reproduce the issue:\r\n=======================\r\nI have 2 simple program. one is server (it will read the input file and send it to port 9600) and one is client (it will connect to the server by giving the IP as input , read it and print the statistics). in my setup server is running in 172.27.10.29 and client is in 172.27.10.24.\r\n\r\nI created the TAP interface (lkl_ptt0) and created a bridge br-lkl. Added TAP interface and my physical interface(eth12) to this bridge.\r\n\r\nServer log:\r\n=========\r\nhadmin@VFSR2:~$ ./tcpfs ccnd.c\r\nEnd of file\r\nTotal bytes sent = {192135}\r\n\r\nclient log:\r\n======= \r\nroot@ICSCHELAP0027:/home/hadmin/linux/tools/lkl/bin# LKL_HIJACK_NET_TAP=lkl_ptt0 LKL_HIJACK_NET_IP=172.27.10.2 LKL_HIJACK_NET_NETMASK_LEN=24 ./lkl-hijack.sh ./tcpfc 172.27.10.29\r\nStart time = {16:00:02:765}\r\nTotal Bytes received 192135\r\nEnd time = {16:00:02:792}\r\nroot@ICSCHELAP0027:/home/hadmin/linux/tools/lkl/bin#\r\n\r\n\r\nserver code:\r\n========= \r\n#include <sys/socket.h>\r\n#include <netinet/in.h>\r\n#include <arpa/inet.h>\r\n#include <stdio.h>\r\n#include <stdlib.h>\r\n#include <unistd.h>\r\n#include <errno.h>\r\n#include <string.h>\r\n#include <sys/types.h>\r\n\r\nint main(int argc, char** argv)\r\n{\r\n    int listenfd = 0;\r\n    int connfd = 0;\r\n    struct sockaddr_in serv_addr;\r\n    char sendBuff[1025];\r\n    int numrv;\r\n    int totalbyteswritten = 0;\r\n    int byteswritten = 0;\r\n\r\n    listenfd = socket(AF_INET, SOCK_STREAM, 0);\r\n\r\n    memset(&serv_addr, '0', sizeof(serv_addr));\r\n    memset(sendBuff, '0', sizeof(sendBuff));\r\n\r\n    serv_addr.sin_family = AF_INET;\r\n    serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);\r\n    serv_addr.sin_port = htons(9600);\r\n\r\n    bind(listenfd, (struct sockaddr*)&serv_addr,sizeof(serv_addr));\r\n\r\n    if(listen(listenfd, 10) == -1)\r\n    {\r\n        printf(\"Failed to listen\\n\");\r\n        return -1;\r\n    }\r\n    while(1)\r\n    {\r\n        connfd = accept(listenfd, (struct sockaddr*)NULL ,NULL);\r\n\r\n        FILE *fp = fopen(argv[1],\"rb\");\r\n        if(fp==NULL)\r\n        {\r\n            printf(\"File opern error\");\r\n            return 1;\r\n        }\r\n\r\n        while(1)\r\n        {\r\n            unsigned char buff[256]={0};\r\n            int nread = fread(buff,1,256,fp);\r\n\r\n            if(nread > 0)\r\n            {\r\n                byteswritten = write(connfd, buff, nread);\r\n                totalbyteswritten += byteswritten;\r\n        //      printf(\"totalbyteswritten so far = {%d}\\n\", totalbyteswritten);\r\n            }\r\n\r\n            if (nread < 256)\r\n            {\r\n                if (feof(fp))\r\n                    printf(\"End of file\\n\");\r\n                if (ferror(fp))\r\n                    printf(\"Error reading\\n\");\r\n                break;\r\n            }\r\n        }\r\n        printf(\"Total bytes sent = {%d}\\n\", totalbyteswritten);\r\n        totalbyteswritten = 0;\r\n        close(connfd);\r\n        sleep(1);\r\n    }\r\n    return 0;\r\n}\r\n\r\n\r\nclient code:\r\n======== \r\n\r\n#include <sys/socket.h>\r\n#include <sys/types.h>\r\n#include <netinet/in.h>\r\n#include <netdb.h>\r\n#include <stdio.h>\r\n#include <string.h>\r\n#include <stdlib.h>\r\n#include <unistd.h>\r\n#include <errno.h>\r\n#include <arpa/inet.h>\r\n#include <time.h>\r\n\r\nvoid getlogtime(char *currentTime);\r\n\r\nint main(int argc, char** argv)\r\n{\r\n    int sockfd = 0;\r\n    int bytesReceived = 0;\r\n    char recvBuff[256];\r\n    memset(recvBuff, '0', sizeof(recvBuff));\r\n    struct sockaddr_in serv_addr;\r\n\r\n    if((sockfd = socket(AF_INET, SOCK_STREAM, 0))< 0)\r\n    {\r\n        printf(\"\\n Error : Could not create socket \\n\");\r\n        return 1;\r\n    }\r\n\r\n    serv_addr.sin_family = AF_INET;\r\n    //serv_addr.sin_port = htons(atoi(argv[2])); // port\r\n    serv_addr.sin_port = htons(9600);\r\n    serv_addr.sin_addr.s_addr = inet_addr(argv[1]);\r\n\r\n    if(inet_pton(AF_INET, argv[1], &serv_addr.sin_addr)<=0)\r\n    {\r\n        printf(\"\\n inet_pton error occured\\n\");\r\n        return 1;\r\n    }\r\n    if(connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr))<0)\r\n    {\r\n        perror(\"Error : Connect Failed \\n\");\r\n        return 1;\r\n    }\r\n\r\n    FILE *fp;\r\n    char fname[256];\r\n    char logtime[100];\r\n    int totalBytesRcvd = 0;\r\n\r\n        getlogtime(logtime);\r\n        sprintf(fname, \"rcvdfle.%s\", logtime);\r\n    fp = fopen(fname, \"ab\");\r\n    if(NULL == fp)\r\n    {\r\n        printf(\"Error opening file\");\r\n        return 1;\r\n    }\r\n\r\n        getlogtime(logtime);\r\n        printf(\"Start time = {%s}\\n\", logtime);\r\n    while((bytesReceived = read(sockfd, recvBuff, 256)) > 0)\r\n    {\r\n        totalBytesRcvd += bytesReceived;\r\n        // recvBuff[n] = 0;\r\n        fwrite(recvBuff, 1,bytesReceived,fp);\r\n        // printf(\"%s \\n\", recvBuff);\r\n    }\r\n      printf(\"Total Bytes received %d\\n\",totalBytesRcvd);\r\n\r\n        getlogtime(logtime);\r\n        printf(\"End time = {%s}\\n\", logtime);\r\n\r\n    if(bytesReceived < 0)\r\n    {\r\n        printf(\"\\n Read Error \\n\");\r\n    }\r\n    close(sockfd);\r\n\r\n    return 0;\r\n}\r\n\r\nvoid getlogtime(char *currentTime)\r\n{\r\n        struct timeval curTime;\r\n        int milli;\r\n        time_t rawtime;\r\n        struct tm * timeinfo;\r\n        char buffer [80];\r\n\r\n        gettimeofday(&curTime, NULL);\r\n        milli = curTime.tv_usec / 1000;\r\n        time(&rawtime);\r\n        timeinfo = localtime(&rawtime);\r\n        strftime(buffer, 80, \"%H:%M:%S\", timeinfo);\r\n        if(currentTime)\r\n                sprintf(currentTime, \"%s:%d\", buffer, milli);\r\n        //printf(\"current time: %s \\n\", currentTime);\r\n}\r\n\r\n\r\n\r\n"}}