Advertisement
teknoraver

scalar_storage_order

Jul 9th, 2024 (edited)
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.46 KB | None | 0 0
  1. #include <stdint.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. #define __sso_be __attribute__((scalar_storage_order("big-endian")))
  6.  
  7. struct __sso_be ipv6hdr {
  8. uint32_t
  9.     version:4,
  10.     tos:8,
  11.     flow_lbl:20;
  12. };
  13.  
  14. int main()
  15. {
  16.     struct ipv6hdr hdr;
  17.  
  18.     memcpy(&hdr, "\x60\x01\x23\x45", 4);
  19.  
  20.     printf("size:   %ld\n\n", sizeof(hdr));
  21.  
  22.     printf("version:    %x\n", hdr.version);
  23.     printf("tos:        %x\n", hdr.tos);
  24.     printf("flow_lbl:   %x\n\n", hdr.flow_lbl);
  25.  
  26.     return 0;
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement