Thread: What Does #define IP_RF 0x8000 Mean? - CodeGuru Forums

CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
CodeGuru Forums - A Developer.com Community for C++, C#, VB, Java and .NET Solutions
  • Register
  • Help
  • Remember Me?
  • Advanced Search
  • Home
  • Forum
  • Visual C++ & C++ Programming
  • C++ (Non Visual C++ Issues)
  • What does #define IP_RF 0x8000 mean?
Results 1 to 6 of 6 Thread: What does #define IP_RF 0x8000 mean?
  • Thread Tools
    • Show Printable Version
  • Display
    • Linear Mode
    • Switch to Hybrid Mode
    • Switch to Threaded Mode
  1. December 6th, 2007, 07:47 PM #1 vr84
    • View Profile
    • View Forum Posts
    vr84 is offline 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 Reply With Quote
  2. December 6th, 2007, 09:07 PM #2 g3RC4n
    • View Profile
    • View Forum Posts
    g3RC4n is offline Member Join Date Jul 2007 Location london Posts 247

    Re: What does #define IP_RF 0x8000 mean?

    Quote 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 Reply With Quote
  3. December 6th, 2007, 09:51 PM #3 vr84
    • View Profile
    • View Forum Posts
    vr84 is offline 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 Reply With Quote
  4. December 7th, 2007, 01:32 AM #4 Paul McKenzie
    • View Profile
    • View Forum Posts
    Paul McKenzie is offline Elite Member Power Poster Join Date Apr 1999 Posts 27,449

    Re: What does #define IP_RF 0x8000 mean?

    Quote 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 Reply With Quote
  5. December 7th, 2007, 02:26 AM #5 cilu's Avatar cilu
    • View Profile
    • View Forum Posts
    • Visit Homepage
    cilu is offline 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 Reply With Quote
  6. December 7th, 2007, 05:11 PM #6 vr84
    • View Profile
    • View Forum Posts
    vr84 is offline 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 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
    1. Visual C++ Programming
    2. Visual C++ FAQs
    3. C++ (Non Visual C++ Issues)
    4. C++ and WinAPI
    5. Managed C++ and C++/CLI
    6. Visual C++ Bugs & Fixes
    7. Xamarin
    8. Graphics Programming
    9. Multithreading
    10. Network Programming
    11. Driver Development
  • C# Programming
    1. C-Sharp Programming
  • Visual Basic Programming
    1. Visual Basic 6.0 Programming
    2. Visual Basic .NET
    3. VBForums
  • Windows 8 and Later Store Development
    1. Modern Windows Apps (Metro)
  • Other .NET Programming
    1. ASP.NET
    2. .NET Framework
      1. .NET Installation and Configuration Issues
    3. ADO.NET
    4. Windows Presentation Foundation (WPF) & XAML forum
  • Java Programming
    1. Java Programming
  • Other Programming
    1. AJAX
    2. Scripting - Client Side
    3. Crystal Reports
    4. Database
    5. XML
    6. Wireless/Mobile Development
    7. Assembly
    8. Scripting - Server Side (PHP, Perl, etc.)
    9. SharePoint
    10. Python
      1. Python Articles
  • General Discussion
    1. General Developer Topics
    2. Project Planning, Design, and Management
    3. Testers and Testing
    4. Algorithms & Data Structures
    5. IoT, IoE, and Maker Forum (on VBForums)
    6. General Discussion / Chit Chat
    7. Announcements, Press Releases, & News
  • CodeGuru Community
    1. Feedback
    2. Articles Suggestions / Requests
    3. Programming Projects
      1. Game Engine Project
      2. C# Game(s) Project
      3. C++ Coding Project
      4. Project: Code War
    4. Testing Area
  • Slow Chat Archives
    1. eCamp Chat: Windows 8 for Developers
    2. Slow Chat: Talk with Microsoft Developer Teams
    3. Slow Chat: Developing Multithreaded Applications
    4. Slow Chat: C++0x
    5. Slow Chat: Visual C++: Yesterday, Today, and Tomorrow
  • Jobs
    1. Looking for Work
    2. Open Positions (Jobs)
  • CodeGuru Technical FAQs
    1. C++ FAQs
    2. STL FAQs
    3. Windows SDK FAQs
    4. Visual C++ FAQs
    5. MFC FAQs
    6. ATL FAQs
    7. .NET Framework (non-language specific) FAQs
    8. C# FAQs
    9. Visual Basic .NET FAQs
    10. Visual Basic FAQs
    11. CodeGuru Individual FAQs
    12. CodeGuru Individual Visual Basic FAQs
  • Retired Forum Areas
    1. Silverlight
    2. Directory Services
    3. General Windows and DNA Programming
    4. 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!
Terms of Service | About Us | Privacy Notice | Contact Us | Advertise | Sitemap| California - Do Not Sell My Info

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.

All times are GMT -5. The time now is 09:52 PM. Copyright TechnologyAdvice

Từ khóa » C 0x8000