use socklen_t with getsockopt()
Was incorrect before too, since it was sizeof(int) in the first place ?
Sylvain
----- Message d'origine ----
De : Thiemo Seufer <[email protected]>
À : Mike Frysinger <[email protected]>
Cc : [email protected]
Envoyé le : Dimanche, 1 Avril 2007, 20h43mn 02s
Objet : Re: [Qemu-devel] [patch] use socklen_t with getsockopt()
Quoted 2 lines · Mike Frysinger
obvious fixup ...
getsockopt()takes asocklen_t, not an int -mike
This is incorrect. Its initial value is sizeof(val).
Thiemo
Quoted 1 line · Sylvain Petreolle
Was incorrect before too, since it was sizeof(int) in the first place ?
The old type of "val" was "int", so it made no different to the size. When "val" is of type socklen_t, it matters.
-- Jamie
Quoted 5 lines · Jamie Lokier
Quoted 1 line · Sylvain Petreolle
Was incorrect before too, since it was sizeof(int) in the first place ?
The old type of "val" was "int", so it made no different to the size. When "val" is of type
socklen_t, it matters.
val is still of type int which is fine ... socklen_t is for the variable which describes the length of val
-mike
Quoted 9 lines · Mike Frysinger
Quoted 5 lines · Jamie Lokier
Quoted 1 line · Sylvain Petreolle
Was incorrect before too, since it was sizeof(int) in the first place ?
The old type of "val" was "int", so it made no different to the size. When "val" is of type
socklen_t, it matters.val is still of type int which is fine ...
socklen_tis for the variable which describes the length of val
It's worth noting that socklen_t should be "int" anyway. From the accept(2) manpage:
NOTE
The third argument of accept() was originally declared as an int *' (and is that under libc4 and libc5 and on many other systems like 4.x BSD, SunOS 4, SGI); a POSIX.1g draft standard wanted to change it into a size_t *', and that is what it is for SunOS 5. Later POSIX drafts have `socklen_t *', and so do the Single Unix Specification and glibc2. Quoting Linus Torvalds:
"_Any_ sane library _must_ have "socklen_t" be the same size as int. Anything else breaks any BSD socket layer stuff. POSIX initially did make it a size_t, and I (and hopefully others, but obviously not too many) complained to them very loudly indeed. Making it a size_t is completely broken, exactly because size_t very seldom is the same size as "int" on 64-bit architectures, for example. And it has to be the same size as "int" because that's what the BSD socket interface is.
Anyway, the POSIX people eventually got a clue, and created
"socklen_t". They shouldn't have touched it in the first place, but once they did they felt it had to have a named type for some unfath- omable reason (probably somebody didn't like losing face over having done the original stupid thing, so they silently just renamed their blunder)."
Quoted 9 lines · Mike Frysinger
Quoted 5 lines · Jamie Lokier
Quoted 1 line · Sylvain Petreolle
Was incorrect before too, since it was sizeof(int) in the first place ?
The old type of "val" was "int", so it made no different to the size. When "val" is of type
socklen_t, it matters.val is still of type int which is fine ...
socklen_tis for the variable which describes the length of val
Yes, thanks for pointing it out.
-- Jamie