2

From a recent Linux man-page:

  const char *inet_ntop(int af, const void *src, char *dst, socklen_t size);

This function converts the network address structure src in the af address family into a character string.

size describes the size of memory dst points to.

I understand the use of socklen_t in other functions like connect() or accept().

But why is socklen_t used here?-S

This should be size_t!

Community
  • 1
  • 1
alk
  • 69,737
  • 10
  • 105
  • 255
  • 2
    `getnameinfo()` also uses `socklen_t`. `size_t` is defined to be at least 16bit. `socklen_t` is defined to be at least 32bit. So any `size_t` value can fit in a `socklen_t`. `socklen_t` is just an opaque integer type defined in [`socket.h`](http://pubs.opengroup.org/onlinepubs/7908799/xns/syssocket.h.html), so it is related to socket APIs, whereas `size_t` is related more to the C/C++ language itself. – Remy Lebeau Jul 04 '15 at 16:05
  • From [http://man7.org/linux/man-pages/man3/inet_ntop.3.html](http://man7.org/linux/man-pages/man3/inet_ntop.3.html): `CONFORMING TO POSIX.1-2001. Note that RFC 2553 defines a prototype where the last argument size is of type size_t. Many systems follow RFC 2553. Glibc 2.0 and 2.1 have size_t, but 2.2 and later have socklen_t.` – 4566976 Jul 04 '15 at 19:18
  • 1
    @RemyLebeau - good answer. You should move this to the answer section. – Craig S. Anderson Jul 04 '15 at 19:43
  • @4566976: Your quote adds even more question marks. (I didn't add this to the question on posting it, to stay as neutral a possible ... :-}) – alk Jul 04 '15 at 20:00

0 Answers0