PDA

View Full Version : Unable to resolve the IP address. ( Qt 3.)



joseph
3rd July 2007, 14:00
Hi

What i did ..
In my application , we are trying to send mails.
The user should be able to attach file ...

Problem ...
i have a function called void Smtp::dnsLookupHelper() . Here it is not able to resolve the DNS SERVER NAME in string . say "ourserver.com"


socket->connectToHost( s.first().name ,25 ); // s.first().name = "ourserver.com"


see the code in this void Smtp::dnsLookupHelper()


void Smtp::dnsLookupHelper()
{
QValueList<QDns::MailServer> s = mxLookup->mailServers();
QValueList<QDns::MailServer>::Iterator it = s.begin();
while( it != s.end() )
{
qDebug("%DNS-Server:"+QString("%1").arg( (*it).name ));
++it;
}





if ( s.isEmpty() && mxLookup->isWorking() )
{
emit status( tr( "Could not find mail server. Please check address." ) );
QMessageBox::warning( qApp->activeWindow(),
tr( "SynsupMail" ),
tr( "Could not find mail server for address:\n\n %1" ).arg( rcpt ) );
QTimer::singleShot( 0, this, SLOT(deleteMe()) );
return;
}

emit status( tr( "Connecting to %1" ).arg( s.first().name ) );
socket->connectToHost( s.first().name ,25 ); // Not able to resolve the DNS name.
//socket->connectToHost( QString("192.168.45.55"), 25 ); //this will work, as i given the IP address directly
t = new QTextStream( socket );

}


if am giving the DNS SERVER NAME like this "192.168.45.55" this will work . Why ..????


please help

wysota
3rd July 2007, 14:15
Is the DNS able to return a proper IP for that hostname? Do you get the expected result in the while() loop?

joseph
3rd July 2007, 14:23
Is the DNS able to return a proper IP for that hostname?
How can I get an IP address from QDns::MailServer.name ??

I tried this below code

QValueList<QDns::MailServer> s = mxLookup->mailServers();
QValueList<QDns::MailServer>::Iterator it = s.begin();
while( it != s.end() )
{
qDebug("%DNS-Server:"+QString("%1").arg( (*it).name )); // display "ourserver.com"
++it;
}

I think

socket->connectToHost( s.first().name ,25 ); should resolve the QDns::MailServer.name to IP address.

pdolbey
3rd July 2007, 15:30
What sort of DNS entry is "ourserver.com"? Can you "ping" it from a command line, and does this return the correct IP? If not (and your DNS servers are correctly set up) its probably an MX (Mail Exchange) record, used to provide mail domain services, such as "@ourserver.com". You can prove this using "nslookup" tool, changing the type=MX. If its published on the internet, you can use the "DNSStuff" website for this as well. If its on an intranet, the simplest way would be to request a new DNS A (alias) record from the admins, like "smtp.ourserver.com", and use that - this would pretty much work with most platform variants of "gethostbyname()" - you can always test this by poking the hosts file.

Just my 5c.

Pete

wysota
3rd July 2007, 20:47
How can I get an IP address from QDns::MailServer.name ??
Something equivalent to:

dig -t mx ourserver.com

and then:
host server.returned.for.ourserver.com


I think

socket->connectToHost( s.first().name ,25 ); should resolve the QDns::MailServer.name to IP address.
Only if it is resolvable by your machine. That's why I asked to check it out.

joseph
4th July 2007, 04:59
What sort of DNS entry is "ourserver.com"? Can you "ping" it from a command line, and does this return the correct IP?
Pete
Ok Pete, sounds very difficult to understand for me, newbiew:) so please bear with me if I ask stupid question


Can you "ping" it from a command line, and does this return the correct IP?
When I ping on the terminal , I get this reply

>ping gmail.com
From 192.168.1.7: icmp_seq=1 Destination Host Unreachable
From 192.168.1.7 icmp_seq=1 Destination Host Unreachable
for gmail.com.


You can prove this using "nslookup" tool, changing the type=MX. If its published on the internet, you can use the "DNSStuff" website for this as well. If its on an intranet, the simplest way would be to request a new DNS A (alias) record from the admins, like "smtp.ourserver.com", and use that - this would pretty much work with most platform variants of "gethostbyname()" - you can always test this by poking the hosts file.
I need some more explanation for this as I'm not getting anything

wysota-->

dig -t mx gmail.com
I get this

; <<>> DiG 9.3.2 <<>> -t mx gmail.com
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 27225
;; flags: qr rd ra; QUERY: 1, ANSWER: 5, AUTHORITY: 4, ADDITIONAL: 6

;; QUESTION SECTION:
;gmail.com. IN MX

;; ANSWER SECTION:
gmail.com. 1619 IN MX 5 gmail-smtp-in.l.google.com.
gmail.com. 1619 IN MX 10 alt1.gmail-smtp-in.l.google.com.
gmail.com. 1619 IN MX 10 alt2.gmail-smtp-in.l.google.com.
gmail.com. 1619 IN MX 50 gsmtp163.google.com.
gmail.com. 1619 IN MX 50 gsmtp183.google.com.

