Skip to content

Add missing IN_CLASSA_NSHIFT and related macros to <netinet/in.h> #8

Closed

Description

@ppenna

Summary

Newlib's <netinet/in.h>\ is missing several BSD/glibc IPv4 address classification macros that are commonly expected by portable networking code:

  • \IN_CLASSA_NSHIFT\ (should be \24)
  • \IN_MULTICAST(i)\ (should be (((i) & 0xf0000000U) == 0xe0000000U))
  • \IN_EXPERIMENTAL(i)\ (should be (((i) & 0xe0000000U) == 0xe0000000U))
  • \IN_LOOPBACKNET\ (should be \127)

Context

CPython's \Modules/getaddrinfo.c\ (the fallback \getaddrinfo\ implementation) uses these macros to classify numeric IPv4 addresses — for example, to skip reverse-DNS (canonical name) lookups on loopback (\127.x.x.x) and multicast addresses. The file already carries #ifndef\ guards that define fallback values when the system headers omit them, so the CPython build is unaffected. However, it would be cleaner if these macros lived in the proper system header.

These macros are defined in glibc's <netinet/in.h>\ and in most BSD <netinet/in.h>\ variants. Adding them to Nanvix's Newlib fork would improve POSIX networking compatibility and reduce the need for downstream workarounds.

Suggested location


ewlib/libc/sys/nanvix/include/netinet/in.h\ (or whichever header currently defines \struct in_addr, \INADDR_ANY, etc.)

References

  • CPython workaround: \Modules/getaddrinfo.c\ lines 122-136
  • glibc definition: \inet/netinet/in.h\
  • POSIX: these are common extensions, not strictly POSIX-mandated, but widely expected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions