@@ -829,6 +829,13 @@ static inline void net_ipv6_addr_prefix_mask(const uint8_t *inaddr,
829
829
outaddr [bytes ] = inaddr [bytes ] & mask ;
830
830
}
831
831
832
+ /** @cond INTERNAL_HIDDEN */
833
+ static inline bool net_ipv4_is_addr_loopback_raw (const uint8_t * addr )
834
+ {
835
+ return addr [0 ] == 127U ;
836
+ }
837
+ /** @endcond */
838
+
832
839
/**
833
840
* @brief Check if the IPv4 address is a loopback address (127.0.0.0/8).
834
841
*
@@ -838,8 +845,15 @@ static inline void net_ipv6_addr_prefix_mask(const uint8_t *inaddr,
838
845
*/
839
846
static inline bool net_ipv4_is_addr_loopback (struct in_addr * addr )
840
847
{
841
- return addr -> s4_addr [0 ] == 127U ;
848
+ return net_ipv4_is_addr_loopback_raw (addr -> s4_addr );
849
+ }
850
+
851
+ /** @cond INTERNAL_HIDDEN */
852
+ static inline bool net_ipv4_is_addr_unspecified_raw (const uint8_t * addr )
853
+ {
854
+ return UNALIGNED_GET ((uint32_t * )addr ) == 0 ;
842
855
}
856
+ /** @endcond */
843
857
844
858
/**
845
859
* @brief Check if the IPv4 address is unspecified (all bits zero)
@@ -850,9 +864,16 @@ static inline bool net_ipv4_is_addr_loopback(struct in_addr *addr)
850
864
*/
851
865
static inline bool net_ipv4_is_addr_unspecified (const struct in_addr * addr )
852
866
{
853
- return UNALIGNED_GET ( & addr -> s_addr ) == 0 ;
867
+ return net_ipv4_is_addr_unspecified_raw ( addr -> s4_addr ) ;
854
868
}
855
869
870
+ /** @cond INTERNAL_HIDDEN */
871
+ static inline bool net_ipv4_is_addr_mcast_raw (const uint8_t * addr )
872
+ {
873
+ return (ntohl (UNALIGNED_GET ((uint32_t * )addr )) & 0xF0000000 ) == 0xE0000000 ;
874
+ }
875
+ /** @endcond */
876
+
856
877
/**
857
878
* @brief Check if the IPv4 address is a multicast address.
858
879
*
@@ -862,8 +883,15 @@ static inline bool net_ipv4_is_addr_unspecified(const struct in_addr *addr)
862
883
*/
863
884
static inline bool net_ipv4_is_addr_mcast (const struct in_addr * addr )
864
885
{
865
- return (ntohl (UNALIGNED_GET (& addr -> s_addr )) & 0xF0000000 ) == 0xE0000000 ;
886
+ return net_ipv4_is_addr_mcast_raw (addr -> s4_addr );
887
+ }
888
+
889
+ /** @cond INTERNAL_HIDDEN */
890
+ static inline bool net_ipv4_is_ll_addr_raw (const uint8_t * addr )
891
+ {
892
+ return (ntohl (UNALIGNED_GET ((uint32_t * )addr )) & 0xFFFF0000 ) == 0xA9FE0000 ;
866
893
}
894
+ /** @endcond */
867
895
868
896
/**
869
897
* @brief Check if the given IPv4 address is a link local address.
@@ -874,7 +902,7 @@ static inline bool net_ipv4_is_addr_mcast(const struct in_addr *addr)
874
902
*/
875
903
static inline bool net_ipv4_is_ll_addr (const struct in_addr * addr )
876
904
{
877
- return ( ntohl ( UNALIGNED_GET ( & addr -> s_addr )) & 0xFFFF0000 ) == 0xA9FE0000 ;
905
+ return net_ipv4_is_ll_addr_raw ( addr -> s4_addr ) ;
878
906
}
879
907
880
908
/**
@@ -941,32 +969,31 @@ static inline void net_ipv6_addr_copy_raw(uint8_t *dest,
941
969
}
942
970
943
971
/**
944
- * @brief Compare two IPv4 addresses
972
+ * @brief Compare two raw IPv4 address buffers
945
973
*
946
- * @param addr1 Pointer to IPv4 address.
947
- * @param addr2 Pointer to IPv4 address.
974
+ * @param addr1 Pointer to IPv4 address buffer .
975
+ * @param addr2 Pointer to IPv4 address buffer .
948
976
*
949
977
* @return True if the addresses are the same, false otherwise.
950
978
*/
951
- static inline bool net_ipv4_addr_cmp (const struct in_addr * addr1 ,
952
- const struct in_addr * addr2 )
979
+ static inline bool net_ipv4_addr_cmp_raw (const uint8_t * addr1 ,
980
+ const uint8_t * addr2 )
953
981
{
954
- return UNALIGNED_GET (& addr1 -> s_addr ) == UNALIGNED_GET (& addr2 -> s_addr );
982
+ return UNALIGNED_GET (( uint32_t * ) addr1 ) == UNALIGNED_GET (( uint32_t * ) addr2 );
955
983
}
956
984
957
985
/**
958
- * @brief Compare two raw IPv4 address buffers
986
+ * @brief Compare two IPv4 addresses
959
987
*
960
- * @param addr1 Pointer to IPv4 address buffer .
961
- * @param addr2 Pointer to IPv4 address buffer .
988
+ * @param addr1 Pointer to IPv4 address.
989
+ * @param addr2 Pointer to IPv4 address.
962
990
*
963
991
* @return True if the addresses are the same, false otherwise.
964
992
*/
965
- static inline bool net_ipv4_addr_cmp_raw (const uint8_t * addr1 ,
966
- const uint8_t * addr2 )
993
+ static inline bool net_ipv4_addr_cmp (const struct in_addr * addr1 ,
994
+ const struct in_addr * addr2 )
967
995
{
968
- return net_ipv4_addr_cmp ((const struct in_addr * )addr1 ,
969
- (const struct in_addr * )addr2 );
996
+ return net_ipv4_addr_cmp_raw (addr1 -> s4_addr , addr2 -> s4_addr );
970
997
}
971
998
972
999
/**
@@ -1114,6 +1141,32 @@ static inline bool net_ipv4_addr_mask_cmp(struct net_if *iface,
1114
1141
return net_if_ipv4_addr_mask_cmp (iface , addr );
1115
1142
}
1116
1143
1144
+ /** @cond INTERNAL_HIDDEN */
1145
+ extern bool net_if_ipv4_is_addr_bcast_raw (struct net_if * iface ,
1146
+ const uint8_t * addr );
1147
+
1148
+ #if defined(CONFIG_NET_NATIVE_IPV4 )
1149
+ static inline bool net_ipv4_is_addr_bcast_raw (struct net_if * iface ,
1150
+ const uint8_t * addr )
1151
+ {
1152
+ if (net_ipv4_addr_cmp_raw (addr , net_ipv4_broadcast_address ()-> s4_addr )) {
1153
+ return true;
1154
+ }
1155
+
1156
+ return net_if_ipv4_is_addr_bcast_raw (iface , addr );
1157
+ }
1158
+ #else
1159
+ static inline bool net_ipv4_is_addr_bcast_raw (struct net_if * iface ,
1160
+ const uint8_t * addr )
1161
+ {
1162
+ ARG_UNUSED (iface );
1163
+ ARG_UNUSED (addr );
1164
+
1165
+ return false;
1166
+ }
1167
+ #endif
1168
+ /** @endcond */
1169
+
1117
1170
extern bool net_if_ipv4_is_addr_bcast (struct net_if * iface ,
1118
1171
const struct in_addr * addr );
1119
1172
@@ -1146,6 +1199,23 @@ static inline bool net_ipv4_is_addr_bcast(struct net_if *iface,
1146
1199
}
1147
1200
#endif
1148
1201
1202
+ /** @cond INTERNAL_HIDDEN */
1203
+ extern struct net_if_addr * net_if_ipv4_addr_lookup_raw (const uint8_t * addr ,
1204
+ struct net_if * * ret );
1205
+
1206
+ static inline bool net_ipv4_is_my_addr_raw (const uint8_t * addr )
1207
+ {
1208
+ bool ret ;
1209
+
1210
+ ret = net_if_ipv4_addr_lookup_raw (addr , NULL ) != NULL ;
1211
+ if (!ret ) {
1212
+ ret = net_ipv4_is_addr_bcast_raw (NULL , addr );
1213
+ }
1214
+
1215
+ return ret ;
1216
+ }
1217
+ /** @endcond */
1218
+
1149
1219
extern struct net_if_addr * net_if_ipv4_addr_lookup (const struct in_addr * addr ,
1150
1220
struct net_if * * iface );
1151
1221
0 commit comments