;; AUTHORITY SECTION:
gmail.com. 267625 IN NS ns1.google.com.
gmail.com. 267625 IN NS ns2.google.com.
gmail.com. 267625 IN NS ns3.google.com.
gmail.com. 267625 IN NS ns4.google.com.

;; ADDITIONAL SECTION:
gsmtp163.google.com. 5221 IN A 64.233.163.27
gsmtp183.google.com. 5221 IN A 64.233.183.27
ns1.google.com. 23924 IN A 216.239.32.10
ns2.google.com. 23924 IN A 216.239.34.10
ns3.google.com. 23924 IN A 216.239.36.10
ns4.google.com. 23924 IN A 216.239.38.10

;; Query time: 1 msec
;; SERVER: 192.168.1.7#53(192.168.1.7)
;; WHEN: Wed Jul 4 09:24:40 2007
;; MSG SIZE rcvd: 326

host server.returned.for.ourserver.com
I get this

Host server.returned.for.gmail.com not found: 3(NXDOMAIN)
I even tried using the smpt example given in qtassistant( qt3 ) and I get error as "Connection refused". Please help.

Thanks

joseph
4th July 2007, 05:37
Ok let me explain what I did again.

Copied the code from "A simple mail client" available in qtassistant (qt3). Compiled the code and ran it.
See the attached file below.
See the information in the status bar. I keep getting that. Also when I debugged to find out what is wrong with the code, I got to know the DNS name is not resolved to host address and I get the error "ErrConnectionRefused".

wysota
4th July 2007, 08:29
I meant to use "host" on one of the results returned by dig, like:

host gmail-smtp-in.l.google.com

And then you can even do:

/usr/sbin/traceroute gmail-smtp-in.l.google.com

and see if you're able to reach the host.

joseph
4th July 2007, 08:39
Ok,
I have tried this

abc@abc:~>host gmail-smtp-in.l.google.com
gmail-smtp-in.l.google.com has address 209.85.147.114
gmail-smtp-in.l.google.com has address 209.85.147.27
abc@abc:~> /usr/sbin/traceroute gmail-smtp-in.l.google.com
traceroute to gmail-smtp-in.l.google.com (209.85.147.114), 30 hops max, 40 byte packets
1 192.168.1.7 (192.168.1.7) 0.214 ms 0.198 ms 0.201 ms
2 203.123.189.33 (203.123.189.33) 1.295 ms 1.638 ms 1.190 ms
Unable to look up 203.123.180.233: Temporary failure in name resolution
3 203.123.180.233 5.012 ms 4.630 ms 5.520 ms
Unable to look up 203.123.177.6: Temporary failure in name resolution
4 203.123.177.6 6.178 ms 5.770 ms 5.082 ms
5 125.16.128.5 (125.16.128.5) 38.943 ms 39.104 ms 35.492 ms
6 59.145.148.75 (59.145.148.75) 130.965 ms 127.178 ms 124.232 ms
7 125.21.167.37 (125.21.167.37) 36.922 ms 38.739 ms 36.964 ms
8 59.145.6.235 (59.145.6.235) 38.769 ms 36.402 ms 37.035 ms
9 125.21.167.70 (125.21.167.70) 39.104 ms 38.159 ms 36.395 ms
10 203.208.190.177 (203.208.190.177) 78.637 ms 74.831 ms 74.324 ms
11 so-2-1-0-0.hkgcw-cr2.ix.singtel.com (203.208.154.38) 264.638 ms * 266.405 ms
12 72.14.196.5 (72.14.196.5) 280.818 ms 287.523 ms 283.697 ms
13 216.239.43.68 (216.239.43.68) 292.592 ms 301.439 ms 304.207 ms
14 209.85.250.88 (209.85.250.88) 312.193 ms 308.870 ms 305.533 ms
15 66.249.95.170 (66.249.95.170) 319.043 ms 64.233.174.43 (64.233.174.43) 320.645 ms *
16 216.239.47.235 (216.239.47.235) 321.036 ms * 216.239.47.233 (216.239.47.233) 341.805 ms
17 216.239.47.237 (216.239.47.237) 453.568 ms 451.889 ms *
18 72.14.233.37 (72.14.233.37) 464.056 ms 460.247 ms 456.496 ms
19 209.85.250.57 (209.85.250.57) 451.512 ms 447.714 ms 447.418 ms
20 72.14.236.146 (72.14.236.146) 457.799 ms 209.85.248.202 (209.85.248.202) 453.523 ms 467.388 ms
21 wa-in-f114.google.com (209.85.147.114) 447.710 ms * *

What should I do next????
Thanks

wysota
4th July 2007, 09:14
Looks like the DNS works correctly then. Could you provide a minimal compilable example reproducing the problem?

joseph
4th July 2007, 09:35
Looks like the DNS works correctly then. Could you provide a minimal compilable example reproducing the problem?

