PelionIoT / nanostack-libservice

Other
2 stars 11 forks source link

New "is this an IPv4/IPv6 literal?" helper #71

Closed Taiki-San closed 6 years ago

Taiki-San commented 6 years ago

In a different PR (https://github.com/ARMmbed/mbed-os/pull/6293#issuecomment-396533529), it was mentioned it'd be helpful to add a new helper function, to go with the new IPv4 functions introduced in https://github.com/ARMmbed/nanostack-libservice/pull/69. I was wondering what shape would you see it take. I was thinking about adding an enum with IPv4, IPv6, unknown, error options and a small helper taking in a string and returning either of them. Not sure about the calling convention for the enums, specifically if the project had guidelines. Was that what @kjbracey-arm had in mind?

ciarmcom commented 6 years ago

ARM Internal Ref: ONME-3740

kjbracey commented 6 years ago

I think having conversion functions that return a bool like stoip4 does is sufficient. If stoip6 did the same, then we can just try each conversion function in turn.

Taiki-San commented 6 years ago

Alright, this will require some changes to stoip6 but the minimal signature change will hopefully not break any third party code.
Should we still add an helper that calls both functions back to back, or is it too risky, considering the caller shall provide an output buffer large enough for an IPv6 even if it only expects an IPv4?

kjbracey commented 6 years ago

Don't see any need for a helper at this layer. You'd then need to invent a "type" enum at this layer, which probably would then need to be converted to the next layer up.

In mbed OS, effectively SocketAddress acts as the helper.

Taiki-San commented 6 years ago

Alright, I'm having a look at how to properly return an error in stoip6.