Emanuele: > I know that NULL is there to indicate end of a string. But why if I do: > > send(SMTPSocket,session->reply,strlen(session->reply)); // session->reply > is where I wrote the response code that ends with \r\n\0 > > it also sends '\0'? > > strlen() shouldn't count \0, but Postfix receives '\0'.
I suggest that you debug your application by looking at tcpdump output. You have already learned how to capture an SMTP session "on the wire". You appear to be struggling with a string conversion problem, namely, between the internal representation used in your C program, and the external representation used in the SMTP protocol. I think you're trying to avoid that conversion, and that would be a mistake. In SMTP, text lines end in <CR><LF>, and NULL characters are allowed only in those places where the protocol syntax says so (NULL was never allowed between <CR><LF> and the next server response). In C, the default string representation is a character buffer with an implicit length (indicated with the null-terminator). Postfix uses a different internal representation: a character buffer with an explicit length that is updated as data is added to the buffer. This representation was chosen for convenience and safety. Regardless of the internal string represenation, to convert from C to SMTP one appends <CR><LF> on output; and to convert from SMTP to C, one strips off the <CR><LF> on input. Wietse