<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>IP address -- std::string to hex - C++ - tribe.net</title>
    <link>http://cpp.tribe.net/thread/41bcbe21-4068-482f-805a-cdafba54ac3e?format=rss</link>
    <description>Tribe.net. Local Connections</description>
    <item>
      <title>Re: IP address -- std::string to hex</title>
      <link>http://CPP.tribe.net/thread/41bcbe21-4068-482f-805a-cdafba54ac3e#1f619a21-67ba-4946-926d-c146195c6802</link>
      <description>Hypno,&#xD;
&#xD;
I did it exactly this way -- by using the socket functions to do it (the C++ is gcc 4.0 on Mac OSX 10.4.5).  I just wanted to know how others would do it.  The sscanf() way I didn't think of, and aside from it being vulnerable to buffer overruns, it beats my code hands down in the least amount of lines (and perhaps the most efficient in terms of CPU cycles) dept.&#xD;
&#xD;
Yes, ethereal has capture filters, but I didn't read up on how to make one ... besides, I get to code in C++ precious little these days (I work in a mostly Perl shop, despite C++ being my favorite (and most experienced by _far_) language -- Perl is ok, but it's no C++).  I recently got to code a small command-line tool that communicated over MIDI to a graphic equalizer (the platform was Win32, so I used the Win32 MIDI APIs to do it).  It was fun, but it only took a couple of days, and then ... back to Perl.&#xD;
&#xD;
Regards,&#xD;
&#xD;
John&#xD;
&#xD;
Falling You - exploring the beauty of voice and sound&#xD;
http://www.fallingyou.com</description>
      <pubDate>Tue, 28 Feb 2006 04:19:43 GMT</pubDate>
      <guid isPermaLink="false">http://CPP.tribe.net/thread/41bcbe21-4068-482f-805a-cdafba54ac3e#1f619a21-67ba-4946-926d-c146195c6802</guid>
      <dc:creator>John Michael</dc:creator>
      <dc:date>2006-02-28T04:19:43Z</dc:date>
    </item>
    <item>
      <title>Re: IP address -- std::string to hex</title>
      <link>http://CPP.tribe.net/thread/41bcbe21-4068-482f-805a-cdafba54ac3e#ecd11d4e-7368-4ab4-a2f1-4e8cfe0992d0</link>
      <description>1.  Instead of writing a function, why not use a standard one like:&#xD;
 inet_aton (const char *name, struct in_addr *addr)&#xD;
to convert it?  Whatever C/C++ you're using must have one.&#xD;
2.  Why store it in a char array?  None of the standard functions will support it that way and you'll need to do a cast.&#xD;
&#xD;
You should stick to the standard functions not only for simplicity but for portability.  They account for endian differences.  Standard calls like  ntohl() network-to-host-long, htonl() host-to-network-long  convert values from the host machine's endian to network endian byte order.&#xD;
&#xD;
Doesn't Ethereal's built in filter handle what you need?  I always found it best to capture everything and then use it''s filter on the output.  Also, isolating as much traffic to begin with by putting it on a separate wire or hub really helps.</description>
      <pubDate>Tue, 28 Feb 2006 04:09:46 GMT</pubDate>
      <guid isPermaLink="false">http://CPP.tribe.net/thread/41bcbe21-4068-482f-805a-cdafba54ac3e#ecd11d4e-7368-4ab4-a2f1-4e8cfe0992d0</guid>
      <dc:creator>Hypno</dc:creator>
      <dc:date>2006-02-28T04:09:46Z</dc:date>
    </item>
    <item>
      <title>Re: IP address -- std::string to hex</title>
      <link>http://CPP.tribe.net/thread/41bcbe21-4068-482f-805a-cdafba54ac3e#3f4ace6b-e7c9-4c87-9fd8-efab0d0c6c33</link>
      <description>nice and concise :)&#xD;
&#xD;
If the ip addess is not verified to be good however this code can overflow the buffer since sscanf will happily put much larger values than 255 into the int variables and sprintf will happily transfer the bytes into the target memory location without bounds checking.</description>
      <pubDate>Tue, 28 Feb 2006 04:05:26 GMT</pubDate>
      <guid isPermaLink="false">http://CPP.tribe.net/thread/41bcbe21-4068-482f-805a-cdafba54ac3e#3f4ace6b-e7c9-4c87-9fd8-efab0d0c6c33</guid>
      <dc:creator>Jason</dc:creator>
      <dc:date>2006-02-28T04:05:26Z</dc:date>
    </item>
    <item>
      <title>Re: IP address -- std::string to hex</title>
      <link>http://CPP.tribe.net/thread/41bcbe21-4068-482f-805a-cdafba54ac3e#780cddcf-354f-47bd-ac5a-9df842380988</link>
      <description>char ipString[] = "222.100.1.32";&#xD;
	char hexString[9];&#xD;
	int a,b,c,d;&#xD;
&#xD;
	sscanf(ipString, "%d.%d.%d.%d", &amp;amp;a, &amp;amp;b, &amp;amp;c, &amp;amp;d ); &#xD;
	sprintf( hexString, "%02X%02X%02X%02X", a, b, c, d );&#xD;
&#xD;
&#xD;
You can do it in two lines of ANSI C.  Remove the "02" if you do not need the zero placeholder if the integer value is 15 or less.  Use lower case letter "x" if you need the hex to contain lowercase hex letters (a through f).</description>
      <pubDate>Tue, 28 Feb 2006 03:19:41 GMT</pubDate>
      <guid isPermaLink="false">http://CPP.tribe.net/thread/41bcbe21-4068-482f-805a-cdafba54ac3e#780cddcf-354f-47bd-ac5a-9df842380988</guid>
      <dc:creator>Jon</dc:creator>
      <dc:date>2006-02-28T03:19:41Z</dc:date>
    </item>
    <item>
      <title>IP address -- std::string to hex</title>
      <link>http://CPP.tribe.net/thread/41bcbe21-4068-482f-805a-cdafba54ac3e#9f339874-03f2-4613-ae68-f164745b694a</link>
      <description>Hello, all ...&#xD;
&#xD;
I'm wondering what the best / least # of lines way in C++ (so it's ok to use C++-isms like iostream, fstream, string, etc.) is to convert an IP address in dotted format (stored in a std::string) to an IP address in hex (stored in an array of chars)?&#xD;
&#xD;
No, this is not a homework question -- i'm just in the middle of writing something like this (to search an ethereal dump file for RTP packets coming from a certain address) and want to know how _you_ would do it :-)&#xD;
&#xD;
Regards,&#xD;
&#xD;
John&#xD;
&#xD;
Faling You - exploring the beauty of voice and sound&#xD;
http://www.fallingyou.com</description>
      <pubDate>Tue, 28 Feb 2006 00:52:48 GMT</pubDate>
      <guid isPermaLink="false">http://CPP.tribe.net/thread/41bcbe21-4068-482f-805a-cdafba54ac3e#9f339874-03f2-4613-ae68-f164745b694a</guid>
      <dc:creator>John Michael</dc:creator>
      <dc:date>2006-02-28T00:52:48Z</dc:date>
    </item>
  </channel>
</rss>



