I can duplicate with your script on my mac

Thanks for taking time to reproduce.

This is probably something you should open an issue for

I was hoping I was wrong and missed something, but I guess I should indeed... I just opened this issue.

my guess is that hard-coded 256 should really be changed to maybe sizeof(struct tcp_info)

As far as I understand this code is responsible for all getsockopt calls, not just the calls for the TCP_INFO structure (for example on macOS one can also retrieve the TCP_CONNECTION_INFO structure using getsockopt...). So unless we are sure the TCP_INFO structure will always be the largest one, it would require checking the size of the requested structure, i.e. translating the getsockopt macro name to the actual C structure name to be able to compute the length, which seems quite complicated...

I guess adding an optional parameter to the getsockopt function to allow the calling code to override the default 256 max size would be ok though.
Or the ugly way: simply doubling current limit and hoping all structures retrievable with getsockopt will always have a size below 512 ;)


In reply to Re^2: getsockopt truncating values to 256 bytes ? by Yaribz
in thread getsockopt truncating values to 256 bytes ? by Yaribz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.