Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re: getsockopt: incorrect return values #3491

Closed
vicuna opened this issue Jul 31, 2002 · 1 comment
Closed

Re: getsockopt: incorrect return values #3491

vicuna opened this issue Jul 31, 2002 · 1 comment
Labels

Comments

@vicuna
Copy link

vicuna commented Jul 31, 2002

Original bug ID: 1283
Reporter: administrator
Status: closed
Resolution: not a bug
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

Sorry -- forgot to say that I'm running Ocaml 3.04 on FreeBSD v4.6.

Thanks,
Steve

On Wed, 2002-07-31 at 13:30, Steven Bishop wrote:

Hi,

The following program terminates producing an incorrect result of !SO_KEEPALIVE
but will terminate correctly if the 'if ...' is modified to 'if (getsockopt sd
SO_KEEPALIVE)':


open Unix;;

exception Fatal of string;;

let sd =
try socket PF_INET SOCK_STREAM 6
with Unix_error(e,s1,s2) ->
raise(Fatal("Error:"^(error_message(e))^s1^s2))
in
let opt = setsockopt sd SO_KEEPALIVE true
in
if (getsockopt sd SO_KEEPALIVE) = true
then print_endline("SO_KEEPALIVE")
else print_endline("!SO_KEEPALIVE");;

Here is an strace of the running program:


socket(PF_INET, SOCK_STREAM, IPPROTO_TCP) = 3
setsockopt(3, SOL_SOCKET, SO_KEEPALIVE, [1], 4) = 0
getsockopt(3, SOL_SOCKET, SO_KEEPALIVE, [8], [4]) = 0
write(1, "!SO_KEEPALIVE\n", 14!SO_KEEPALIVE
) = 14

I believe the problem is due to tha fact that the Unix getsockopt can return
any non-zero integer for true (hence the [8] in the strace output). The
getsockopt implementation calls getsockopt_int and returns a Val_int(..)
though I believe it should return a Val_bool(..) to explictely map numbers > 1
to true.

This probably means implementing getsockopt as:


CAMLprim value unix_getsockopt_bool(value socket, value option) {
return Val_bool(Int_val(getsockopt_int(sockopt_bool, socket, SOL_SOCKET,
option)));
}

Regards,
Steve

--
Steve Bishop
President - Cambridge University Caving Club - http://cucc.survex.com/

smb50@cam.ac.uk - http://smb50.quns.cam.ac.uk/ - Mobile 07748 960856
Queens' College, Cambridge. CB3 9ET

@vicuna
Copy link
Author

vicuna commented Jul 31, 2002

Comment author: administrator

See #3489

@vicuna vicuna closed this as completed Aug 25, 2002
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant