Click here to Skip to main content
15,902,114 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi,

Could any one please give me C++ structure for IPV6 Header ..
Fields are :
Version : 4 bits
Traffic Class : 8 Bits
Flow Label : 20 Bits
PayLoadLength : 16 Bits
Next Header : 8 Bits
Hop Limit : 8 Bits
Source IPv6 Address : 128 Bits
Destination IPv6 Address : 128 Bits


Regards
Lakkan
Posted
Updated 26-Jan-12 0:41am
v3
Comments
Lakkan 27-Jan-12 4:00am    
which datatype I have to use for to represent 20 Bits.. similarly 128 Bits..
could you plese help me on this..

See here[^] for sample code on using bit fields in C++ structs.
 
Share this answer
 
It never hurts to ask Google: ipv6.c - IP header information[^]
 
Share this answer
 
Comments
Lakkan 27-Jan-12 6:14am    
I Thank you all for your info..
What is, exactly your trouble?
If the posted ones are your exact requirements (there isn't an already defined struct for this, is there?), then the coding is just straightforward:
C++
struct IPV6header
{
  u_int version: 4;
  u_int traffic_class: 8;
  // ... and so on ...
  u_char source_addr[16];
  u_char dest_addr[16];
};
 
Share this answer
 
v2
Comments
Richard MacCutchan 26-Jan-12 7:03am    
I think your bit fields may be in the wrong order ...
CPallini 26-Jan-12 7:14am    
It depends on requirements.
Richard MacCutchan 26-Jan-12 7:19am    
That is true.
which datatype I have to use to represent 20 Bits.. similarly 128 Bits..
could you plese help me on this..
 
Share this answer
 
Comments
Richard MacCutchan 27-Jan-12 4:44am    
Did you look at the link I gave you which showed exactly how to represent bit fields in structures? Did you also check CPallini's answer which shows you how to represent 128 bits (hint: how many bytes is that?).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900