bsocket.inc 857 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. function SA_LEN(const Buf): Cardinal; // Untyped buffer; this is *unsafe*.
  2. begin
  3. Result:=__libc_sa_len(PSockAddr(@Buf)^.sa_family);
  4. end;
  5. function CMSG_DATA(cmsg: Pointer): PByte;
  6. begin
  7. Result:=PByte(Cardinal(cmsg) + SizeOf(Pcmsghdr));
  8. end;
  9. function CMSG_NXTHDR(mhdr: Pmsghdr; cmsg: Pcmsghdr): Pcmsghdr;
  10. begin
  11. Result:=__cmsg_nxthdr(mhdr, cmsg);
  12. end;
  13. function CMSG_FIRSTHDR(mhdr: Pmsghdr): Pcmsghdr;
  14. begin
  15. if mhdr^.msg_controllen >= SizeOf(cmsghdr) then
  16. Result:=mhdr^.msg_control
  17. else
  18. Result:=nil;
  19. end;
  20. function CMSG_ALIGN(len: size_t): size_t;
  21. begin
  22. Result:=(len+SizeOf(size_t)-1) and (not(SizeOf(size_t)-1));
  23. end;
  24. function CMSG_SPACE(len: size_t): size_t;
  25. begin
  26. Result:=CMSG_ALIGN(len)+CMSG_ALIGN(SizeOf(cmsghdr));
  27. end;
  28. function CMSG_LEN(len: size_t): size_t;
  29. begin
  30. Result:=CMSG_ALIGN(SizeOf(cmsghdr))+len;
  31. end;