[En-Nut-Discussion] TCP connection to fixe IP
Gilles
gilles at palmcom.fr
Tue Oct 13 02:31:35 CEST 2009
Zack,
I agree on the local addresses compatibilities.
But for distant PC, I don't understand why it does not work.
The code is :
TCPSOCKET *sock1;
FILE *stream1;
if ((sock1 = NutTcpCreateSocket()) != 0)
{
if (NutTcpConnect(sock1,dest_addr, PortSend) == 0)
{
if ((stream1 = _fdopen((int) sock1, "r+b")) != 0)
{
fwrite(buff,1,i,stream1);
fclose(stream1);
}
else
{
puts("Assigning a
stream failed");
}
}
else
{
int errorTCP;
errorTCP = NutTcpError(sock1);
printf("failed: 0x%x",errorTCP);
}
NutTcpCloseSocket(sock1);
}
Init Values are :
PortSend = 5001;
Dest_addr = 82.xx.yy.zz
bridge are OK is both directions on port 5001&5002
This code work in local network.
I assume that it will work also to distant IP
So the faulty code is maybe in the initialisation of my IP stuff.
Void InitEthernetDevice(void);
{
if (NutRegisterDevice(&DEV_ETHER, 0 , 0))
{
puts("No Ethernet Device");
return -1;
}
printf("\nConfigure %s...", DEV_ETHER_NAME);
NutNetLoadConfig("eth0");
NutNetIfConfig(DEV_ETHER_NAME, confnet.cdn_mac, confnet.cdn_cip_addr,
confnet.cdn_ip_mask);
if(confnet.cdn_gateway)
{
printf("\nAdd Gateway...");
NutIpRouteAdd(0,0, confnet.cdn_gateway, &DEV_ETHER);
}
puts("\nOK");
return 0;
}
The complete initialisation code is :
InitEthernetDevice();
printf("Start Responder...");
if (NutRegisterDiscovery((u_long)-1, 0, DISF_INITAL_ANN)) {
puts("failed");
}
else {
puts("OK");
}
Any idea where to looking for?
Gilles
-----Original Message-----
From: ennut at thezachariasgroup.com [mailto:ennut at thezachariasgroup.com]
Sent: lundi 12 octobre 2009 23:48
To: gilles at palmcom.fr; Ethernut User Chat (English)
Subject: Re: [En-Nut-Discussion] TCP connection to fixe IP
Gilles,
I see multiple problems.
1.) You will only have connectivity between
192.168.xxx.yyy addresses on a local network
because these are local IP addresses.
They will not go out of the local network onto
the internet with these 192.168 based addresses.
Your router will convert these 192.168 based IP addresses
to an IP Address and port number that is actually
accessible from the internet. The router won't
even try to convert a destination address
starting with 192.168 to an internet address.
2.) Assuming the subnet mask is 255.255.255.0, your "not good" example shows
a
device IP of 192.168.1.1 with a gateway of
192.168.0.254. These are not compatible.
To communicate with a distant PC, one of the
devices need to have a fixed IP Address that is not a local address.
The other unit then must connect to the PC with the fixed IP Address.
Zack
At 05:12 PM 10/12/2009, you wrote:
>Bonjour Ole,
>
>1) As I said in my previous Email, the code works correctly in a local
>network BUT with respect of the IP range.
>Example:
>
>GOOD: device IP = 192.168.0.1 and gateway IP = 192.168.0.254
>
>NOT GOOD : device IP = 192.168.1.1 and gateway IP = 192.168.0.254
>
>In that case, the gateway IP is force to 0.0.0.0 by NutOS
>
>How can I bypass the 0.0.0.0 change ?
>
>2) I have redo some test between my ARM9 and a distant PC to be able to
give
>you more details about this type of connection. Actually, the error
received
>is : Time out
>Firewall have check and seems correct.
>No TCPIP message can be send out to an external IP
>
>Best regards
>Gilles
>
>-----Original Message-----
>From: Ole Reinhardt [mailto:ole.reinhardt at embedded-it.de]
>Sent: lundi 5 octobre 2009 09:55
>To: gilles at palmcom.fr; Ethernut User Chat (English)
>Subject: Re: [En-Nut-Discussion] TCP connection to fixe IP
>
>Hi Gilles,
>
> > I have developed a piece of code to establish a dialog between my ARM9
>board
> > and a PC in 2 different location.(2 different IP fix addresses)
> > When the PC establish the TCP link , the ARM9 receive and respond to
the
> > TCP frame correctly.
> > If I try to establish the TCP dialog starting from the ARM9, it fails on
>the
> > NutTcpConnect(sock1,dest_addr, PortSend)
> > All is good if I stay inside my office network.
>
>Are you sure there is neither a masquerading (NAT) nor any other kind of
>firewall between the pc and your board? Have you correctly set your
>gateways on both entities?
>
>Have you checked the error code after the failed connect with
>NutTcpError()? It might give you a hint what is going wrong.
>
>Regards,
>
>Ole Reinhardt
>
>--
> _____________________________________________________________
>| |
>| Embedded-IT |
>| |
>| Ole Reinhardt Tel. / Fax: +49 (0)271 7420433 |
>| Luisenstraße 29 Mobil: +49 (0)177 7420433 |
>| 57076 Siegen eMail: ole.reinhardt at embedded-it.de |
>| Germany Web: http://www.embedded-it.de |
>|_____________________________________________________________|
>
>
>_______________________________________________
>http://lists.egnite.de/mailman/listinfo/en-nut-discussion
More information about the En-Nut-Discussion
mailing list