[ reiser @ 06.04.2008. 02:51 ] @
Napisao sam IRC klasu i sad hocu da dodam i podrsku za DCC secure chat. E sad, u opisu DCC protokola se kaze (obratiti paznju na bold deo):

Citat:
Implementation
==============

The CHAT and SEND connection types should not be
accepted automatically as this would create the potential for
terrorism. Instead, they should notify the user that an
offer has been made, and allow the user to accept it.

The recipient should have the opportunity to rename
a file send with the DCC SEND command prior to retrieving
it.

The following are the steps which should occur in
the clients:

Initiator:
DCC command issued.
Create a socket, bind it to INADDR_ANY, port 0, and
make it passive (a listening socket).
Send the recipient a DCC request via CTCP supplying
the address and port of the socket. (This
is ideally taken from the address of the local
side of the socket which is connected to a
server. This is presumably the interface on
the host which is closest to the rest of
the net, and results in one less routing hop
in the case of gateway nodes).
Continue normally until a connection is received.

On a connection:
Accept the connection.
Close the original passive socket.
Conduct transaction on the new socket.

Acceptor:
CTCP DCC request received.
Record information on the DCC request and notify the user.

At this point, the USER should be able to abort (close) the
request, or accept it. The request should be accepted with
a command specifying the sender, type, and argument, or
a subset of these where no ambiguity exists.

If accepted, create a TCP socket.
Connect the new socket to the address and port supplied.
Conduct the transaction over the socket.


Sve u svemu, kada moj irc engine primi request za dcc chat (tj kad mu neko posalje CTCP DCC CHAT chat <longip> <port> komandu, gde je <longip> adresa tog korisnika i <port> je port na koji irc engine treba da se konektuje), moj program ne moze da se konektuje:
Code:
//
// Connect fja
//
function TReiDCC.Connect : Integer;
var
  WSAData  : TWSAData;
  SockAddr : TSockAddrIn;
  positive : DWORD;
begin
  If FConnected Then
  Begin
    result := ERROR_CONNECTED;
    Exit;
  End;

  result := WSAStartup($101, WSAData);
  If result <> 0 Then
  Begin
    WSACleanup;
    Exit;
  End;

  FSock := Socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
  If FSock = INVALID_SOCKET Then
  Begin
    Shutdown(FSock, SD_BOTH);
    CloseSocket(FSock);
    WSACleanup;
    result := INVALID_SOCKET;
    Exit;
  End;

  SockAddr.sin_family := AF_INET;
  SockAddr.sin_port := htons(FPort);
  SockAddr.sin_addr.S_addr := inet_addr(PAnsiChar(HostNameToIP(FHost)));
  result := WinSock2.Connect(FSock, @SockAddr, SizeOf(SockAddr)); // << ovde vraca gresku
  If result <> 0 Then
  Begin
    Shutdown(FSock, SD_BOTH);
    CloseSocket(FSock);
    WSACleanup;
    Exit;
  End;

  positive := 1;
  ioctlsocket(FSock, FIONBIO, positive);

  FConnected := TRUE;

  If not Assigned(DataRecvThread) Then
    DataRecvThread := TReiThread.Create;
  DataRecvThread.OnExecute := RecvThread;
  DataRecvThread.Start;

  result := ERROR_SUCCESS;
end;

Dakle WinSock2.Connect() fja ne prolazi, tj WSAGetLastError() mi vrati error code 10061 - WSAECONNREFUSED. MSDN kaze:
Citat:
WSAECONNREFUSED
10061
Connection refused.

No connection could be made because the target computer actively refused it. This usually results from trying to connect to a service that is inactive on the foreign host—that is, one with no server application running.


E sad, po nekoj logici, kad se requestuje DCC chat, zar ne bi irc klijent (mirc/xchat/whatever) trebao da otvori taj port i da ceka da se neko konektuje na taj isti port ? Ili ja radim nesto pogresno oko kodiranja?

thx
[ reiser @ 06.04.2008. 15:05 ] @
Problem resen.