Skip to content

Commit b877d2c

Browse files
rlubosdkalowsk
authored andcommitted
net: stats: Use correct format specifiers when printing stats
net_stats_t type is an unsigned type, therefore %u should be used instead of %d when printing values of this type, otherwise negative values will be printer if INT32_MAX is exceeded. Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
1 parent ef02567 commit b877d2c

File tree

3 files changed

+71
-71
lines changed

3 files changed

+71
-71
lines changed

samples/net/stats/src/main.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,96 +32,96 @@ static void print_stats(struct net_if *iface, struct net_stats *data)
3232
}
3333

3434
#if defined(CONFIG_NET_IPV6)
35-
printk("IPv6 recv %d\tsent\t%d\tdrop\t%d\tforwarded\t%d\n",
35+
printk("IPv6 recv %u\tsent\t%u\tdrop\t%u\tforwarded\t%u\n",
3636
GET_STAT(iface, ipv6.recv),
3737
GET_STAT(iface, ipv6.sent),
3838
GET_STAT(iface, ipv6.drop),
3939
GET_STAT(iface, ipv6.forwarded));
4040
#if defined(CONFIG_NET_IPV6_ND)
41-
printk("IPv6 ND recv %d\tsent\t%d\tdrop\t%d\n",
41+
printk("IPv6 ND recv %u\tsent\t%u\tdrop\t%u\n",
4242
GET_STAT(iface, ipv6_nd.recv),
4343
GET_STAT(iface, ipv6_nd.sent),
4444
GET_STAT(iface, ipv6_nd.drop));
4545
#endif /* CONFIG_NET_IPV6_ND */
4646
#if defined(CONFIG_NET_IPV6_PMTU)
47-
printk("IPv6 PMTU recv %d\tsent\t%d\tdrop\t%d\n",
47+
printk("IPv6 PMTU recv %u\tsent\t%u\tdrop\t%u\n",
4848
GET_STAT(iface, ipv6_pmtu.recv),
4949
GET_STAT(iface, ipv6_pmtu.sent),
5050
GET_STAT(iface, ipv6_pmtu.drop));
5151
#endif /* CONFIG_NET_IPV6_PMTU */
5252
#if defined(CONFIG_NET_STATISTICS_MLD)
53-
printk("IPv6 MLD recv %d\tsent\t%d\tdrop\t%d\n",
53+
printk("IPv6 MLD recv %u\tsent\t%u\tdrop\t%u\n",
5454
GET_STAT(iface, ipv6_mld.recv),
5555
GET_STAT(iface, ipv6_mld.sent),
5656
GET_STAT(iface, ipv6_mld.drop));
5757
#endif /* CONFIG_NET_STATISTICS_MLD */
5858
#endif /* CONFIG_NET_IPV6 */
5959

6060
#if defined(CONFIG_NET_IPV4)
61-
printk("IPv4 recv %d\tsent\t%d\tdrop\t%d\tforwarded\t%d\n",
61+
printk("IPv4 recv %u\tsent\t%u\tdrop\t%u\tforwarded\t%u\n",
6262
GET_STAT(iface, ipv4.recv),
6363
GET_STAT(iface, ipv4.sent),
6464
GET_STAT(iface, ipv4.drop),
6565
GET_STAT(iface, ipv4.forwarded));
6666
#endif /* CONFIG_NET_IPV4 */
6767

68-
printk("IP vhlerr %d\thblener\t%d\tlblener\t%d\n",
68+
printk("IP vhlerr %u\thblener\t%u\tlblener\t%u\n",
6969
GET_STAT(iface, ip_errors.vhlerr),
7070
GET_STAT(iface, ip_errors.hblenerr),
7171
GET_STAT(iface, ip_errors.lblenerr));
72-
printk("IP fragerr %d\tchkerr\t%d\tprotoer\t%d\n",
72+
printk("IP fragerr %u\tchkerr\t%u\tprotoer\t%u\n",
7373
GET_STAT(iface, ip_errors.fragerr),
7474
GET_STAT(iface, ip_errors.chkerr),
7575
GET_STAT(iface, ip_errors.protoerr));
7676

7777
#if defined(CONFIG_NET_IPV4_PMTU)
78-
printk("IPv4 PMTU recv %d\tsent\t%d\tdrop\t%d\n",
78+
printk("IPv4 PMTU recv %u\tsent\t%u\tdrop\t%u\n",
7979
GET_STAT(iface, ipv4_pmtu.recv),
8080
GET_STAT(iface, ipv4_pmtu.sent),
8181
GET_STAT(iface, ipv4_pmtu.drop));
8282
#endif /* CONFIG_NET_IPV4_PMTU */
8383

84-
printk("ICMP recv %d\tsent\t%d\tdrop\t%d\n",
84+
printk("ICMP recv %u\tsent\t%u\tdrop\t%u\n",
8585
GET_STAT(iface, icmp.recv),
8686
GET_STAT(iface, icmp.sent),
8787
GET_STAT(iface, icmp.drop));
88-
printk("ICMP typeer %d\tchkerr\t%d\n",
88+
printk("ICMP typeer %u\tchkerr\t%u\n",
8989
GET_STAT(iface, icmp.typeerr),
9090
GET_STAT(iface, icmp.chkerr));
9191

9292
#if defined(CONFIG_NET_UDP)
93-
printk("UDP recv %d\tsent\t%d\tdrop\t%d\n",
93+
printk("UDP recv %u\tsent\t%u\tdrop\t%u\n",
9494
GET_STAT(iface, udp.recv),
9595
GET_STAT(iface, udp.sent),
9696
GET_STAT(iface, udp.drop));
97-
printk("UDP chkerr %d\n",
97+
printk("UDP chkerr %u\n",
9898
GET_STAT(iface, udp.chkerr));
9999
#endif
100100

101101
#if defined(CONFIG_NET_STATISTICS_TCP)
102-
printk("TCP bytes recv %u\tsent\t%d\n",
102+
printk("TCP bytes recv %u\tsent\t%u\n",
103103
GET_STAT(iface, tcp.bytes.received),
104104
GET_STAT(iface, tcp.bytes.sent));
105-
printk("TCP seg recv %d\tsent\t%d\tdrop\t%d\n",
105+
printk("TCP seg recv %u\tsent\t%u\tdrop\t%u\n",
106106
GET_STAT(iface, tcp.recv),
107107
GET_STAT(iface, tcp.sent),
108108
GET_STAT(iface, tcp.drop));
109-
printk("TCP seg resent %d\tchkerr\t%d\tackerr\t%d\n",
109+
printk("TCP seg resent %u\tchkerr\t%u\tackerr\t%u\n",
110110
GET_STAT(iface, tcp.resent),
111111
GET_STAT(iface, tcp.chkerr),
112112
GET_STAT(iface, tcp.ackerr));
113-
printk("TCP seg rsterr %d\trst\t%d\tre-xmit\t%d\n",
113+
printk("TCP seg rsterr %u\trst\t%u\tre-xmit\t%u\n",
114114
GET_STAT(iface, tcp.rsterr),
115115
GET_STAT(iface, tcp.rst),
116116
GET_STAT(iface, tcp.rexmit));
117-
printk("TCP conn drop %d\tconnrst\t%d\n",
117+
printk("TCP conn drop %u\tconnrst\t%u\n",
118118
GET_STAT(iface, tcp.conndrop),
119119
GET_STAT(iface, tcp.connrst));
120120
#endif
121121

122122
printk("Bytes received %u\n", GET_STAT(iface, bytes.received));
123123
printk("Bytes sent %u\n", GET_STAT(iface, bytes.sent));
124-
printk("Processing err %d\n", GET_STAT(iface, processing_error));
124+
printk("Processing err %u\n", GET_STAT(iface, processing_error));
125125
}
126126

127127
#if defined(CONFIG_NET_STATISTICS_PER_INTERFACE)

subsys/net/ip/net_stats.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -85,96 +85,96 @@ static inline void stats(struct net_if *iface)
8585
}
8686

8787
#if defined(CONFIG_NET_STATISTICS_IPV6)
88-
NET_INFO("IPv6 recv %d\tsent\t%d\tdrop\t%d\tforwarded\t%d",
88+
NET_INFO("IPv6 recv %u\tsent\t%u\tdrop\t%u\tforwarded\t%u",
8989
GET_STAT(iface, ipv6.recv),
9090
GET_STAT(iface, ipv6.sent),
9191
GET_STAT(iface, ipv6.drop),
9292
GET_STAT(iface, ipv6.forwarded));
9393
#if defined(CONFIG_NET_STATISTICS_IPV6_ND)
94-
NET_INFO("IPv6 ND recv %d\tsent\t%d\tdrop\t%d",
94+
NET_INFO("IPv6 ND recv %u\tsent\t%u\tdrop\t%u",
9595
GET_STAT(iface, ipv6_nd.recv),
9696
GET_STAT(iface, ipv6_nd.sent),
9797
GET_STAT(iface, ipv6_nd.drop));
9898
#endif /* CONFIG_NET_STATISTICS_IPV6_ND */
9999
#if defined(CONFIG_NET_STATISTICS_IPV6_PMTU)
100-
NET_INFO("IPv6 PMTU recv %d\tsent\t%d\tdrop\t%d",
100+
NET_INFO("IPv6 PMTU recv %u\tsent\t%u\tdrop\t%u",
101101
GET_STAT(iface, ipv6_pmtu.recv),
102102
GET_STAT(iface, ipv6_pmtu.sent),
103103
GET_STAT(iface, ipv6_pmtu.drop));
104104
#endif /* CONFIG_NET_STATISTICS_IPV6_PMTU */
105105
#if defined(CONFIG_NET_STATISTICS_MLD)
106-
NET_INFO("IPv6 MLD recv %d\tsent\t%d\tdrop\t%d",
106+
NET_INFO("IPv6 MLD recv %u\tsent\t%u\tdrop\t%u",
107107
GET_STAT(iface, ipv6_mld.recv),
108108
GET_STAT(iface, ipv6_mld.sent),
109109
GET_STAT(iface, ipv6_mld.drop));
110110
#endif /* CONFIG_NET_STATISTICS_MLD */
111111
#endif /* CONFIG_NET_STATISTICS_IPV6 */
112112

113113
#if defined(CONFIG_NET_STATISTICS_IPV4)
114-
NET_INFO("IPv4 recv %d\tsent\t%d\tdrop\t%d\tforwarded\t%d",
114+
NET_INFO("IPv4 recv %u\tsent\t%u\tdrop\t%u\tforwarded\t%u",
115115
GET_STAT(iface, ipv4.recv),
116116
GET_STAT(iface, ipv4.sent),
117117
GET_STAT(iface, ipv4.drop),
118118
GET_STAT(iface, ipv4.forwarded));
119119
#endif /* CONFIG_NET_STATISTICS_IPV4 */
120120

121-
NET_INFO("IP vhlerr %d\thblener\t%d\tlblener\t%d",
121+
NET_INFO("IP vhlerr %u\thblener\t%u\tlblener\t%u",
122122
GET_STAT(iface, ip_errors.vhlerr),
123123
GET_STAT(iface, ip_errors.hblenerr),
124124
GET_STAT(iface, ip_errors.lblenerr));
125-
NET_INFO("IP fragerr %d\tchkerr\t%d\tprotoer\t%d",
125+
NET_INFO("IP fragerr %u\tchkerr\t%u\tprotoer\t%u",
126126
GET_STAT(iface, ip_errors.fragerr),
127127
GET_STAT(iface, ip_errors.chkerr),
128128
GET_STAT(iface, ip_errors.protoerr));
129129

130130
#if defined(CONFIG_NET_STATISTICS_IPV4_PMTU)
131-
NET_INFO("IPv4 PMTU recv %d\tsent\t%d\tdrop\t%d",
131+
NET_INFO("IPv4 PMTU recv %u\tsent\t%u\tdrop\t%u",
132132
GET_STAT(iface, ipv4_pmtu.recv),
133133
GET_STAT(iface, ipv4_pmtu.sent),
134134
GET_STAT(iface, ipv4_pmtu.drop));
135135
#endif /* CONFIG_NET_STATISTICS_IPV4_PMTU */
136136

137-
NET_INFO("ICMP recv %d\tsent\t%d\tdrop\t%d",
137+
NET_INFO("ICMP recv %u\tsent\t%u\tdrop\t%u",
138138
GET_STAT(iface, icmp.recv),
139139
GET_STAT(iface, icmp.sent),
140140
GET_STAT(iface, icmp.drop));
141-
NET_INFO("ICMP typeer %d\tchkerr\t%d",
141+
NET_INFO("ICMP typeer %u\tchkerr\t%u",
142142
GET_STAT(iface, icmp.typeerr),
143143
GET_STAT(iface, icmp.chkerr));
144144

145145
#if defined(CONFIG_NET_STATISTICS_UDP)
146-
NET_INFO("UDP recv %d\tsent\t%d\tdrop\t%d",
146+
NET_INFO("UDP recv %u\tsent\t%u\tdrop\t%u",
147147
GET_STAT(iface, udp.recv),
148148
GET_STAT(iface, udp.sent),
149149
GET_STAT(iface, udp.drop));
150-
NET_INFO("UDP chkerr %d",
150+
NET_INFO("UDP chkerr %u",
151151
GET_STAT(iface, udp.chkerr));
152152
#endif
153153

154154
#if defined(CONFIG_NET_STATISTICS_TCP)
155-
NET_INFO("TCP bytes recv %u\tsent\t%d",
155+
NET_INFO("TCP bytes recv %u\tsent\t%u",
156156
GET_STAT(iface, tcp.bytes.received),
157157
GET_STAT(iface, tcp.bytes.sent));
158-
NET_INFO("TCP seg recv %d\tsent\t%d\tdrop\t%d",
158+
NET_INFO("TCP seg recv %u\tsent\t%u\tdrop\t%u",
159159
GET_STAT(iface, tcp.recv),
160160
GET_STAT(iface, tcp.sent),
161161
GET_STAT(iface, tcp.drop));
162-
NET_INFO("TCP seg resent %d\tchkerr\t%d\tackerr\t%d",
162+
NET_INFO("TCP seg resent %u\tchkerr\t%u\tackerr\t%u",
163163
GET_STAT(iface, tcp.resent),
164164
GET_STAT(iface, tcp.chkerr),
165165
GET_STAT(iface, tcp.ackerr));
166-
NET_INFO("TCP seg rsterr %d\trst\t%d\tre-xmit\t%d",
166+
NET_INFO("TCP seg rsterr %u\trst\t%u\tre-xmit\t%u",
167167
GET_STAT(iface, tcp.rsterr),
168168
GET_STAT(iface, tcp.rst),
169169
GET_STAT(iface, tcp.rexmit));
170-
NET_INFO("TCP conn drop %d\tconnrst\t%d",
170+
NET_INFO("TCP conn drop %u\tconnrst\t%u",
171171
GET_STAT(iface, tcp.conndrop),
172172
GET_STAT(iface, tcp.connrst));
173173
#endif
174174

175175
NET_INFO("Bytes received %u", GET_STAT(iface, bytes.received));
176176
NET_INFO("Bytes sent %u", GET_STAT(iface, bytes.sent));
177-
NET_INFO("Processing err %d",
177+
NET_INFO("Processing err %u",
178178
GET_STAT(iface, processing_error));
179179

180180
#if NET_TC_COUNT > 1
@@ -183,7 +183,7 @@ static inline void stats(struct net_if *iface)
183183
NET_INFO("TC Priority\tSent pkts\tbytes");
184184

185185
for (i = 0; i < NET_TC_TX_COUNT; i++) {
186-
NET_INFO("[%d] %s (%d)\t%d\t\t%d", i,
186+
NET_INFO("[%d] %s (%u)\t%u\t\t%u", i,
187187
priority2str(GET_STAT(iface,
188188
tc.sent[i].priority)),
189189
GET_STAT(iface, tc.sent[i].priority),
@@ -197,7 +197,7 @@ static inline void stats(struct net_if *iface)
197197
NET_INFO("TC Priority\tRecv pkts\tbytes");
198198

199199
for (i = 0; i < NET_TC_RX_COUNT; i++) {
200-
NET_INFO("[%d] %s (%d)\t%d\t\t%d", i,
200+
NET_INFO("[%d] %s (%u)\t%u\t\t%u", i,
201201
priority2str(GET_STAT(iface,
202202
tc.recv[i].priority)),
203203
GET_STAT(iface, tc.recv[i].priority),
@@ -213,7 +213,7 @@ static inline void stats(struct net_if *iface)
213213
NET_INFO("Power management statistics:");
214214
NET_INFO("Last suspend time: %u ms",
215215
GET_STAT(iface, pm.last_suspend_time));
216-
NET_INFO("Got suspended %d times",
216+
NET_INFO("Got suspended %u times",
217217
GET_STAT(iface, pm.suspend_count));
218218
NET_INFO("Average suspend time: %u ms",
219219
(uint32_t)(GET_STAT(iface, pm.overall_suspend_time) /

0 commit comments

Comments
 (0)