Read fails after tcpreplay with error: 0: Resource temporarily unavailabl

前端 未结 3 1386
刺人心
刺人心 2021-01-13 18:47

I have a very simple script to run. It calls tcpreplay and then ask the user to type in something. Then the read will fail with read: read error: 0: Resource temporarily una

3条回答
  •  花落未央
    2021-01-13 19:22

    Apparently tcpreplay sets O_NONBLOCK on stdin and then doesn't remove it. I'd say it's a bug in tcpreplay. To work it around you can run tcpreplay with stdin redirected from /dev/null. Like this:

    tcpreplay -i eth4 SMTP.pcap 

    Addition: note that this tcpreplay behavior breaks non-interactive shells only.

    Another addition: alternatively, if you really need tcpreplay to receive your input you can write a short program which resets O_NONBLOCK. Like this one (reset-nonblock.c):

    #include 
    #include 
    #include 
    
    int
    main()
    {
        if (fcntl(STDIN_FILENO, F_SETFL,
                  fcntl(STDIN_FILENO, F_GETFL) & ~O_NONBLOCK) < 0) {
            perror(NULL);
            return 1;
        }
        return 0;
    }
    

    Make it with "make reset-nonblock", then put it in your PATH and use like this:

    tcpreplay -i eth4 SMTP.pcap
    reset-nonblock
    

提交回复
热议问题