The if-statement checks whether the reply from the server contains the terminating sequence. If it's true it searches for the next newline character which should terminate the status line (the line starting with "250"). But your server doesn't send a correct status message, thus "pos" will be NULL and you are trying to dereference an invalid address.
Originally Posted by bremenpl
I've used pos + 6 on purpose in the second call of strstr(). After the first call, "pos" will point to the first '\r' of the sequence "\r\n.\r\n250". Thus pos + 6 will point to '5' and you are able to look for the next '\n' which will terminate the status message ("250 <possible some text>\r\n").
if ((pos = strstr(pos, "\r\n.\r\n250")))
pos = strstr(pos + strlen(WORLD_2_SEND), "\n");
I admit this was a hack and in hindsight I shouldn't have used it. It would be better to split the reply from the server into lines (terminated by '\n'). Then you should simply wait for a line which contains only ".\r\n" which is the sign that the text message is over. Finally you would parse the following status line (parsing a status line is a good candidate for a function).
That's the line which is wrong in the server code. The end of the message should read "250\r\n" to send a valid status message.
message = "151 Definicja Pingwina yo\nDefinicja Pingwina yo\nDefinicja Pingwina yo\n\r\n.\r\n250";
I've also noticed some other things:
"new_sock" is a pointer to an int but you allocate only 1 byte for it. And int is usually at least 4 bytes nowadays.
int socket_desc , new_socket , c , *new_sock;
new_sock = malloc(1);
*new_sock = new_socket;
What do you want to achieve here?
"prefix" has only room for 3 characters, thus you are missing the terminating '\0'. But strcmp() expects a '\0'-terminated string.
memcpy(prefix, server_reply, sizeof(char) * 3);
if (0 == strcmp("150", prefix))