Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0001282OCamlOCaml generalpublic2002-07-31 13:302002-07-31 16:10
Reporteradministrator 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0001282: getsockopt: incorrect return values
DescriptionHi,

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

TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0001004)
administrator (administrator)
2002-07-31 16:09

> 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)':
> 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.

You're entirely right. This will be fixed in the next release.

Thanks for the bug report.

- Xavier Leroy

(0001005)
administrator (administrator)
2002-07-31 16:10

Fixed as suggested 2002-07-30 by XL.

- Issue History
Date Modified Username Field Change
2005-11-18 10:13 administrator New Issue


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker