0
バイナリデータで読み込むためのInPipeと、ファイアウォールを通過するバイナリデータを書き戻すためのOutPipeがあります。名前付きパイプは読み取りのみで書き込みはしません
/// The input named pipe, "ToFirewall"
static FILE* InPipe = NULL;
/// The output named pipe, "FromFirewall"
static FILE* OutPipe = NULL;
私は別の機能で両方のパイプを開きます。私はデータを読み込むように、それは書き込みをスキップし、それは私のファイアウォールを通過したかどうかをチェックする気にしないいくつかの理由
static bool OpenPipes(void)
{
//ToFirewall
InPipe = fopen("ToFirewall", "rb");
if(InPipe == NULL)
{
perror("ERROR, failed to open pipe ToFirewall:");
return false;
}
OutPipe = fopen("FromFirewall", "wb");
if(OutPipe == NULL)
{
perror("ERROR, failed to open pipe FromFirewall:");
return false;
}
return true;
}
。私はオンラインで見て、フラッシングについての解決策を読んだが、役に立たなかった。ここで
static void* FilterThread(void* args) {
OpenPipes();
unsigned char* buffer = malloc(1500);
int ret = fread(buffer, 1, 1500, InPipe);
if(ret){
fclose(InPipe);
}
//Check is FilterPacket will allow the packet through the firewall
if(FilterPacket(buffer, args)) {
fwrite(buffer, 1, 60, OutPipe);
fflush(OutPipe);
}
// fflush(OutPipe);
fclose(OutPipe);
return NULL;
}
は私の出力
RCVR: opened file output.bin
SNDR: Waiting 200ms between packets
SNDR: Number of packets: 18
SNDR: Starting packet 0
SNDR: Starting packet 1
SNDR: Starting packet 2
SNDR: Starting packet 3
SNDR: Starting packet 4
SNDR: Starting packet 5
SNDR: Starting packet 6
SNDR: Starting packet 7
SNDR: Starting packet 8
SNDR: Starting packet 9
SNDR: Starting packet 10
SNDR: Starting packet 11
SNDR: Starting packet 12
SNDR: Starting packet 13
SNDR: Starting packet 14
SNDR: Starting packet 15
SNDR: Starting packet 16
SNDR: Starting packet 17
SNDR: Finished, wrote 18 packets to the pipe
であり、ここで、あなたは、予想される出力は、実際に読み出したデータの1500のバイトまでを読み込み、
> RCVR: opened file output.bin
SNDR: Waiting 200ms between packets
SNDR: Number of packets: 18
SNDR: Starting packet 0
SNDR: Starting packet 1
RCVR: 129.21.37.11 -> 74.125.21.103
SNDR: Starting packet 2
RCVR: 74.125.21.103 -> 129.21.37.11
SNDR: Starting packet 3
SNDR: Starting packet 4
RCVR: 129.21.37.11 -> 74.125.21.103
SNDR: Starting packet 5
SNDR: Starting packet 6
RCVR: 74.125.21.103 -> 129.21.37.11
SNDR: Starting packet 7
RCVR: 129.21.37.28 -> 74.125.21.103
SNDR: Starting packet 8
SNDR: Starting packet 9
RCVR: 129.21.37.11 -> 74.125.21.103
SNDR: Starting packet 10
RCVR: 74.125.21.103 -> 129.21.37.28
SNDR: Starting packet 11
SNDR: Starting packet 12
RCVR: 74.125.21.103 -> 129.21.37.11
SNDR: Starting packet 13
RCVR: 129.21.37.28 -> 74.125.21.103
SNDR: Starting packet 14
SNDR: Starting packet 15
SNDR: Starting packet 16
RCVR: 129.21.37.11 -> 74.125.21.103
SNDR: Starting packet 17
RCVR: 74.125.21.103 -> 129.21.37.28
SNDR: Finished, wrote 18 packets to the pipe
FwSim, Commanding firewall to Exit
RCVR: 74.125.21.103 -> 129.21.37.11
Exiting
あなたは[、最小完全、かつ検証例]を作成してみてくださいすることができ(HTT p://stackoverflow.com/help/mcve)と私たちを見せてくれる?プログラムのどこで出力を印刷しますか? 'fread'(と' fwrite')が実際に返すものをチェックしましたか? –
ああ、あなたはパイプが*ストリーミング*であることを知っています。つまり、1回の読み込み呼び出しで要求されたすべてのデータを得ることができない場合は、ループで読み込む必要があります。 –
パイプの反対側には何がありますか? – immibis