GetSockOptSocket handles linux getsockopt(2) when level is SOL_SOCKET.
(t *kernel.Task, s socket.Socket, ep commonEndpoint, family int, _ linux.SockType, name, outLen int)
| 993 | |
| 994 | // GetSockOptSocket handles linux getsockopt(2) when level is SOL_SOCKET. |
| 995 | func GetSockOptSocket(t *kernel.Task, s socket.Socket, ep commonEndpoint, family int, _ linux.SockType, name, outLen int) (marshal.Marshallable, *syserr.Error) { |
| 996 | // TODO(b/124056281): Stop rejecting short optLen values in getsockopt. |
| 997 | switch name { |
| 998 | case linux.SO_ERROR: |
| 999 | if outLen < sizeOfInt32 { |
| 1000 | return nil, syserr.ErrInvalidArgument |
| 1001 | } |
| 1002 | |
| 1003 | // Get the last error and convert it. |
| 1004 | err := ep.SocketOptions().GetLastError() |
| 1005 | if err == nil { |
| 1006 | optP := primitive.Int32(0) |
| 1007 | return &optP, nil |
| 1008 | } |
| 1009 | |
| 1010 | optP := primitive.Int32(syserr.TranslateNetstackError(err).ToLinux()) |
| 1011 | return &optP, nil |
| 1012 | |
| 1013 | case linux.SO_PEERCRED: |
| 1014 | if family != linux.AF_UNIX || outLen < unix.SizeofUcred { |
| 1015 | return nil, syserr.ErrInvalidArgument |
| 1016 | } |
| 1017 | return s.GetPeerCreds(t) |
| 1018 | |
| 1019 | case linux.SO_PASSCRED: |
| 1020 | if outLen < sizeOfInt32 { |
| 1021 | return nil, syserr.ErrInvalidArgument |
| 1022 | } |
| 1023 | |
| 1024 | v := primitive.Int32(boolToInt32(ep.SocketOptions().GetPassCred())) |
| 1025 | return &v, nil |
| 1026 | |
| 1027 | case linux.SO_SNDBUF: |
| 1028 | if outLen < sizeOfInt32 { |
| 1029 | return nil, syserr.ErrInvalidArgument |
| 1030 | } |
| 1031 | |
| 1032 | size := ep.SocketOptions().GetSendBufferSize() |
| 1033 | |
| 1034 | if size > math.MaxInt32 { |
| 1035 | size = math.MaxInt32 |
| 1036 | } |
| 1037 | |
| 1038 | sizeP := primitive.Int32(size) |
| 1039 | return &sizeP, nil |
| 1040 | |
| 1041 | case linux.SO_RCVBUF: |
| 1042 | if outLen < sizeOfInt32 { |
| 1043 | return nil, syserr.ErrInvalidArgument |
| 1044 | } |
| 1045 | |
| 1046 | size := ep.SocketOptions().GetReceiveBufferSize() |
| 1047 | |
| 1048 | if size > math.MaxInt32 { |
| 1049 | size = math.MaxInt32 |
| 1050 | } |
| 1051 | |
| 1052 | sizeP := primitive.Int32(size) |
no test coverage detected
searching dependent graphs…