Shop OBEX P1 Docs P2 Docs Learn Events
Hostname Expired ?? Ip stil working ; DHCP renew Leastime — Parallax Forums

Hostname Expired ?? Ip stil working ; DHCP renew Leastime

Igor_RastIgor_Rast Posts: 357
edited 2012-12-12 13:58 in Accessories
Ok . So here is the next headace that poped op

I think it all has to do with dhcp leas period. lease renewal maybe ?

from yesterday the proxy server worked fine localy or from the net , loading the page , running the graphs (xml). tested it a couple of times during the next day . from other placed , latly at night the propeller was no longer letting me see the graph run, but the page was still coming up , it works.

MMM.

Finding out whats happening , I see I can not reach the propeller by hostname , But if I type it by ip then ip does.

If I go to see in my modem web-page, what dhcp computer are connected, usualy the px-210 is among them , now it is gone,
If i access the propeller by ip adress. then it does work fine .
I updated the xml to change the hostname used to the ip . then all works fine again ,
sad.jpg

Anyway , the prop is gone in the list , still accesable by ip but not by hostname ,
so the modem must have removed them when the lease period ended orso .
How can we prevent this from happening. it does keep working for the rest fine , by ip.

Im using Mike G latest code found online
790 x 678 - 82K
sad.jpg 82.2K
«13

