- Forum
- Visual C++ & C++ Programming
- C++ (Non Visual C++ Issues)
- What does #define IP_RF 0x8000 mean?
- If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register or Login before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.
Results 1 to 6 of 6 Thread: What does #define IP_RF 0x8000 mean? - December 6th, 2007, 07:47 PM #1 vr84
- View Profile
- View Forum Posts
Member Join Date Jul 2007 Posts 40 What does #define IP_RF 0x8000 mean? What does the line with #define IP_RF 0x8000 do? What does the colon in the line with u_int ip_hl:4 do? Code: /* IP header */ struct sniff_ip { #if BYTE_ORDER == LITTLE_ENDIAN u_int ip_hl:4, /* header length */ ip_v:4; /* version */ #if BYTE_ORDER == BIG_ENDIAN u_int ip_v:4, /* version */ ip_hl:4; /* header length */ #endif #endif /* not _IP_VHL */ u_char ip_tos; /* type of service */ u_short ip_len; /* total length */ u_short ip_id; /* identification */ u_short ip_off; /* fragment offset field */ #define IP_RF 0x8000 /* reserved fragment flag */ #define IP_DF 0x4000 /* dont fragment flag */ #define IP_MF 0x2000 /* more fragments flag */ #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */ u_char ip_ttl; /* time to live */ u_char ip_p; /* protocol */ u_short ip_sum; /* checksum */ struct in_addr ip_src,ip_dst; /* source and dest address */ }; Reply With Quote - December 6th, 2007, 09:07 PM #2 g3RC4n
- View Profile
- View Forum Posts
Member Join Date Jul 2007 Location london Posts 247 Re: What does #define IP_RF 0x8000 mean? Originally Posted by vr84 What does the line with #define IP_RF 0x8000 do? What does the colon in the line with u_int ip_hl:4 do? Code: /* IP header */ struct sniff_ip { #if BYTE_ORDER == LITTLE_ENDIAN u_int ip_hl:4, /* header length */ ip_v:4; /* version */ #if BYTE_ORDER == BIG_ENDIAN u_int ip_v:4, /* version */ ip_hl:4; /* header length */ #endif #endif /* not _IP_VHL */ u_char ip_tos; /* type of service */ u_short ip_len; /* total length */ u_short ip_id; /* identification */ u_short ip_off; /* fragment offset field */ #define IP_RF 0x8000 /* reserved fragment flag */ #define IP_DF 0x4000 /* dont fragment flag */ #define IP_MF 0x2000 /* more fragments flag */ #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */ u_char ip_ttl; /* time to live */ u_char ip_p; /* protocol */ u_short ip_sum; /* checksum */ struct in_addr ip_src,ip_dst; /* source and dest address */ }; #define IP_RF 0x8000 is a way of representing an int as an index ie Code: #define _ON_ 0 #define _OFF_ 1 int var; var = _ON_; if(var = _ON_){ var = _OFF_; } the 0x8000 means hexdecimal, so i could of said Code: #define _ON_ 0x0000 #define _OFF_ 0x0001 it's a way of indexing values u_int ip_hl:4 means Code: typedef unsigned int u_int; u_int being shorthand for "unsigned int" ip_hl:4, as in the ":4" part means that the int is to use 4 bits, in structs you canspeify the number of bits for it to use, this is pretty advanced stuff about saving space, i've never had to use it though Last edited by g3RC4n; December 6th, 2007 at 09:13 PM. Reply With Quote - December 6th, 2007, 09:51 PM #3 vr84
- View Profile
- View Forum Posts
Member Join Date Jul 2007 Posts 40 Re: What does #define IP_RF 0x8000 mean? Thanks for the help, I understand it now. Just wondering why hex was used instead of a number? (#define IP_RF 32768) Last edited by vr84; December 6th, 2007 at 10:04 PM. Reason: follow up question Reply With Quote - December 7th, 2007, 01:32 AM #4 Paul McKenzie
- View Profile
- View Forum Posts
Elite Member Power Poster Join Date Apr 1999 Posts 27,449 Re: What does #define IP_RF 0x8000 mean? Originally Posted by vr84 Thanks for the help, I understand it now. Just wondering why hex was used instead of a number? (#define IP_RF 32768) Hex is a number. It is a number represented in base 16, and is used to "visualize" the set of bits or series of contiguous bits in a number much more than the equivalent decimal number. It is used, since binary cannot be placed in a #define, and base 16 is a shorthand way of representing binary numbers by grouping the binary numbers in groups of 4. For example 0x0402 is "0000 0100 0000 0010" in binary. Imagine a panel of 16 switches, and you want the 9th and 10th switches (starting from the right) on. Quick, what number is that in decimal? OK, now what number is that in binary: 0000 0110 0000 0000 = 0x0600 in hex. In decimal this is 1536. Putting 1536 in the #define is not intuitive for someone reading the code, as it hides visual information as to what "1536" stands for. Placing 0x0600 conveys more visual information as to the number and purpose of that number "OK, they're setting the 9th and 10th bits on". It is just more convenient and easier to specify hexadecimal values for things like this. Regards, Paul McKenzie Reply With Quote - December 7th, 2007, 02:26 AM #5 cilu
- View Profile
- View Forum Posts
- Visit Homepage
Elite Member Power Poster Join Date Oct 2002 Location Timisoara, Romania Posts 14,360 Re: What does #define IP_RF 0x8000 mean? Perhaps you should get a good C++ book: http://www.codeguru.com/forum/showthread.php?t=231039. Marius Bancila Home Page My CodeGuru articles I do not offer technical support via PM or e-mail. Please use vbBulletin codes. Reply With Quote - December 7th, 2007, 05:11 PM #6 vr84
- View Profile
- View Forum Posts
Member Join Date Jul 2007 Posts 40 Re: What does #define IP_RF 0x8000 mean? Thanks for the detailed answer Paul, it makes sense to me now. Reply With Quote Quick Navigation C++ (Non Visual C++ Issues) Top - Site Areas
- Settings
- Private Messages
- Subscriptions
- Who's Online
- Search Forums
- Forums Home
- Forums
- Visual C++ & C++ Programming
- Visual C++ Programming
- Visual C++ FAQs
- C++ (Non Visual C++ Issues)
- C++ and WinAPI
- Managed C++ and C++/CLI
- Visual C++ Bugs & Fixes
- Xamarin
- Graphics Programming
- Multithreading
- Network Programming
- Driver Development
- C# Programming
- C-Sharp Programming
- Visual Basic Programming
- Visual Basic 6.0 Programming
- Visual Basic .NET
- VBForums
- Windows 8 and Later Store Development
- Modern Windows Apps (Metro)
- Other .NET Programming
- ASP.NET
- .NET Framework
- .NET Installation and Configuration Issues
- ADO.NET
- Windows Presentation Foundation (WPF) & XAML forum
- Java Programming
- Java Programming
- Other Programming
- AJAX
- Scripting - Client Side
- Crystal Reports
- Database
- XML
- Wireless/Mobile Development
- Assembly
- Scripting - Server Side (PHP, Perl, etc.)
- SharePoint
- Python
- Python Articles
- General Discussion
- General Developer Topics
- Project Planning, Design, and Management
- Testers and Testing
- Algorithms & Data Structures
- IoT, IoE, and Maker Forum (on VBForums)
- General Discussion / Chit Chat
- Announcements, Press Releases, & News
- CodeGuru Community
- Feedback
- Articles Suggestions / Requests
- Programming Projects
- Game Engine Project
- C# Game(s) Project
- C++ Coding Project
- Project: Code War
- Testing Area
- Slow Chat Archives
- eCamp Chat: Windows 8 for Developers
- Slow Chat: Talk with Microsoft Developer Teams
- Slow Chat: Developing Multithreaded Applications
- Slow Chat: C++0x
- Slow Chat: Visual C++: Yesterday, Today, and Tomorrow
- Jobs
- Looking for Work
- Open Positions (Jobs)
- CodeGuru Technical FAQs
- C++ FAQs
- STL FAQs
- Windows SDK FAQs
- Visual C++ FAQs
- MFC FAQs
- ATL FAQs
- .NET Framework (non-language specific) FAQs
- C# FAQs
- Visual Basic .NET FAQs
- Visual Basic FAQs
- CodeGuru Individual FAQs
- CodeGuru Individual Visual Basic FAQs
- Retired Forum Areas
- Silverlight
- Directory Services
- General Windows and DNA Programming
- Windows OS Issues
« Previous Thread | Next Thread » Posting Permissions - You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
- BB code is On
- Smilies are On
- [IMG] code is On
- [VIDEO] code is On
- HTML code is Off
Forum Rules -- Blue Codeguru -- Default Mobile Style ---- Child of Default Mobile Style | Click Here to Expand Forum to Full Width Featured * The Best Reasons to Target Windows 8 Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform. - * Porting from Android to Windows 8: The Real Story Do you have an Android application? How hard would it really be to port to Windows 8?
- * Guide to Porting Android Applications to Windows 8 If you've already built for Android, learn what do you really need to know to port your application to Windows Phone 8.
- * HTML5 Development Center Our portal for articles, videos, and news on HTML5, CSS3, and JavaScript
- * Windows App Gallery See the Windows 8.x apps we've spotlighted or submit your own app to the gallery!
|