troubleshooting Question

Assertion Fault on CIPAddressCtrl::SetAddress()

Avatar of glenh
glenh asked on
System Programming
3 Comments1 Solution415 ViewsLast Modified:
This may not be exactly the best approach to converting a string to a unsigned long for the SetAddress method but its the best I could come up with due to my lack of knowledge on bit conversions.

For some reason I am getting an assertion fault everytime I call SetAddress() even though it appears my conversion worked just fine.  Here is a copy of the function that does the conversion.  Is there something else I am possibly missing?

unsigned long EQLP_Utilities::strtodw(string ip) {
   unsigned long ipaddress = 0;
   unsigned long lbyte1, lbyte2, lbyte3, lbyte4;
   string sbyte1, sbyte2, sbyte3, sbyte4;
   string combinedip;
   int patternptr = 0;
   int startptr = 0;
   int length = 0;

   patternptr = ip.find('.', startptr);
   sbyte1 = ip.substr(startptr,patternptr);
   lbyte1 = atoi(sbyte1.c_str());
   bitset<8> byte1(lbyte1);
   startptr = patternptr + 1;

   patternptr = ip.find('.', startptr);
   sbyte2 = ip.substr(startptr,patternptr);
   lbyte2 = atoi(sbyte2.c_str());
   bitset<8> byte2(lbyte2);
   startptr = patternptr + 1;

   patternptr = ip.find('.', startptr);
   sbyte3 = ip.substr(startptr,patternptr);
   lbyte3 = atoi(sbyte3.c_str());
   bitset<8> byte3(lbyte3);
   startptr = patternptr + 1;

   patternptr = ip.find('.', startptr);
   sbyte4 = ip.substr(startptr,patternptr);
   lbyte4 = atoi(sbyte4.c_str());
   bitset<8> byte4(lbyte4);

   combinedip.assign(byte1.to_string());
   combinedip.append(byte2.to_string());
   combinedip.append(byte3.to_string());
   combinedip.append(byte4.to_string());
   bitset<32> finalbits(combinedip);
   ipaddress = finalbits.to_ulong();

   return ipaddress;
}
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros