LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-20-2006, 10:58 AM   #1
fredbull
LQ Newbie
 
Registered: Jun 2006
Posts: 3

Rep: Reputation: 0
Smtp server in C : problem with windows clients


Hi,

I've made a smtp server that works fine on the port #2525. But on the port #25, there's a problem with windows clients : they always need to make 2 attempts to establish the connection (with only one call of connect)

I don't understand.
 
Old 06-20-2006, 12:20 PM   #2
fredbull
LQ Newbie
 
Registered: Jun 2006
Posts: 3

Original Poster
Rep: Reputation: 0
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 ?
 
Old 06-20-2006, 01:20 PM   #3
krizzz
Member
 
Registered: Oct 2004
Location: NY
Distribution: Slackware
Posts: 200

Rep: Reputation: 30
A bit too optimistic to call it smtp srv You close the socket within the loop - threfore try to accept on the closed socket. Move close() out of the while loop.... Sorry just realized that you closed the returned one ...

Last edited by krizzz; 06-20-2006 at 01:24 PM.
 
Old 06-21-2006, 03:11 AM   #4
fredbull
LQ Newbie
 
Registered: Jun 2006
Posts: 3

Original Poster
Rep: Reputation: 0
Of course, this is not THE server, but just an example that illustrates the problem

This example just send "Hello world !" and close the connection without waiting for data, this is why there's a close in the while loop.

All is OK on a port different of 25.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux Print Server with Windows Clients Echo Kilo Linux - Networking 3 02-01-2007 09:45 AM
RH Server...Windows Clients, is this possible? ZingSter Red Hat 3 04-06-2006 04:18 PM
samba¦server¦with¦windows¦2000¦clients dabash Linux - Networking 3 08-23-2005 01:08 AM
Networking Problem: Redhat 8.0 as a Server - Windows 98SE as clients Haxor Linux - Networking 10 03-19-2003 08:18 PM
Linux app-server to server StarOffice to Windows Clients: Need advice biosx Linux - Networking 3 08-14-2002 10:14 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration