uses
  Crt,
  CoBase,
  CoEth01;


const
  DestAddr : TEthAddress = (
    Size: SizeOf(TEthAddress);
    Mac: (Bytes:(0, 80, 252, 33, 19, 154));
    Protocol: $800
  );

var
  Eth1     : PCoEth01;
  Eth2     : PCoEth01;
  Status   : TCoStatus;


  Buff1     : array[0..100] of Byte;

  Buff2     : array[0..1535] of Byte;

  FromAddr  : TEthAddress;
  RecvLen   : Word;

  Ovlp1     : TOverlapped;
  Ovlp2     : TOverlapped;

  Count     : Integer;

begin
  ClrScr;

  Eth1 := New( PCoEth01, Init );
  Eth2 := New( PCoEth01, Init );

  Eth1^.CO_Properties := CPR_UPPER_APP or CPR_LOWER_NONE;
  Eth2^.CO_Properties := CPR_UPPER_APP or CPR_LOWER_NONE;

  Eth2^.Eth_IoBase := $310;


  Status := Eth1^.CoBind( nil, 0, nil  );
  if Status <> CST_SUCCESS then
  begin
    WriteLn( 'Eth1_Bind, Error:', Status );
  end;


  Status := Eth2^.CoBind( nil, 0, nil  );
  if Status <> CST_SUCCESS then
  begin
    WriteLn( 'Eth2_Bind, Error:', Status );
  end;

  Count := 100;
  repeat

    Status := Eth2^.CoRecvBufferFrom( @Buff2, SizeOf(Buff2), @RecvLen,
                0, @FromAddr, @Ovlp1 );

    Status := Eth2^.CoRecvBufferFrom( @Buff2, SizeOf(Buff2), @RecvLen,
                0, @FromAddr, @Ovlp2 );


{    if Status <> CST_PENDING then
    begin
      WriteLn('...');
      Exit;
    end;}

    Status := Eth1^.CoSendBufferTo( @Buff1, SizeOf(Buff1), 0, @DestAddr, nil );

    Eth2^.CoCancelIO( @Ovlp1, 0 );

    if Status <> CST_SUCCESS then
    begin
      WriteLn( 'Send, Error:', Status );
    end;


    Status := Eth2^.CoGetIoResult( @Ovlp1, COF_WAIT );
    if Status <> CST_SUCCESS then
    begin
      WriteLn( 'Recv, Error:', Status );
    end
    else begin
      WriteLn( 'Recvlen = ', RecvLen );
      WriteLn( 'FromAddr.Protocol = ', FromAddr.Protocol );
    end;

    Status := Eth2^.CoGetIoResult( @Ovlp2, COF_WAIT );
    if Status <> CST_SUCCESS then
    begin
      WriteLn( 'Recv, Error:', Status );
    end
    else begin
      WriteLn( 'Recvlen = ', RecvLen );
      WriteLn( 'FromAddr.Protocol = ', FromAddr.Protocol );
    end;

    Dec( Count );

  until Count = 0;

  Status := Eth1^.CoUnbind( 0, nil );
  if Status <> CST_SUCCESS then
  begin
    WriteLn( 'Eth1_Unbind, Error:', Status );
  end;

{  Status := Eth2^.CoUnbind( 0, nil );
  if Status <> CST_SUCCESS then
  begin
    WriteLn( 'Eth2_Unbind, Error:', Status );
  end;}

  Eth1^.Release;
  Eth2^.Release;
end.