msg_flags.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // SPDX-License-Identifier: LGPL-2.1
  2. #include <sys/types.h>
  3. #include <sys/socket.h>
  4. #ifndef MSG_PROBE
  5. #define MSG_PROBE 0x10
  6. #endif
  7. #ifndef MSG_WAITFORONE
  8. #define MSG_WAITFORONE 0x10000
  9. #endif
  10. #ifndef MSG_BATCH
  11. #define MSG_BATCH 0x40000
  12. #endif
  13. #ifndef MSG_SOCK_DEVMEM
  14. #define MSG_SOCK_DEVMEM 0x2000000
  15. #endif
  16. #ifndef MSG_ZEROCOPY
  17. #define MSG_ZEROCOPY 0x4000000
  18. #endif
  19. #ifndef MSG_SPLICE_PAGES
  20. #define MSG_SPLICE_PAGES 0x8000000
  21. #endif
  22. #ifndef MSG_FASTOPEN
  23. #define MSG_FASTOPEN 0x20000000
  24. #endif
  25. #ifndef MSG_CMSG_CLOEXEC
  26. # define MSG_CMSG_CLOEXEC 0x40000000
  27. #endif
  28. static size_t syscall_arg__scnprintf_msg_flags(char *bf, size_t size,
  29. struct syscall_arg *arg)
  30. {
  31. bool show_prefix = arg->show_string_prefix;
  32. const char *prefix = "MSG_";
  33. int printed = 0, flags = arg->val;
  34. if (flags == 0)
  35. return scnprintf(bf, size, "NONE");
  36. #define P_MSG_FLAG(n) \
  37. if (flags & MSG_##n) { \
  38. printed += scnprintf(bf + printed, size - printed, "%s%s%s", printed ? "|" : "", show_prefix ? prefix : "", #n); \
  39. flags &= ~MSG_##n; \
  40. }
  41. P_MSG_FLAG(OOB);
  42. P_MSG_FLAG(PEEK);
  43. P_MSG_FLAG(DONTROUTE);
  44. P_MSG_FLAG(CTRUNC);
  45. P_MSG_FLAG(PROBE);
  46. P_MSG_FLAG(TRUNC);
  47. P_MSG_FLAG(DONTWAIT);
  48. P_MSG_FLAG(EOR);
  49. P_MSG_FLAG(WAITALL);
  50. P_MSG_FLAG(FIN);
  51. P_MSG_FLAG(SYN);
  52. P_MSG_FLAG(CONFIRM);
  53. P_MSG_FLAG(RST);
  54. P_MSG_FLAG(ERRQUEUE);
  55. P_MSG_FLAG(NOSIGNAL);
  56. P_MSG_FLAG(MORE);
  57. P_MSG_FLAG(WAITFORONE);
  58. P_MSG_FLAG(BATCH);
  59. P_MSG_FLAG(SOCK_DEVMEM);
  60. P_MSG_FLAG(ZEROCOPY);
  61. P_MSG_FLAG(SPLICE_PAGES);
  62. P_MSG_FLAG(FASTOPEN);
  63. P_MSG_FLAG(CMSG_CLOEXEC);
  64. #undef P_MSG_FLAG
  65. if (flags)
  66. printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags);
  67. return printed;
  68. }
  69. #define SCA_MSG_FLAGS syscall_arg__scnprintf_msg_flags