Announcement

Collapse
No announcement yet.

Having Trouble Configuring IP Settings

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Having Trouble Configuring IP Settings

    I've been having trouble getting a sequence to work that writes new IP settings to the XPort.

    I based it on the sample code that is in several of the sample C files. However, the final function call is returning an error.

    Here is the relevant code:

    Code:
    // XML fragment to hold IP address and default gateway address
    static char xmlIPConfig[] =
        "<?xml version=\"1.0\" standalone=\"yes\"?>"
            "<configrecord version=\"0.1.0.0T0\">"
                "<configgroup name = \"interface\" instance = \"eth0\">"
                   "<configitem name = \"ip address\">"
                       "<value>%s</value>"
                   "</configitem>"
                   "<configitem name = \"default gateway\">"
                       "<value>%s</value>"
                   "</configitem>";
    
    struct xml_read_value_specification xmlReadValueSpec;
    struct input_stream_with_const_char_ptr bufferStream;
    
            snprintf(xmlBuffer, MAX_LEN_XML_BUFFER, xmlIPConfig, dbIP, dbGateway);
            // Init stream with the XML fragment
            if (!StreamInitWithConstCharPtr(&bufferStream, xmlBuffer))
            {
                result = -1;
                return result;
            }
            // Activate the settings in the fragment
            if (!XMLImportFromStream(&bufferStream.inStream, TLogWriteMessage, NULL))
            {
                result = -2;
                return result;
            }
    ("dbIP" and "dbGateway" are the IP address and Default Gateway in string format.)

    Anyhow, it is the XMLImportFromStream function that is failing.

    Does anyone have any idea why?

  • #2
    Hello out there experts. Please reply. I did gather some more information. I got the actual error message generated by the "XMLImportFromStream" function. It is
    ERROR: Failed XML input parsing
    So, I would suspect that the formatting of the XML fragment that I created is wrong in some way. I've gone through it and compared it to the others in the sample code. I can't see anything wrong. I included it in the previous posting. please take a look at it and see if you can make out what is wrong.

    Thanks.
    - Bob

    Comment


    • #3
      Is this a snippet, or the actual complete string in your code:

      static char xmlIPConfig[] =
      "<?xml version=\"1.0\" standalone=\"yes\"?>"
      "<configrecord version=\"0.1.0.0T0\">"
      "<configgroup name = \"interface\" instance = \"eth0\">"
      "<configitem name = \"ip address\">"
      "<value>%s</value>"
      "</configitem>"
      "<configitem name = \"default gateway\">"
      "<value>%s</value>"
      "</configitem>";
      If this is the string you're using, you need to close the document with a </configgroup> and </configrecord>
      Erick Liska
      Lantronix Inc.

      Comment


      • #4
        You're absolutely right. I can't believe how much I looked at that fragment and missed that. However, even after including those closing delimiters it didn't work. I'm still getting the same parsing error.

        Just as a test I substituted literal values in the fragment, as shown here:
        Code:
        char xmlIPConfig[] =
            "<?xml version=\"1.0\" standalone=\"yes\"?>"
                "<configrecord version=\"0.1.0.0T0\">"
                    "<configgroup name=\"interface\" instance=\"eth0\">"
                       "<configitem name=\"ip address\">"
                           "<value>192.168.0.2/24</value>"
                       "</configitem>"
                       "<configitem name=\"default gateway\">"
                           "<value>192.168.0.3</value>"
                       "</configitem>"
           	"</configgroup>"
                "</configrecord>"
                ;
        
            char xmlBuffer[MAX_LEN_XML_BUFFER];
            snprintf(xmlBuffer, MAX_LEN_XML_BUFFER, xmlIPConfig, dbIP, dbGateway);
        This works.

        But this doesn't:
        Code:
            // XML fragment to hold IP address and default gateway address
            static char xmlIPConfig[] =
                "<?xml version=\"1.0\" standalone=\"yes\"?>"
                    "<configrecord version=\"0.1.0.0T0\">"
                        "<configgroup name=\"interface\" instance=\"eth0\">"
                           "<configitem name=\"ip address\">"
                               "<value>%s</value>"
                           "</configitem>"
                           "<configitem name=\"default gateway\">"
                               "<value>%s</value>"
                           "</configitem>"
               	   "</configgroup>"
        	"</configrecord>"
                ;
        
            char dbIP[19];          // M3 db IP address as a string
            char dbGateway[16];     // M3 db Gateway Address as a string
            char xmlBuffer[MAX_LEN_XML_BUFFER];
        
            snprintf(xmlBuffer, MAX_LEN_XML_BUFFER, xmlIPConfig, dbIP, dbGateway);
        I've printed out the values (dbIP and dbGateway) that I am loading into the xmlBuffer and they look fine on the screen. So I don't know what is causing the function to get heartburn.

        Comment


        • #5
          Have you looked at the actual formatted string xmlBuffer after the snprintf() call?
          Erick Liska
          Lantronix Inc.

          Comment


          • #6
            Allocating with sprintf

            It is possible that your MAX_LEN_XML_BUFFER is not large enough.

            You can avoid all of that by using sprintf_malloc() instead. Just make sure to call Free() afterwards.

            Comment


            • #7
              I decided to completely eliminate the intermediate buffer and just use the constant array. I am still getting a parsing failure. I tried to print out the string to the web page using "httpWriteData" because my serial port is already being used to talk to a host device. Nothing shows up on the page. I'm not sue why that is. When I tried to print out the contents of the intermediate buffer, and I was actually loading some variables into it (the IP address and gateway adress) those would get printed, but nothing else.

              As I said previously, I got it to work one time, when I loaded the values directly instead of trying to copy the variables into the xmlBuffer via the snprintf function. It successfuly loaded the new IP address and gateway address, but that caused the device to enable DHCP when it was rebooted. That caused me a lot of grief while I got it back into a fixed IP mode. Apparently DHCP must be specifically disabled when loading a new IP address and/or a default gateway. So I added configitems for bootp and dhcp to disable them. It has given me parsing errors ever since, even when using the xml fragment directly (not depending on snprintf to load the values into xmlBuffer).

              If it makes any difference, all of this is taking place in a task that I create just for this purpose. It does the folowing:
              - Wait for the host to send valid IP settings to it via the serial port
              - Compare these settings with the internal IP settings on the XPort
              - Write the new settings if they differ
              - Reboot the XPort

              I have the reboot disabled for now, until I am sure the rest works.

              Any ideas?

              Comment


              • #8
                XML defaults

                For any XML configgroup that your XML contains, any configitems or values missing from that configgroup will be set to their default values.

                The default for dhcp is "enabled", so when you leave dhcp out when importing the "interface" configgroup, you will be enabling dhcp.

                You sent us a copy of what worked one time. You must experiment to discover what you are doing differently now.

                Comment


                • #9
                  I have been experimenting for the last four days. I was hoping that you could take the XML fragment and function calls that I sent and try them on a unit in your lab. Since I cannot push things out to the serial port, writing them to the web page is my only way of seeing what is going on. For some reason I am seeing nothing when I try to print out the actual XML fragment string, either from the constant array or the one that gets filled with the IP address and gateway values via the snprintf call. That would be very valuable. Why won't the HttpWriteData function cause the entire string to appear on the web page?

                  I plan on going back to the fragment that worked, though it causes the device to default to DHCP "On", and work forward from there. If you have any other insights or suggestions, please let me know.

                  Comment


                  • #10
                    Bob - you mentioned that you couldn't send anything out the serial port for debugging. I thought I'd quickly mention that you can use the TLOG functionality in your code and have the output go to a syslog server. This is of course in addition to using the "auto show tlog" command from a telnet session (see the device level). Also the web server will show you the current tlog window at the /tlog url.

                    mattmc

                    Comment


                    • #11
                      Just to bring this to a conclusion, I finally got the configuration to work. I found one problem in the code that built the IP address up (it added a second period between the first two sets of numbers). I never did figure out what the problem was with the BootP and DHCP configurations though. I added them back in to the XML fragment after getting the IP Address and Gateway Address working, and then it all worked.

                      This isnt the most satisfying explanation, but sometimes that's how things work out.

                      On to the next problem - er - opportunity!

                      By the way, thanks Matt for the heads-up about being able to view the tlog via the web server. That helps a lot.

                      Comment


                      • #12
                        Where you have written this part of code. in s2e file or somewhere else. i want to hold an default ip for 1 min then it should get switch to the configured ip.any idea how to implement it?

                        Comment

                        Working...
                        X