sock: change IPv4 address type to array#5945
Conversation
|
I was wondering when this discussion flames up. ;) I strongly prefer using host byte order at the user API level. The overhead for changing the order as as soon as it is needed is negligible. |
|
I find it weird for IPv4 addresses to be in host-byte order to be honest, but okay then I will change this macro, because I still think its useful for people who don't know about host- or network byteorder ;-) |
(especially since IPv6 addresses are in network byte order) |
|
Mh come to think of it: excectly because of that, I would prefer to make the IPv4 address an array, too... What do you think? |
Yes! I thought about that, too. Let's do that. |
|
Done, but kept the helper macro, for people who like to work with |
|
Arghs, also needs helper function for dynamic initialization to now... |
|
Done |
sys/include/net/sock.h
Outdated
| uint8_t ipv6[16]; | ||
| #endif | ||
| uint32_t ipv4; /**< IPv4 address mode */ | ||
| uint32_t ipv4; /**< IPv4 address mode (in network byte order) */ |
There was a problem hiding this comment.
Didn't we want to change this to be an array?
sys/include/net/sock.h
Outdated
| */ | ||
| static inline void sock_init_ipv4(uint8_t *ipv4, uint32_t addr) | ||
| { | ||
| const uint8_t a[] = SOCK_INIT_IPV4(addr); |
There was a problem hiding this comment.
This is not gonna work, the macro expects 4 arguments.
I actually think we can get rid of this function.
Users will usually not supply IPv4 addresses as "uint32".
They either get it from other functions (e.g., dns reply), or hardcode it.
In that case
ep = {.addr.ipv4= { a,b,c,d }}
would work as expected if the field is an uint8_t array, right?
There was a problem hiding this comment.
Users will usually not supply IPv4 addresses as "uint32".
They either get it from other functions (e.g., dns reply), or hardcode it.
In that case
But a socket wrapper will ;-)
There was a problem hiding this comment.
I mean, the output of inet_pton() or any struct in_addr can directly be copied into .addr.ipv4, right?
There was a problem hiding this comment.
True... I was more thinking in the direction of e.g.
sock_init_ipv4(out->addr.ipv4, in_addr->sin_addr.s_addr);But I guess you can do this with memcpy(), too.
|
Sorry there seems to be some commit fuckup... |
|
Now it's like I intended it to be |
|
@kaspar030 ping? |
|
IMHO we don't need the helper macro and that static inline convenience function. |
|
Done. |
|
ACK, please squash! I'll be on holidays for the next ten days, so unfortunately I have to reassign. |
6a7e69d to
334f823
Compare
|
Squashed |
334f823 to
6d5fdbf
Compare
|
Fixed a rebase error. |
haukepetersen
left a comment
There was a problem hiding this comment.
ACK also from my side.
|
I'm just realizing that this complicates some things, e.g.:
|
|
Well you wanted the macros removed. I was expecting something like that :-/. |
|
How about we add a field |
|
This leaves the byte-order unclear/inconsistent with the port. |
|
To clarify:
|
|
Hmm. I don't think that the byte order for an address matters that much, compared to a port number. I find it absolutely more natural to write What we gain by introducing an uint32_t version of the IPv4 address is the ability to do 32bit register compares due to 4b alignment, which, apart from being easier to code (and read), is probably way more efficient than having to do memcpys and memcmps. |
I really had problems in #5936, #5937, and #5938 to keep byte order. To keep in line with the portability credo of this module I added a helper macro (so we can initialize the IPv4 address statically).