msg_flags.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include <sys/types.h>
  2. #include <sys/socket.h>
  3. #ifndef MSG_PROBE
  4. #define MSG_PROBE 0x10
  5. #endif
  6. #ifndef MSG_WAITFORONE
  7. #define MSG_WAITFORONE 0x10000
  8. #endif
  9. #ifndef MSG_SENDPAGE_NOTLAST
  10. #define MSG_SENDPAGE_NOTLAST 0x20000
  11. #endif
  12. #ifndef MSG_FASTOPEN
  13. #define MSG_FASTOPEN 0x20000000
  14. #endif
  15. #ifndef MSG_CMSG_CLOEXEC
  16. # define MSG_CMSG_CLOEXEC 0x40000000
  17. #endif
  18. static size_t syscall_arg__scnprintf_msg_flags(char *bf, size_t size,
  19. struct syscall_arg *arg)
  20. {
  21. int printed = 0, flags = arg->val;
  22. if (flags == 0)
  23. return scnprintf(bf, size, "NONE");
  24. #define P_MSG_FLAG(n) \
  25. if (flags & MSG_##n) { \
  26. printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "|" : "", #n); \
  27. flags &= ~MSG_##n; \
  28. }
  29. P_MSG_FLAG(OOB);
  30. P_MSG_FLAG(PEEK);
  31. P_MSG_FLAG(DONTROUTE);
  32. P_MSG_FLAG(CTRUNC);
  33. P_MSG_FLAG(PROBE);
  34. P_MSG_FLAG(TRUNC);
  35. P_MSG_FLAG(DONTWAIT);
  36. P_MSG_FLAG(EOR);
  37. P_MSG_FLAG(WAITALL);
  38. P_MSG_FLAG(FIN);
  39. P_MSG_FLAG(SYN);
  40. P_MSG_FLAG(CONFIRM);
  41. P_MSG_FLAG(RST);
  42. P_MSG_FLAG(ERRQUEUE);
  43. P_MSG_FLAG(NOSIGNAL);
  44. P_MSG_FLAG(MORE);
  45. P_MSG_FLAG(WAITFORONE);
  46. P_MSG_FLAG(SENDPAGE_NOTLAST);
  47. P_MSG_FLAG(FASTOPEN);
  48. P_MSG_FLAG(CMSG_CLOEXEC);
  49. #undef P_MSG_FLAG
  50. if (flags)
  51. printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags);
  52. return printed;
  53. }
  54. #define SCA_MSG_FLAGS syscall_arg__scnprintf_msg_flags