Implement traversity_core_get_local_ips for UNIX systems

Review Request #1963 — Created Oct. 25, 2022 and submitted

Information

traversity/traversity
default

Reviewers

This is basically an import from the original code in purple2 with some clean
ups.

ran traversity-test on Debian Bookworm AMD64, OpenBSD 7.1 64bit, Freebsd 13.1 32bit, macOS Monterey 64bit, and Haiku OS (not sure version/arch).

I also force the ioctl path on all of them, Haiku only uses the ioctl path, but OpenBSD does not support the ioctl path.

Summary ID
Implement traversity_core_get_local_ips for UNIX systems
This is basically an import from the original code in purple2 with some clean ups.
208a31ff2c5986cc9e192683f36afb15d29f7e93
Description From Last Updated

Should we add some error information to error here in case of tmp being NULL? inet_ntop sets errno.

ivanhoeivanhoe

freeifaddrs is not called in case if this early return.

ivanhoeivanhoe

Should we use error to collect possible errors from socket, ioctl, and inet_ntop?

ivanhoeivanhoe

Is this a typo or some special version of ioctl that returns the error code? Judging from the Linux man …

ivanhoeivanhoe

Should free ifc.ifc_req in case of this early return.

ivanhoeivanhoe

Should free ifc.ifc_req in case of this early return.

ivanhoeivanhoe

I think the G_GNUC_UNUSED can be removed now.

ivanhoeivanhoe

Same as above, is it correct to use ret here instead of errno?

ivanhoeivanhoe
grim
ivanhoe
  1. 
      
  2. traversity/traversitycoreunix.c (Diff revision 1)
     
     

    Should we add some error information to error here in case of tmp being NULL? inet_ntop sets errno.

  3. traversity/traversitycoreunix.c (Diff revision 1)
     
     

    Should we use error to collect possible errors from socket, ioctl, and inet_ntop?

  4. traversity/traversitycoreunix.c (Diff revision 1)
     
     

    The man page of netdevice suggests the following regarding the size of buffer:

    If  the  size  specified by ifc_len is insufficient to store all the addresses, the kernel will skip the exceeding ones and return success.  There is no reliable way of detecting this condition once it has occurred.  It is therefore recommended to either determine the necessary buffer size beforehand by calling SIOCGIFCONF with ifc_req set to NULL, or to retry the call with a bigger buffer whenever ifc_len upon return differs by less than sizeof(struct ifreq) from its original value.
    
  5. 
      
grim
grim
grim
ivanhoe
  1. 
      
  2. traversity/traversitycoreunix.c (Diff revisions 1 - 4)
     
     

    freeifaddrs is not called in case if this early return.

  3. traversity/traversitycoreunix.c (Diff revisions 1 - 4)
     
     

    Is this a typo or some special version of ioctl that returns the error code? Judging from the Linux man page of ioctl this should be g_strerror(errno). Same issue on line 161.

  4. traversity/traversitycoreunix.c (Diff revisions 1 - 4)
     
     

    Should free ifc.ifc_req in case of this early return.

  5. traversity/traversitycoreunix.c (Diff revisions 1 - 4)
     
     

    Should free ifc.ifc_req in case of this early return.

  6. traversity/traversitycoreunix.c (Diff revisions 1 - 4)
     
     

    I think the G_GNUC_UNUSED can be removed now.

  7. traversity/traversitycoreunix.c (Diff revisions 1 - 4)
     
     

    Same as above, is it correct to use ret here instead of errno?

  8. 
      
grim
ivanhoe
  1. Ship It!
  2. 
      
grim
Review request changed

Status: Closed (submitted)

Loading...