Comments

  • Mike GMike G Posts: 2,702
    edited 2012-11-12 06:20
    The DHCP host name field is an entry in the router's DHCP client table. It does not resolve name to IP nor is the DHCP object designed to do so.

    The DHCP host name does not resolve on my network. Which is the main main reason I wrote the NetBIOS object; broadcast IP/name resolution on a local network.

    I'm a little confused though... if the DHCP lease period has ended, which you identified. Why not simply invoke DHCP again? What is the purpose of this post? Is it informative? Are you looking for a solution?
  • Igor_RastIgor_Rast Posts: 357
    edited 2012-11-12 10:04
    Mike G wrote: »
    The DHCP host name field is an entry in the router's DHCP client table. It does not resolve name to IP nor is the DHCP object designed to do so.

    okl. mike , maybe its not designed to do it , but by changing the CON value below in the dhcp object, I was always able to open the prop just by calling it by the hostname
    hostName        byte  "Px-210", $0
    
    . I thouth youd incorporated the netbios inside it , ill have to go look at it more closly then , but it did work fine .probably the modem that remembers the hostname and redirects.

    . What I think happened was that , when the leas time ended , The prop did not ask for a renewal of the ip adres,

    when that happen , (foto previus post ), the propeller was gone from the list , Then the addressing by hostname stopped working ,
    but it was still possible to get to the prop if i was using the ip adress, that it had,

    I didn't want to restart it , so I would lose the current scenario

    so today, I test it again ,
    And now i can not even access it by its ip , so I cannot access the propeller anymore ,havent touched it sins yesterday

    I went to look inside the modem page, and I can see that anothe tel has been assign the ip adress that the prop had before , thats probably why i cant reach
    Mike G wrote: »
    Why not simply invoke DHCP again?
    I thouth this was already beeing done , keeping the same ip assignd, now , if the prop is connected for long , someone else may get his ip assignd by the dhcp engine of the modem , making it unaccessable.

    Restarting the prop I get every thing working again as normal , Getting the propeller by Hostname ,
    Image is how the modem has registerd it
    bek.jpg
    453 x 152 - 29K
    bek.jpg 29.2K
  • Mike GMike G Posts: 2,702
    edited 2012-11-12 11:44
    okl. mike , maybe its not designed to do it , but by changing the CON value below in the dhcp object, I was always able to open the prop just by calling it by the hostname
    That may be the case on your network which is not standard. That same logic applied to my network will not work.
    . What I think happened was that , when the leas time ended , The prop did not ask for a renewal of the ip adres,
    It is up to the client to manage the IP lease. That means you - the programer - must manage the lease.

    As far as I can tell, the DHCP object is functioning as expected.
  • Igor_RastIgor_Rast Posts: 357
    edited 2012-11-12 15:20
    Ok mike .

    So for me the next job =
    1. get the prop to find out when the leastime is ending, and renew it before it does it before it expires .
    2. integrate the netbios protocol along with the rest of the driver . tp be sure its always accesable by hostname

    yes ? or do i understand it wrong ?
  • twctwc Posts: 107
    edited 2012-11-12 17:17
    Hey Mike:

    Re: renewing DHCP lease. I tried modifying TcpSocketClientDemoDhcpDns by putting Main in a REPEAT loop...
    'REPEAT
      pst.str(string("Initialize W5200", CR))
      wiz.Start(3, 0, 1, 2)
      'Loop until we get the W5200 version
      'This let us know that the W5200 is ready to go
      repeat until wiz.GetVersion > 0
        pause(250)
        if(i++ > ATTEMPTS*5)
          pst.str(string(CR, "W5200 SPI communication failed!", CR))
          return
      wiz.HardReset(RESET_PIN)
    'REPEAT  
      wiz.SetMac($00, $08, $DC, $17, $62, $ca)
    'REPEAT
      pst.str(string("Getting network paramters", CR))
      dhcp.Init(@buff, 7)
    'REPEAT
      pst.str(string("Requesting IP....."))
      repeat until dhcp.DoDhcp
        if(++t1 > ATTEMPTS)
          quit
    
    
    ...you can see the 4 different places I tried REPEATing. The later three REPEATs encounter DHCP discover error on 2nd pass. Just FYI - The first REPEAT option causes the SPI check to fail (maybe need to call a wiz.stop before (re)wiz.start or ?). I noticed if I just put a 'reboot' statement at the end of Main it works fine i.e. repeats the entire process (i.e. DHCP, DNS, file display) indefinitely. What's the best way to renew the lease? Is there a way to find out when it expires? Or maybe it's reasonable practice just to renew every 'n' hours? Thanks for your support.
  • Mike GMike G Posts: 2,702
    edited 2012-11-12 19:00
    Re: renewing DHCP lease. I tried modifying TcpSocketClientDemoDhcpDns by putting Main in a REPEAT loop...
    ...you can see the 4 different places I tried REPEATing. The later three REPEATs encounter DHCP discover error on 2nd pass. Just FYI - The first REPEAT option causes the SPI check to fail (maybe need to call a wiz.stop before (re)wiz.start or ?). I noticed if I just put a 'reboot' statement at the end of Main it works fine i.e. repeats the entire process (i.e. DHCP, DNS, file display) indefinitely.
    I do not recommend continually initializing the W5200 objects.
    What's the best way to renew the lease? Is there a way to find out when it expires? Or maybe it's reasonable practice just to renew every 'n' hours?
    DHCP lease time is a router\network configuration. My router defaults to 24 hours. You need either a timer or a real time clock. Set the timer to 12 hours then invoke dhcp.DoDhcp.
  • twctwc Posts: 107
    edited 2012-11-13 04:29
    Mike G wrote: »
    Set the timer to 12 hours then invoke dhcp.DoDhcp.

    ...that's what I thought I was doing with this REPEAT option I tried i.e.
    REPEAT 'rest of Main i.e. DHCP, DNS, TCP, HTTP, display file
      pst.str(string("Requesting IP....."))
      repeat until dhcp.DoDhcp
        if(++t1 > ATTEMPTS)
          quit
    

    ...1st pass works but the 2nd pass results in DHCP 'Discover Error'. If you insert a REPEAT at the same place does it work for you?

    The clue is that putting the REBOOT command at the end of Main (instead of using a REPEAT loop) works i.e. REBOOT is initializing something that allows DHCP to work repeatedly while REPEAT encounters DHCP 'Discover Error' the 2nd pass. I did try (re)moving the wiz.HardReset, doesn't change behavior.
  • Mike GMike G Posts: 2,702
    edited 2012-11-13 11:13
    Be sure to clear the buffer before issuing DoDhcp.
      REPEAT 'rest of Main i.e. DHCP, DNS, TCP, HTTP, display file
        pst.str(string("Requesting IP....."))
        bytefill(@buff, 0, $F0)
        pause(1000)
        t1 := 0
        repeat until dhcp.DoDhcp
          if(++t1 > ATTEMPTS)
            quit
    

    You can also clear the buffer from the DoDhcp method.
    PUB DoDhcp | ptr
    
      bytefill(buffPtr, 0, DHCP_MAGIC_COOKIE) 
    

    I'll add a renew method, expose the lease time, and maybe add a timer object. A timer will require a COG.
  • Igor_RastIgor_Rast Posts: 357
    edited 2012-11-13 13:33
    Mike about calling the prop by hostname
    In my situation with the current objects used,
    what is best ,
    1. to integrate the netbios into the prop to get it accesable by name ,( netbios ip resolution )
    or 2. is the DNS object the best to implement with it to resolve the ip by name
    but then there wil be a socket needed to keep resolving the ip, ? or do i understand the working wrong
    Or doesnt it matter that much , if its only inteded for local acces ( hostname ip resolution)


    still testing with the dhcp renewal. the extra cog needed you mentio is the only thing making me think twice . cant a counter do the job , (i:= i++. if i > 100000? renew ip )
    happy to see your renewal code.
  • twctwc Posts: 107
    edited 2012-11-13 14:48
    Hey Mike:

    Still seems to have a problem. I cut down the TCSDDD code to just do repeated calls to DHCP...
      pst.str(string("Initialize W5200", CR))
      wiz.Start(3, 0, 1, 2)
      wiz.SetMac($00, $08, $DC, $17, $62, $ca)
      pst.str(string("Getting network parameters", CR))
      dhcp.Init(@buff, 7)
    REPEAT
      pst.str(string("Requesting IP....."))
      bytefill(@buff, 0, $F0)
      pause(1000)
      t1 := 0
      repeat until dhcp.DoDhcp
        if(++t1 > DHCP_ATTEMPTS)
          quit
      if(t1 > DHCP_ATTEMPTS)
        pst.char(CR) 
        pst.str(string(CR, "DHCP Attempts: "))
        pst.dec(t1)
        pst.str(string(CR, "Error Code: "))
        pst.dec(dhcp.GetErrorCode)
        pst.char(CR)
        pst.str(dhcp.GetErrorMessage)
        pst.char(CR)
        return
      else
        PrintIp(dhcp.GetIp)
    

    ...it still has same behavior - DHCP works the first pass, gets 'Discover Error' 2nd pass. Does it work at your end? Interesting if I take out the REPEAT and stick a REBOOT at the end it works fine.
  • Mike GMike G Posts: 2,702
    edited 2012-11-13 15:44
    Does it work at your end?
    Yes, it works on my end.

    I appreciate your help testing the objects. I'll try to get a formal fix out this weekend.

    A Wireshark filter using "port 67 or port 68" would go a long way helping me to figure out what is happening on your network.
    561 x 865 - 78K
  • twctwc Posts: 107
    edited 2012-11-14 06:01
    Was thinking the fact REBOOT works was a clue so I tried some stuff. Now I'm able to get REPEATed calls to DHCP working with this code...
      pst.str(string("Initialize W5200", CR))
      wiz.Start(3, 0, 1, 2)
      pst.str(string("Getting network parameters", CR))
    REPEAT
      wiz.HardReset(4)
      wiz.SetMac($00, $08, $DC, $17, $62, $cb)
      dhcp.Init(@buff, 7)
      pst.str(string("Requesting IP....."))
      bytefill(@buff, 0, $F0)
      pause(1000)
      t1 := 0
      repeat until dhcp.DoDhcp
        if(++t1 > DHCP_ATTEMPTS)
          quit
      if(t1 > DHCP_ATTEMPTS)
        pst.char(CR) 
        pst.str(string(CR, "DHCP Attempts: "))
        pst.dec(t1)
        pst.str(string(CR, "Error Code: "))
        pst.dec(dhcp.GetErrorCode)
        pst.char(CR)
        pst.str(dhcp.GetErrorMessage)
        pst.char(CR)
        return
      else
        PrintIp(dhcp.GetIp)
    

    ...interestingly, using wiz.SoftReset instead of wiz.HardRest doesn't work (i.e. still encounters the '2nd pass Discover Error'). However, this 'fix' isn't perfect since now, though the program makes it thru the 2nd and subsequent passes of DHCP, the problem is shifted to '2nd pass DNS error' (resolved ip =0.0.0.0). BTW, as with DHCP, do I need a bytefill to clear the buffer between repeated use of DNS?

    I will test some more, don't want to be a bother until I have a better feel. Sorry I can't be of more assistance with wireshark - it can't see any of the DHCP activity handled by the router. The obvious solution is to set up my own server, but that's beyond my means and ability at this time. Maybe there's a way (ex: port forwarding) to setup a test? But I can't fool around too much with my 'work' PC nor the LAN - if I crash the network wife & kids won't be happy :=)

    I have to go out of town for a few days, get back into it next week. Thanks for your support Mike!
  • Igor_RastIgor_Rast Posts: 357
    edited 2012-11-14 14:48
    Ok . Ill jump in with som wireshark data then .

    I did some more tryling with the dhcp , renewal .
    Using the code below , extracted from the html5graphdemo .

    The renewing works fine with my ISP modem , but will not work with my linksys modem

    PUB Main | i, page, dnsServer
      
      wiz.HardReset(nRESET_WIZ)
        
      i := 0
      
      pst.Start(115_200)
      pause(500)
    
      pst.str(string("Initialize W5200", CR))
      wiz.start(6, 5, 4, 7) 
      wiz.SetMac($00, $08, $DC, $16, $F8, $01)
    
      pst.str(string("Getting network paramters", CR))
      dhcp.Init(@buff, 7)
     
      repeat 
        pst.str(string("Requesting IP....."))
    
        i := 0 
        repeat until dhcp.DoDhcp
          if(++i > DHCP_ATTEMPTS)
            quit
    
        if(dhcp.GetErrorCode > 0 OR i > DHCP_ATTEMPTS)
          pst.char(CR) 
          pst.str(string(CR, "DHCP Attempts: "))
          pst.dec(i)
          pst.str(string(CR, "Error Code: "))
          pst.dec(dhcp.GetErrorCode)
          pst.char(CR)
          pst.str(dhcp.GetErrorMessage)
          pst.char(CR)
    
          return
        else
          PrintIp(dhcp.GetIp)
    
        pst.str(string("DNS..............."))
        dnsServer := wiz.GetDns
        PrintIp(wiz.GetDns)
    
        pst.str(string("DHCP Server......."))
        printIp(wiz.GetDhcpServerIp)
    
        pst.str(string("Router IP........."))
        printIp(wiz.GetRouter)
        pst.char(CR)
     
       pause(2000)
    

    With My isp modem , it looks to get the dhcp ip assign succesfully repeatedly , so incorporating it by a timmer or clock will be all thats left .
    Screenshots ,

    ss1.jpg
    ss2.jpg


    wireshark log ISP modem succesful.zip

    but when I disconnected all from the network modem en connect it to the linksys modemto get the wireshark (udp.port==68) and (udp.port==67) working on the linksys to so sniff out whats happening . because its not working there ,
    If I see closely the offer is beeing sent to the wrong ip adress (sourse ip ) therefore never getting to the prop for it to send the ack back out ,
    ff1.jpg
    ff2.jpg


    wireshark logs Linksys fail.zip

    Hope this data is helpfull
    1024 x 521 - 121K
    364 x 610 - 90K
    997 x 165 - 61K
    343 x 276 - 28K
  • twctwc Posts: 107
    edited 2012-11-20 04:30
    Re: failure when REPEATing DHCP (i.e. renewing lease). I did find a solution that works, or make that 'remember' a solution discovered before. I was trying to think why the 'HardReset' would allow a REPEATed DHCP. Then I recalled that early on in testing I found that DHCP would not work (for my setup) unless the source IP was set to 0,0,0,0 (i.e. wiz.SetIp (0,0,0,0)). Notably, it wouldn't work with an otherwise valid (for my network) IP address - which is of course what the first pass through DHCP delivers. So (for my setup) the solution is as simple as resetting the IP to 0,0,0,0 prior to each pass thru DHCP i.e...
      pst.str(string("Initialize W5200", CR))
      wiz.Start(3, 0, 1, 2)
    REPEAT
    'DHCP
      wiz.SetIp(0,0,0,0)
      pst.str(string("Getting network parameters", CR))
      dhcp.Init(@buff, 7)
    'REPEAT
      pst.str(string("Requesting IP....."))
      bytefill(@buff, 0, $F0)
      repeat until dhcp.DoDhcp
        if(++t1 > DHCP_ATTEMPTS)
          quit
    

    ...now it works fine for REPEATing the call to DHCP (and then DNS). Why don't you try it with your linksys Igor, maybe it will work for you too.
  • Igor_RastIgor_Rast Posts: 357
    edited 2012-11-20 05:13
    @twc, Thanks for the reply . I am going to test that one out and let you know about it .
    I think the problem with the linksys not getting the renewd ip has a different origin, because its also not getting the ip correctly the first pass,

    If i look at what the wireshark sees(previous post) , The DHCP offer that my linksys modem sends out after the discovery request from the wiznet .
    Is not formatted well , With this I mean ,
    The modem is suppose to send the DHCP offer to 192.168.2.254 (dhcp server ip) . But its sending the offer to 192.168.2.1 wich was probably the ip that was supose to be offerd to the wiznet , this probably is the cause of the ip not getting set, Did have the problem before, Mike did a bugfix on it . But I havent used the linksys modem after that till now . thats when i realized the bug was still there ..
    and probably inside the discovery request . correct me if im wrong

    I saw that mike did a few changes and is working on the dhcp leastime , he has updated the source codes. now trying to figure out whats changed and if it takes care of my problem with the linksys.

    @Mike . Hows the leastime getting along, what were the bug fixes that you implemented , were they for the ip problem that I have now or was it somthing else beeing fixed in the object ?

    Igor
  • Mike GMike G Posts: 2,702
    edited 2012-11-20 07:17
    Thank you for the logs.
    The modem is suppose to send the DHCP offer to 192.168.2.254 (dhcp server ip) . But its sending the offer to 192.168.2.1 wich was probably the ip that was supose to be offerd to the wiznet , this probably is the cause of the ip not getting set,
    The DHCP packet is broadcast to 255.255.255.255. The source, 192.168.2.1, is the IP address of the router sending the Offer and ACK packet. This is correct. Only one of the WireShark logs shows multiple DHCP requests; increasing Ip. This logs shows the router responding with a DHCP NAK. Probably due to the requested IP being 0.0.0.0 and not on the network. The other logs show only one DHCP request. We might have to look at the testing code for errors or the logs did not run long enough to capture the DHCP request.
    I saw that mike did a few changes and is working on the dhcp leastime , he has updated the source codes. now trying to figure out whats changed and if it takes care of my problem with the linksys
    The DHCP object has been updated/refactored.
    • Added a requestedIP field to the DHCP obejct; PUB SetRequestIp(octet3, octet2, octet1, octet0). Use this field to request an IP. If the field is 0.0.0.0 (default) an IP is not requested. This should fix the DHCP NAK response.
    • Reset DHCP packet fields between requests.
    • Added dhcp.GetLeaseTime to retrieve the lease time (in seconds) sent in the ACK packet.
  • twctwc Posts: 107
    edited 2012-11-20 07:35
    ...oops, I spoke a bit too soon. It's true the wiz.SetIp(0,0,0,0) solves the DHCP renewal issue. But now that it makes a second and subsequent pass thru DHCP it turns out the REPEATed DNS fails (I forgot I hardwired the dest IP when testing earlier). Anyway, Mike can you confirm this code works (with or without the wiz.SetIp(0,0,0,0)) or not with your setup? On my setup (with the wiz.SetIp(0,0,0,0)) DHCP works each pass but DNS only works the first pass, 2nd and subsequent passes return resolved ip 0.0.0.0. As before, if I replace the REPEAT loop with a REBOOT both DHCP and DNS work multiple passes. I tried a few things like moving the dns.Init statement, bytefilling the buffer even wiz.HardReset but no luck. Can you think of any reason (ex: global variable init, socket init, open, close, etc.) the second pass thru DNS isn't like the first (i.e. after F10 or REBOOT)? I'll keep at it, watch for new code.
    REPEAT
    'DHCP
      wiz.SetIp(0,0,0,0)
      pst.str(string("Getting network parameters", CR))
      dhcp.Init(@buff, 7)
      pst.str(string("Requesting IP....."))
      bytefill(@buff, 0, $F0)
      repeat until dhcp.DoDhcp
        if(++t1 > DHCP_ATTEMPTS)
          quit
      if(t1 > DHCP_ATTEMPTS)
        pst.char(CR) 
        pst.str(string(CR, "DHCP Attempts: "))
        pst.dec(t1)
        pst.str(string(CR, "Error Code: "))
        pst.dec(dhcp.GetErrorCode)
        pst.char(CR)
        pst.str(dhcp.GetErrorMessage)
        pst.char(CR)
        return
      else
        PrintIp(dhcp.GetIp)
      pst.str(string("DNS..............."))
      dnsServer := wiz.GetDns
      PrintIp(wiz.GetDns)
      pst.str(string("DHCP Server......."))
      printIp(wiz.GetDhcpServerIp)
      pst.str(string("Router IP........."))
      printIp(wiz.GetRouter)
      pst.str(string("Gateway IP........"))                                        
      printIp(wiz.GetGatewayIp)
      pst.char(CR) 
    'DNS
      pst.str(string("Resolve domain IP.")) 
      dns.Init(@buff, 6)
      remoteIP := dns.ResolveDomain(@site)
      PrintIp(remoteIP)
      pst.char(CR)
      pause(1000)
    
  • Mike GMike G Posts: 2,702
    edited 2012-11-20 08:24
    Looking into the reported DNS bug.
  • Mike GMike G Posts: 2,702
    edited 2012-11-20 09:26
    I'll have to look more into the DNS object. If the line remoteIP := dns.ResolveDomain() is not within a repeat loop then the IP resolves. It could be a scope issue or testing harness bug.
    Anyway, Mike can you confirm this code works (with or without the wiz.SetIp(0,0,0,0)) or not with your setup?
    I do not use wiz.SetIp(0,0,0,0) and it works fine.
  • twctwc Posts: 107
    edited 2012-11-20 11:43
    Hey Mike - updates on my testing..

    1. Just curious, does the previous test work with the wiz.SetIp(0,0,0,0) stmt. on your setup?

    2. To isolate the DNS issue I moved the REPEAT statement...
    REPEAT
    'DNS
      pst.str(string("Resolve domain IP.")) 
      remoteIP := dns.ResolveDomain(@site))
      PrintIp(remoteIP)
      pst.char(CR)
      pause(1000)
    

    ...on my setup it resolves IP correctly the first pass (i.e. after F10 or REBOOT), 2nd and subsequent pass return 0.0.0.0.

    3. Now I'm experimenting with DnsDemo.spin, just trying to put it in a REPEAT loop...
    REPEAT
      sock.Init(0, UDP, 53)
      sock.RemoteIp(10,0,0,1)
      sock.RemotePort(53)
      pause(500)
     'REPEAT
      CreateTransactionId($FFFF)
      FillTransactionID
     'REPEAT
      url := @url5
      'Copy header to the buffer
      bytemove(buffPtr, @msgId, DNS_HEADER_LEN)
      'Format and copy the url
      ptr := ParseUrl(url, buffPtr+DNS_HEADER_LEN)
      'Add the QTYPE and QCLASS
      bytemove(ptr, @QTYPE, 4)
      ptr += 4
      DisplayMemory(buffPtr, ptr - buffPtr, true)
      ptr := SendReceive(buffPtr, ptr - buffPtr+1)
      GetRcode(ptr)
      pst.str(RCodeError)
      pst.char($20)
      pst.dec(rcode)
      pst.char(13)
     ' if(rcode == 0)
        ansRRS := ParseDnsResponse(ptr) 
      repeat i from 0 to ansRRS-1
        ifnot(GetResolvedIp(i) == NULL)
          pst.str(string("ip_"))
          pst.dec(i)
          pst.char($20)
          PrintIP(GetResolvedIp(i))
          pst.char(CR)
      sock.Close
      pause(3000)
    

    ...tried putting the REPEAT a few places, none successful in making a 2nd pass As shown, the terminal displays...
    Initialize
    -----------------------------------------------------
          00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
          -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    0000  BF 28 01 00 00 01 00 00 00 00 00 00 03 77 77 77
    0010  07 77 65 61 74 68 65 72 03 67 6F 76 00 00 01 00
    0020  01 00
    Start: 116 Len: 33
    -----------------------------------------------------
    Send Bytes: 34
    Open
    Send Message
    Bytes to Read: 144
     
    Message from: 10.0.0.1:53 (136)
    -----------------------------------------------------
          00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
          -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    0000  BF 28 81 80 00 01 00 04 00 00 00 00 03 77 77 77
    0010  07 77 65 61 74 68 65 72 03 67 6F 76 00 00 01 00
    0020  01 C0 0C 00 05 00 01 00 00 00 34 00 1F 03 77 77
    0030  77 07 77 65 61 74 68 65 72 03 67 6F 76 09 65 64
    0040  67 65 73 75 69 74 65 03 6E 65 74 00 C0 2D 00 05
    0050  00 01 00 00 11 9C 00 10 04 61 38 39 35 01 67 06
    0060  61 6B 61 6D 61 69 C0 47 C0 58 00 01 00 01 00 00
    0070  00 0C 00 04 17 3D C2 93 C0 58 00 01 00 01 00 00
    0080  00 0C 00 04 17 3D C2 98 00
    Start: 124 Len: 136
    -----------------------------------------------------
    
    Disconnect
    No error condition. 0
    ip_0 23.61.194.147
    ip_1 23.61.194.152
    -----------------------------------------------------
          00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
          -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    0000  C8 BC 01 00 00 01 00 00 00 00 00 00 03 77 77 77
    0010  00 00 01 00 01 77
    Start: 116 Len: 21
    -----------------------------------------------------
    Send Bytes: 22
    Open
    Send Message
    Bytes to Read: 29
     
    Message from: 10.0.0.1:53 (21)
    -----------------------------------------------------
          00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
          -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    0000  C8 BC 80 83 00 01 00 00 00 00 00 00 03 77 77 77
    0010  00 00 01 00 01 00
    Start: 124 Len: 21
    -----------------------------------------------------
    
    Disconnect
    Name Error 3
    ip_0 23.61.194.147
    ip_-1 0.0.0.0
    -----------------------------------------------------
          00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
          -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    0000  E6 07 01 00 00 01 00 00 00 00 00 00 03 77 77 77
    0010  00 00 01 00 01 77
    Start: 116 Len: 21
    -----------------------------------------------------
    Send Bytes: 22
    Open
    Send Message
    Bytes to Read: 29
     
    Message from: 10.0.0.1:53 (21)
    -----------------------------------------------------
          00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
          -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    0000  E6 07 80 83 00 01 00 00 00 00 00 00 03 77 77 77
    0010  00 00 01 00 01 00
    Start: 124 Len: 21
    -----------------------------------------------------
    
    Disconnect
    Name Error 3
    ip_0 23.61.194.147
    ip_-1 0.0.0.0
     
    

    ...Note that I commented out the ' if (rcode == 0' check so the program displays the ParseDnsResponse even though there's a 'Name Error 3''. So in the display notice a) 2nd & subsequent DNS requests send less bytes than the first and b) the failing ParseDnsResponse seems to have one valid IP (instead of two as in the correct first pass) and one oddball 'ip_-1 0.0.0.0'.

    Does this code exhibit similar behavior on your setup? If you tell me the proper way to put DnsDemo.spin in a REPEAT loop (i.e. where to put REPEAT statement) I can try it on my setup, help zero in on the difference. Thanks a lot Mike!
  • Igor_RastIgor_Rast Posts: 357
    edited 2012-11-20 11:45
    Ok, So here the next Logs , ,
    Im trying to understand first to minimize stupid questions beeing asked .:P .

    About the DNS . to get the DNS working along with the rest ,as I did understand it wrong before ,
    does it take just the adding of the dns object to the list
    dns             : "Dns.spin"
    

    Adding a url thats gets resolved in the DAT section
    url1  byte    "www.px-210.nl", $0
    

    and adding the next lines below the dhcp statments in the repeat loop.
    pst.str(string("Resolve domain IP.")) 
        dns.Init(@buff, 6)
        remoteIP := dns.ResolveDomain(@url1)
        PrintIp(remoteIP)
        pst.char(CR)
    

    Was this all thats needed to incorporate the dns with the server ???
    Im having a dificult time with the DNS as my modem seems to already resolve the hostname to the ip adres, and like mike said this is not always the case . so I havent found a way to check if the dns itself is working . (without renewing )

    I have updated the new source files from mike , Using the code below to test the ip renewal and the dns
    PUB Main | i, page, dnsServer,remoteIP
      
      wiz.HardReset(nRESET_WIZ)
        
      i := 0
      
      pst.Start(115_200)
      pause(500)
    
      pst.str(string("Initialize W5200", CR))
      wiz.start(6, 5, 4, 7) 
      wiz.SetMac($00, $08, $DC, $16, $F8, $01)
    
      pst.str(string("Getting network paramters", CR))
      dhcp.Init(@buff, 7)
     
      repeat 
        pst.str(string("Requesting IP....."))
    
        i := 0 
        repeat until dhcp.DoDhcp
          if(++i > DHCP_ATTEMPTS)
            quit
    
        if(dhcp.GetErrorCode > 0 OR i > DHCP_ATTEMPTS)
          pst.char(CR) 
          pst.str(string(CR, "DHCP Attempts: "))
          pst.dec(i)
          pst.str(string(CR, "Error Code: "))
          pst.dec(dhcp.GetErrorCode)
          pst.char(CR)
          pst.str(dhcp.GetErrorMessage)
          pst.char(CR)
    
          return
        else
          PrintIp(dhcp.GetIp)
    
        pst.str(string("DNS..............."))
        dnsServer := wiz.GetDns
        PrintIp(wiz.GetDns)
    
        pst.str(string("DHCP Server......."))
        printIp(wiz.GetDhcpServerIp)
    
        pst.str(string("Router IP........."))
        printIp(wiz.GetRouter)
        
        pst.str(string("Gateway IP........"))                                        
        printIp(wiz.GetGatewayIp)
          
        pst.char(CR)
     
        pst.str(string("Resolve domain IP.")) 
        dns.Init(@buff, 6)
        remoteIP := dns.ResolveDomain(@url1)
        PrintIp(remoteIP)
        pst.char(CR)
    
         pause(2000)
       
    

    Okay . Connected to my ISP modem , this is what happens ,
    The Ip renewal seems to work fine , It did work fine before also with this modem , renewing it multiple times without a problem.
    But for the DNS , if i incorporated it the right way then . Resolves only on the first pass. and after that keeps resolving to 0.0.0.0.
    With the DNS lines inserted in the code , ( not resolving dns on second pass and forth )
    777.jpg


    Without the DNS inserted in the code .Seems to renew fine . only ip
    8888.jpg


    wireshark logs ISP modem LOG.zip

    Thats was the ISP Modem

    Connecting all to the linksys modem I get the following result ,
    The DHCP ip assigning issue seems to be fixed with the updated code.. Renewing it does also look to be working fine , This was not the case before . so that issue seems to be fixed,
    This is the case without the DNS code beeing run.
    99999999888888.jpg


    If i put the DNS code also in it , I can see the DNS never gets assignd , not even on the first pass , always resolving to 0.0.0.0 probably the bug mike is now already aware of.
    So Here some more logs where this is going wrong , hoping to get it all working.
    9999999.jpg


    Wireshark log linksys modem Linksys log.zip



    Igor

    o @ twc , I dont reset the ip to 0.0.0.0 and that works fine with both modems

    @ mike , where to i incorporate the dhcp.GetLeaseTime to get it right , can you give a small example
    387 x 870 - 121K
    380 x 856 - 110K
    357 x 798 - 116K
    375 x 792 - 101K
  • twctwc Posts: 107
    edited 2012-11-20 15:09
    Igor_Rast wrote: »
    o @ twc , I dont reset the ip to 0.0.0.0 and that works fine with both modems

    I understand you and Mike don't need this wiz.SetIp(0,0,0,0), I was wondering what happens if you include it - still works OK or ?]

    I got the updated software, results not changed i.e...

    1. With the wiz.SetIp(0,0,0,0) I can make multi-passes thru DHCP, without it 2nd pass is Discover Error
    2. 2nd pass thru DNS fails (resolves to 0.0.0.0) with different 'Bytes Sent' (using modified DnsDemo.spin in post #21) than 1st pass

    Mike, maybe the DhcpDemo.spin and DnsDemo.spin should loop repeatedly to demonstrate proper usage and expose any issues. I'm not sure if my hacked DnsDemo.spin (REPEAT stmt. added) is proper, might/might not have the same issue (i.e. different 'Bytes Sent' on 2nd pass) on your & Igors setup.
  • Mike GMike G Posts: 2,702
    edited 2012-11-20 16:57
    Does this code exhibit similar behavior on your setup? If you tell me the proper way to put DnsDemo.spin in a REPEAT loop (i.e. where to put REPEAT statement) I can try it on my setup, help zero in on the difference.

    In this instance, the test case caused the bug due to the destructive nature of dns.ParseUrl() and (I believe) the scope of repeat. ParseUrl converts a url string to its encoded DNS packet value. The url www.weather.gov is converted to the following encoding in a two step process
       w  w  w     w  e  a  t  h  e  r     g  o  v   
    03 77 77 77 07 77 65 61 74 68 65 72 03 67 6F 76 
    

    The first steps replaces all the dots in the source string with zero terminators. The second step reads each url segment length copies the length to the DNS packet then moves the segments to fledgling DNS packet.

    When this method is placed in a repeat loop, the second iteration is not longer "www. weather. gov", $0. It's $03, w, w w, $00. Hence, the name error returned from the DNS query. I'd have to runs some tests but I believe the same scope issue is happening with the inline constant, string("www.weather.gov"), within the repeat loop.

    I added a small buffer to Dns.Spin and DnsDemo.spin. The URL is copied to the buffer. dns.ParseUrl() modifies the buffer version and leaves the original. I'm not too fond of this solution. I might look into making the dns.ParseUrl() a little smarter so it can recognize an encoded URL. I'm not sure how often this situation will occur in a real world application but since it is possible, I'll add validation.
  • Mike GMike G Posts: 2,702
    edited 2012-11-20 18:04
    where to i incorporate the dhcp.GetLeaseTime to get it right , can you give a small example

    Lease time is a property of the Dhcp.spin. This property is populated from the DHCP ACK packet and is the time in seconds of the lease.
      pst.str(string("Lease Time........"))
      pst.dec(dhcp.GetLeaseTime)
      pst.char(CR)
    

    Ultimately, it has to be up to the programmer to implement a lease handler. There are just too many possible hardware and software requirements to consider. I have a few ideas and built 2 beta prototypes. However, both lease handlers have resource trade-offs.
  • Igor_RastIgor_Rast Posts: 357
    edited 2012-11-20 18:17
    Nice explination Mike , i gave the added buffer a try .
    and indeed that seem to fix the issue that the domain adres not being resolved on the second pass ( MY ISP MODEM) .
    with the original url surviving , the ip keeps getting resolved on the continuing passes . Nice ,.
    wwwwwwwwwwwwwwwwwwwwwww.jpg


    But with the Linksys modem , The issue is still the same, the domain name never resolves the ip . not even the first try.
    the dhcp ip assignment doesnt seem to have any problems getting the ip renewd
    eeeeeeeee.jpg



    @twc ,
    i added the wiz.SetIp(0,0,0,0) inside the repeat to test out for you ,
    letting my code look like below
    PUB Main | i, page, dnsServer,remoteIP
      
      wiz.HardReset(nRESET_WIZ)
        
      i := 0
      
      pst.Start(115_200)
      pause(500)
    
      pst.str(string("Initialize W5200", CR))
      wiz.start(6, 5, 4, 7) 
      wiz.SetMac($00, $08, $DC, $16, $F8, $01)
    
      pst.str(string("Getting network paramters", CR))
      
     
      repeat 
        wiz.SetIp(0,0,0,0)
        dhcp.Init(@buff, 7)
        pst.str(string("Requesting IP....."))
    

    Changing this didnt seem to have any effect on the workings , the senario that did work already keeps working , and to others still dont work. and behave the same
    so this doesnt affect my setup
    367 x 796 - 110K
    406 x 525 - 66K
  • Igor_RastIgor_Rast Posts: 357
    edited 2012-11-20 18:30
    Mike G wrote: »
    Ultimately, it has to be up to the programmer to implement a lease handler. There are just too many possible hardware and software requirements to consider. I have a few ideas and built 2 beta prototypes. However, both lease handlers have resource trade-offs.

    What do you mean by resoursce trade-offs , things beeing different with a different modem manufacturer >?? or that they all use different leas times? zo making a handler that works on all is kinda a verry big job .?

    I noticed that the leastime is always the maximu leasetime time ( mine 864000 sec - 1 day) on the ongoing passed , meaning the lease time is beeing renewd on the dhcp pass, but ,
    the handler will have to figure out the leasetime of the current session without it renewing it , and only renewing if it passed half the release time , ( at half the time I readed somewhere that is usualy the right time to renew the ip adress ) .
    You will make me a verry happy man if I can see the 2 beta handler prototypes your talking about


    @Mike
    I noticed that if I use a different name in the main object for the
    url1  byte    "www.px-210.nl", $0
    
    from the name of the hostname in the dhcp object hostName
    byte  "www.px-210.nl", $0,
    
    to resolve the dns hostname ,
    then it never resolves,
    Ofcourse this is only with my isp modem with the linksys its not working at all .

    If this is the case , isnt it best to let both of them use the same variable , so this mistake is not made making it not function. for resolving its own ip to a domain name? making calling the prop by hostname work by dns
  • Mike GMike G Posts: 2,702
    edited 2012-11-20 19:35
    But with the Linksys modem , The issue is still the same, the domain name never resolves the ip . not even the first try.
    the dhcp ip assignment doesnt seem to have any problems getting the ip renewd
    I believe the problem is your network configuration. Describe the network set up. How is the Linksys router connected to the network? Is it connected to the ISP modem? If so how? Which port? Does the Linksys router replace the ISP modem?
    to resolve the dns hostname ,
    then it never resolves,
    Ofcourse this is only with my isp modem with the linksys its not working at all .

    If this is the case , isnt it best to let both of them use the same variable , so this mistake is not made making it not function. for resolving its own ip to a domain name? making calling the prop by hostname work by dns
    Apparently, your ISP modem is able to register a name to IP. The Linksys router can not. I believe this is particular to your network configuration and something you'll have to work through.

    The host name field in the dhcp object does not resolve on my network. I also use a Linksys router. I have to use NetBIOS name services to resolve name to IP on my local network.

    I think you are getting stuck on a network device configuration that is somewhat unique.
  • Igor_RastIgor_Rast Posts: 357
    edited 2012-11-20 20:08
    Mike G wrote: »
    I believe the problem is your network configuration. Describe the network set up. How is the Linksys router connected to the network? Is it connected to the ISP modem? If so how? Which port? Does the Linksys router replace the ISP modem?

    The linksys router was not connected to the intertet/ISP modem . I just pluged the propeller to the linksys router , and unpluged my pc from the isp modem and put it also connected to the linksys modem , ,the pc I only connect to be able to wireshark it all. but before I just used the serial terminal. So there is no connection with the ISP modem in the testcase nor with the internet , its like a standing alone network.( it replaces the ISP modem )
    i thout I use this test setup just to make sure the hole thing works with all modems .

    NETbios ,DNS , Hostname , Indeed verry confusing with me , and the modem that I have . because its already resolving it . making it even more difficult to catch when its working or not
    so if I understand you right this time, its best fot me to incorporate the netbios for it to work in most senarios ( also with your modem) getting called by the name
    so ill have to incorporate the netbiosunittest object to the current project in place of the dns resolving that I am doing now,? ..
    and the currect appouch of adding the dns resolving etcc is not the best solution/not the solution at all?

    Did a Nmap on the prop and this is wat I get to see,.Looks like the dns working ? or is this not the case still cant find a better way to test
    ffffffffffffff.jpg
    912 x 580 - 120K
  • Mike GMike G Posts: 2,702
    edited 2012-11-20 20:42
    Did a Nmap on the prop and this is wat I get to see,.Looks like the dns working ? or is this not the case still cant find a better way to test
    Your question is beyond my skill level. I have not idea what nmap is showing and II have not idea how the network was setup when nmap was run. There is no way I can even attempt a coherent response. I remember reading about Linux having some smart network configuration that will automatically resolve client names to IPs when issuing DHCP. I'm not sure if that has anything to do with your setup. It does appear your ISP modem can resolve name to IP. Have you looked at the manual?

    I do know - I have a Linksys router and the host name does not resolve. I downloaded nmap and tried to find the host name. It did not work. I ran the NetBIOS demo then nmap found the name. nmap found the name by broadcasting NetBIOS name services. Go figure! The main reason I created NetBIOS name services was because the DHCP host name did not resolve to an IP. I remember being very happy to find a DHCP option for Host Name. I though it would work - I was wrong.
    Did a Nmap on the prop and this is wat I get to see,.Looks like the dns working ? or is this not the case still cant find a better way to test
    How about trying an external address like www.weather.gov.

    You do realize that the WizNet had two different IPs according to post #26 192.168.2.2 was assigned by the ISP modem while 192.168.2.100 was assigned by the Linksys. What was the network configuration when nmap was run in post 29?

    Secondly, I wrote a DNS client - that's all. The client does not register with a DNS server nor does the DHCP object register with a DNS server.
  • Igor_RastIgor_Rast Posts: 357
    edited 2012-11-20 23:15
    Mike G wrote: »

    You do realize that the WizNet had two different IPs according to post #26 192.168.2.2 was assigned by the ISP modem while 192.168.2.100 was assigned by the Linksys. What was the network configuration when nmap was run in post 29?

    .
    I was using the ISP modem with the nmap the 2 different ip is indeed liky you stated 192.168.2.2 for the ISp modem , and 192.168.2.100 was the linksys modem
    ill continue with some more teste in the morning
Sign In or Register to comment.