Author Topic: DynDNS  (Read 11908 times)

Offline Lukee

  • Newbie
  • *
  • Posts: 10
    • View Profile
DynDNS
« on: August 29, 2008, 03:06:56 PM »
Hello,

I would like use the DynDNS, but I don't know how do it. My device must send following information:

http://username:password@members.dyndns.org/nic/update?hostname=yourhostname&myip=ipaddress&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG

Server DynDNS listening on the 80 or 8245 port.

Thanks for fast reply!

Best Regards

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: DynDNS
« Reply #1 on: August 29, 2008, 04:29:26 PM »
Hi

To do this you need to generate a HTTP GET request.

What the HTTP client does is connect to the web site
http://members.dyndns.org - this needs to be resolved using DNS - in fact it resolves to the IP address 63.208.196.95 (this is probably a fixed IP so could be used directly to save the DNS part).

When it has connected to the port (80 for example) it performs a GET with the parameters "/nic/update?hostname=yourhostname&myip=ipaddress&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG".
The web site will return a 401 "Authorization required" message if no authentication information is added, which will cause a login popup in a standard browser to appear.

The browser will then send the authorization credentials "username" and "password" as part of the next GET attempt.
It is possible to send the authorization in the first GET since the browser is probably only no doing automatically the first time for security reasons.

The best way to do this is to create a TCP socket which establishes the connection and then sends the HTTP content (it must construct this in a TCP buffer and send it). To see the content, record your own connection from your standard browser and basically copy it. The user name and password need to be encrypted using base64 encoding - there are routines for this in webutils.c

Once the GET connection works, the server may return some other information which you can interpret to validate the success.

Regards

Mark

Offline Lukee

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: DynDNS
« Reply #2 on: September 01, 2008, 03:16:45 PM »
Hi,

Which function should I use to send with GET method this data ?

regards
Lukee

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: DynDNS
« Reply #3 on: September 01, 2008, 04:28:49 PM »
Lukee

You can use fnSendTCP().

Look at the way that smtp.c uses this to send text based commands.

Regards

Mark

Offline Lukee

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: DynDNS
« Reply #4 on: September 02, 2008, 03:53:08 PM »
Hi Mark!

I try create a TCP socket. This is my code:

Code: [Select]
static USOCKET        HTTP_GET_TCP_socket = -1;
static unsigned char  ipHTTP_GET[IPV4_LENGTH] = {63,208,196,95};
...
HTTP_GET_TCP_socket = fnGetTCP_Socket(TOS_MINIMISE_DELAY, (unsigned short)10, fnTestListener);
fnTCP_Connect(HTTP_GET_TCP_socket, ipHTTP_GET, 80, 0, 0);
...

HTTP_GET_TCP_socket get value equal 8, but when fnTCP_Connect is run than error occur. I get following information from compiler:

"Unhandled exception at 0x0045bf7f in uTaskerV1-3.exe: 0xC0000005: Access violation writing location 0x004cb7a0."

What I do wrong ?

Best Regards
Lukee

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: DynDNS
« Reply #5 on: September 03, 2008, 01:01:44 PM »
Hi Lukee

I have just tested this code and it didn't cause any problem.
However I don't know whether the problem is in this code or somewhere else. I am wondering whether the crash (I think in the simulator) is a consequence of using an additional TCP socket, which is then not available for another piece of code.
Ensure that you have increased the number of TCP sockets in the socket pool: #define USER_TCP_SOCKETS in config.h should be increased by one for each TCP socket that is needed by the application.

Such a crash in the simulator should be quite easy to analyse. You can repeat the command that crashed and identify why it is accessing bad memory - often due to a pointer which has not been initialised or has been overwritten.

Regards

Mark

Offline Lukee

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: DynDNS
« Reply #6 on: September 04, 2008, 09:49:12 AM »
Hello Mark,

I have question about sending TCP packet.

1. I must create socket: HTTP_GET_TCP_socket = fnGetTCP_Socket(TOS_MINIMISE_DELAY, (unsigned short)10, fnTestListener);
2. next connect to selected IP and selected PORT: fnTCP_Connect(HTTP_GET_TCP_socket, ipHTTP_GET, 80, 0, 0);
3. and than send packet using this function: fnSendTCP(HTTP_GET_TCP_socket, (unsigned char *)buf, usDataLen, 0);
4. when I send everything what I want I must close connection: fnTCP_close(HTTP_GET_TCP_socket);

Everything what I wrote is correct ?


Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: DynDNS
« Reply #7 on: September 04, 2008, 08:34:40 PM »
Lukee

Yes, the sequence is correct.

Note that you should only send data once the connection has been made (in the listener, the callback even TCP_EVENT_CONNECTED signals this).
After each individual TCP data packet that you send you shoudl wait for an acknowledgment (event TCP_EVENT_ACK) before sending further data packets.
The same is true for the last data packet that you want to send. You should wait for its TCP_EVENT_ACK before closing the connection.

Regards

Mark