If you want more explanations, here's the server's code :
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <netdb.h>
#include <netinet/in.h>
#include <unistd.h>
#include <arpa/inet.h>
int main() {
struct sockaddr_in SockLocale;
int sock = socket(AF_INET, SOCK_STREAM, 0);
if(sock==-1) exit(-1);
memset(&SockLocale,0,sizeof(struct sockaddr_in));
SockLocale.sin_family = AF_INET;
SockLocale.sin_addr.s_addr = htonl(INADDR_ANY);
SockLocale.sin_port = htons(25);
if(bind(sock,(struct sockaddr*)&SockLocale,sizeof(struct sockaddr_in)) != -1) {
if(listen(sock, 100)<0) {
exit(-1);
}
}
else {
exit(-1);
}
while(1) {
struct sockaddr_in SockDistant;
char buffer[512];
socklen_t TailleSock = sizeof(SockDistant);
memset(&SockDistant,0,sizeof(struct sockaddr_in));
int s_distant = accept(sock,(struct sockaddr*)&SockDistant,&TailleSock);
if(s_distant!=-1) {
printf("CONNEXION OK\r\n");
strcpy(buffer,"Hello world !\r\n");
write(s_distant,buffer,strlen(buffer));
printf("String \"Hello world !\" sent\r\n");
close(s_distant);
}
}
}
On the port #2525, all is ok.
but on the port #25 (smtp), when i connect with telnet from windows, I get this on the screen of the linux :
Code:
CONNEXION OK
String "Hello world !" sent
CONNEXION OK
String "Hello world !" sent
Under debian.
do you understant anything ?