As I told I have copied the same code available in qtassistant in qt3. Anyway here is the link
http://web.mit.edu/qt_v3.3.3/www/mail-example.html (mail)

Here is the code

Smtp::Smtp( const QString &from, const QString &to,
const QString &subject,
const QString &body )
{
socket = new QSocket( this );
connect ( socket, SIGNAL( readyRead() ),
this, SLOT( readyRead() ) );
connect ( socket, SIGNAL( connected() ),
this, SLOT( connected() ) );
connect ( socket, SIGNAL( error ( int ) ),
this, SLOT( slotShowError(int) ) );
mxLookup = new QDns( to.mid( to.find( '@' )+1 ), QDns::Mx );
connect( mxLookup, SIGNAL(resultsReady()),
this, SLOT(dnsLookupHelper()) );
message = QString::fromLatin1( "From: " ) + from +
QString::fromLatin1( "\nTo: " ) + to +
QString::fromLatin1( "\nSubject: " ) + subject +
QString::fromLatin1( "\n\n" ) + body + "\n";
message.replace( message, QString::fromLatin1( "\n" ),
QString::fromLatin1( "\r\n" ) );
message.replace( message, QString::fromLatin1( "\r\n.\r\n" ),
QString::fromLatin1( "\r\n..\r\n" ) );
sender = from;
rcpt = to;
state = Init;
}

void Smtp::dnsLookupHelper()
{
QValueList<QDns::MailServer> s = mxLookup->mailServers();
if ( s.isEmpty() && mxLookup->isWorking() )
{
emit status( tr( "Could not find mail server. Please check address." ) );
QMessageBox::warning( qApp->activeWindow(),
tr( "SynsupMail" ),
tr( "Could not find mail server for address:\n\n %1" ).arg( rcpt ) );
QTimer::singleShot( 0, this, SLOT(deleteMe()) );
return;
}
emit status( tr( "Connecting to %1" ).arg( s.first().name ) );
socket->connectToHost( s.first().name, 25 ); //The error occurs here
t = new QTextStream( socket );
}


//The control never comes here
void Smtp::connected()
{
emit status( tr( "Connected to %1" ).arg( socket->peerName() ) );
}
//Displays error status as 0 which is QSocket::ErrConnectionRefused
void Smtp::slotShowError(int errorNo)
{
qDebug("%Error:"+QString("%1").arg((QSocket::Error)errorNo));
}

Again the code is same as what is given in qtassistant( qt3 ).

wysota
4th July 2007, 10:11
This is hardly what I can call compilable... So what did you change in the example? Does the pure example code function correctly?

joseph
4th July 2007, 10:15
This is hardly what I can call compilable... So what did you change in the example?
The code is exactly the same as the example/network/mail. I just copied the entire code without any changes to it.


Does the pure example code function
No... It doesnt work.:confused:

wysota
4th July 2007, 11:20
Can you connect to gmail-smtp-in.l.google.com using telnet?

telnet gmail-smtp-in.l.google.com 25

The server should respond with a smtp greeting, something like:
220 mx.google.com ESMTP

joseph
4th July 2007, 11:33
Can you connect to gmail-smtp-in.l.google.com using telnet?

telnet gmail-smtp-in.l.google.com 25

The server should respond with a smtp greeting, something like:
220 mx.google.com ESMTP

I get this

abc@abc:~> telnet gmail-smtp-in.l.google.com 25
Trying 209.85.147.27...
telnet: connect to address 209.85.147.27: No route to host
Trying 209.85.147.114...
telnet: connect to address 209.85.147.114: No route to host

wysota
4th July 2007, 23:07
In that case the problem is not in your application or Qt, but in your machine. It has its routing set up incorrectly. I suggest you contact your network administrator about it.

joseph
5th July 2007, 04:12
In that case the problem is not in your application or Qt, but in your machine. It has its routing set up incorrectly. I suggest you contact your network administrator about it.

Hi wysota,
I told about my problem to network admin. According to him, I cannot directly access the mailservers( like yahoo, gmail etc ) as this would be against security.
Actually, we dont have any access to mail domains. We can only use lotus notes to send and receive the mails. All other IDs (mails) are blocked. The network admin tells me I can only use 198.168.1.1 IP to send the mail from my workplace using lotus. I tried sending mails to my peers within our intranet using 198.168.1.1 and it succeeded. The mail was sent.

What is that I can do, without taking my network admin's help, to solve the above problem? or anything I can ask him to make my application work.

One more important thing is I have my peers working on .NET and they have implemented sending/receving mails. I had a discussion and as I understood, they too are using 198.168.1.1 as bypass address to send and receive the mails.

Thanks

wysota
5th July 2007, 09:37
Then why don't you use that address as well?

joseph
5th July 2007, 12:02
Then why don't you use that address as well?

OH, Got it...Thanks wysota... It was my network admins problem, fixed it and got it right.

Thanks wysota again....