Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- union packet{
- unsigned int a;
- struct {
- unsigned char version : 4;
- unsigned char ihl : 4;
- unsigned char dscp : 6;
- unsigned char ecn : 2;
- unsigned short totallength : 16;
- }ipv4;
- };
- int main() {
- union packet P;
- printf("Enter int value: \n");
- scanf("%d", &P.a);
- printf("Version: %u \n", P.ipv4.version);
- printf("IHL: %u \n", P.ipv4.ihl);
- printf("DSCP: %u \n", P.ipv4.dscp);
- printf("ECN: %u \n", P.ipv4.ecn);
- printf("Total length: %u \n", P.ipv4.totallength);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement