@@ -63,6 +63,8 @@ public class NetworkIF {
63
63
private long packetsSent ;
64
64
private long inErrors ;
65
65
private long outErrors ;
66
+ private long inDrops ;
67
+ private long collisions ;
66
68
private long speed ;
67
69
private long timeStamp ;
68
70
@@ -156,10 +158,11 @@ public String getDisplayName() {
156
158
* The interface Maximum Transmission Unit (MTU).
157
159
* </p>
158
160
*
159
- * @return The MTU of the network interface. This value is set when the
160
- * {@link oshi.hardware.NetworkIF} is instantiated and may not be up to
161
- * date. To update this value, execute the
162
- * {@link #setNetworkInterface(NetworkInterface)} method
161
+ * @return The MTU of the network interface.
162
+ * <p>
163
+ * This value is set when the {@link oshi.hardware.NetworkIF} is
164
+ * instantiated and may not be up to date. To update this value, execute
165
+ * the {@link #setNetworkInterface(NetworkInterface)} method
163
166
*/
164
167
public int getMTU () {
165
168
return this .mtu ;
@@ -170,10 +173,11 @@ public int getMTU() {
170
173
* The Media Access Control (MAC) address.
171
174
* </p>
172
175
*
173
- * @return The MAC Address. This value is set when the
174
- * {@link oshi.hardware.NetworkIF} is instantiated and may not be up to
175
- * date. To update this value, execute the
176
- * {@link #setNetworkInterface(NetworkInterface)} method
176
+ * @return The MAC Address.
177
+ * <p>
178
+ * This value is set when the {@link oshi.hardware.NetworkIF} is
179
+ * instantiated and may not be up to date. To update this value, execute
180
+ * the {@link #setNetworkInterface(NetworkInterface)} method
177
181
*/
178
182
public String getMacaddr () {
179
183
return this .mac ;
@@ -184,10 +188,11 @@ public String getMacaddr() {
184
188
* The Internet Protocol (IP) v4 address.
185
189
* </p>
186
190
*
187
- * @return The IPv4 Addresses. This value is set when the
188
- * {@link oshi.hardware.NetworkIF} is instantiated and may not be up to
189
- * date. To update this value, execute the
190
- * {@link #setNetworkInterface(NetworkInterface)} method
191
+ * @return The IPv4 Addresses.
192
+ * <p>
193
+ * This value is set when the {@link oshi.hardware.NetworkIF} is
194
+ * instantiated and may not be up to date. To update this value, execute
195
+ * the {@link #setNetworkInterface(NetworkInterface)} method
191
196
*/
192
197
public String [] getIPv4addr () {
193
198
return Arrays .copyOf (this .ipv4 , this .ipv4 .length );
@@ -198,10 +203,11 @@ public String[] getIPv4addr() {
198
203
* The Internet Protocol (IP) v4 subnet masks.
199
204
* </p>
200
205
*
201
- * @return The IPv4 subnet mask length. Ranges between 0-32 This value is set
202
- * when the {@link oshi.hardware.NetworkIF} is instantiated and may not
203
- * be up to date. To update this value, execute the
204
- * {@link #setNetworkInterface(NetworkInterface)} method.
206
+ * @return The IPv4 subnet mask length. Ranges between 0-32.
207
+ * <p>
208
+ * This value is set when the {@link oshi.hardware.NetworkIF} is
209
+ * instantiated and may not be up to date. To update this value, execute
210
+ * the {@link #setNetworkInterface(NetworkInterface)} method.
205
211
*
206
212
*/
207
213
public Short [] getSubnetMasks () {
@@ -213,10 +219,11 @@ public Short[] getSubnetMasks() {
213
219
* The Internet Protocol (IP) v6 address.
214
220
* </p>
215
221
*
216
- * @return The IPv6 Addresses. This value is set when the
217
- * {@link oshi.hardware.NetworkIF} is instantiated and may not be up to
218
- * date. To update this value, execute the
219
- * {@link #setNetworkInterface(NetworkInterface)} method
222
+ * @return The IPv6 Addresses.
223
+ * <p>
224
+ * This value is set when the {@link oshi.hardware.NetworkIF} is
225
+ * instantiated and may not be up to date. To update this value, execute
226
+ * the {@link #setNetworkInterface(NetworkInterface)} method
220
227
*/
221
228
public String [] getIPv6addr () {
222
229
return Arrays .copyOf (this .ipv6 , this .ipv6 .length );
@@ -227,10 +234,11 @@ public String[] getIPv6addr() {
227
234
* The Internet Protocol (IP) v6 address.
228
235
* </p>
229
236
*
230
- * @return The IPv6 address prefix lengths. Ranges between 0-128. This value is
231
- * set when the {@link oshi.hardware.NetworkIF} is instantiated and may
232
- * not be up to date. To update this value, execute the
233
- * {@link #setNetworkInterface(NetworkInterface)} method
237
+ * @return The IPv6 address prefix lengths. Ranges between 0-128.
238
+ * <p>
239
+ * This value is set when the {@link oshi.hardware.NetworkIF} is
240
+ * instantiated and may not be up to date. To update this value, execute
241
+ * the {@link #setNetworkInterface(NetworkInterface)} method
234
242
*/
235
243
public Short [] getPrefixLengths () {
236
244
return Arrays .copyOf (this .prefixLengths , this .prefixLengths .length );
@@ -241,10 +249,11 @@ public Short[] getPrefixLengths() {
241
249
* Getter for the field <code>bytesRecv</code>.
242
250
* </p>
243
251
*
244
- * @return The Bytes Received. This value is set when the
245
- * {@link oshi.hardware.NetworkIF} is instantiated and may not be up to
246
- * date. To update this value, execute the {@link #updateAttributes()}
247
- * method
252
+ * @return The Bytes Received.
253
+ * <p>
254
+ * This value is set when the {@link oshi.hardware.NetworkIF} is
255
+ * instantiated and may not be up to date. To update this value, execute
256
+ * the {@link #updateAttributes()} method
248
257
*/
249
258
public long getBytesRecv () {
250
259
return this .bytesRecv ;
@@ -267,10 +276,11 @@ public void setBytesRecv(long bytesRecv) {
267
276
* Getter for the field <code>bytesSent</code>.
268
277
* </p>
269
278
*
270
- * @return The Bytes Sent. This value is set when the
271
- * {@link oshi.hardware.NetworkIF} is instantiated and may not be up to
272
- * date. To update this value, execute the {@link #updateAttributes()}
273
- * method
279
+ * @return The Bytes Sent.
280
+ * <p>
281
+ * This value is set when the {@link oshi.hardware.NetworkIF} is
282
+ * instantiated and may not be up to date. To update this value, execute
283
+ * the {@link #updateAttributes()} method
274
284
*/
275
285
public long getBytesSent () {
276
286
return this .bytesSent ;
@@ -293,10 +303,11 @@ public void setBytesSent(long bytesSent) {
293
303
* Getter for the field <code>packetsRecv</code>.
294
304
* </p>
295
305
*
296
- * @return The Packets Received. This value is set when the
297
- * {@link oshi.hardware.NetworkIF} is instantiated and may not be up to
298
- * date. To update this value, execute the {@link #updateAttributes()}
299
- * method
306
+ * @return The Packets Received.
307
+ * <p>
308
+ * This value is set when the {@link oshi.hardware.NetworkIF} is
309
+ * instantiated and may not be up to date. To update this value, execute
310
+ * the {@link #updateAttributes()} method
300
311
*/
301
312
public long getPacketsRecv () {
302
313
return this .packetsRecv ;
@@ -319,10 +330,11 @@ public void setPacketsRecv(long packetsRecv) {
319
330
* Getter for the field <code>packetsSent</code>.
320
331
* </p>
321
332
*
322
- * @return The Packets Sent. This value is set when the
323
- * {@link oshi.hardware.NetworkIF} is instantiated and may not be up to
324
- * date. To update this value, execute the {@link #updateAttributes()}
325
- * method
333
+ * @return The Packets Sent.
334
+ * <p>
335
+ * This value is set when the {@link oshi.hardware.NetworkIF} is
336
+ * instantiated and may not be up to date. To update this value, execute
337
+ * the {@link #updateAttributes()} method
326
338
*/
327
339
public long getPacketsSent () {
328
340
return this .packetsSent ;
@@ -345,10 +357,11 @@ public void setPacketsSent(long packetsSent) {
345
357
* Getter for the field <code>inErrors</code>.
346
358
* </p>
347
359
*
348
- * @return Input Errors. This value is set when the
349
- * {@link oshi.hardware.NetworkIF} is instantiated and may not be up to
350
- * date. To update this value, execute the {@link #updateAttributes()}
351
- * method
360
+ * @return Input Errors.
361
+ * <p>
362
+ * This value is set when the {@link oshi.hardware.NetworkIF} is
363
+ * instantiated and may not be up to date. To update this value, execute
364
+ * the {@link #updateAttributes()} method
352
365
*/
353
366
public long getInErrors () {
354
367
return this .inErrors ;
@@ -371,10 +384,11 @@ public void setInErrors(long inErrors) {
371
384
* Getter for the field <code>outErrors</code>.
372
385
* </p>
373
386
*
374
- * @return The Output Errors. This value is set when the
375
- * {@link oshi.hardware.NetworkIF} is instantiated and may not be up to
376
- * date. To update this value, execute the {@link #updateAttributes()}
377
- * method
387
+ * @return The Output Errors.
388
+ * <p>
389
+ * This value is set when the {@link oshi.hardware.NetworkIF} is
390
+ * instantiated and may not be up to date. To update this value, execute
391
+ * the {@link #updateAttributes()} method
378
392
*/
379
393
public long getOutErrors () {
380
394
return this .outErrors ;
@@ -392,15 +406,71 @@ public void setOutErrors(long outErrors) {
392
406
this .outErrors = ParseUtil .unsignedLongToSignedLong (outErrors );
393
407
}
394
408
409
+ /**
410
+ * <p>
411
+ * Getter for the field <code>inDrops</code>.
412
+ * </p>
413
+ *
414
+ * @return Incoming/Received dropped packets. On Windows, returns discarded
415
+ * incoming packets.
416
+ * <p>
417
+ * This value is set when the {@link oshi.hardware.NetworkIF} is
418
+ * instantiated and may not be up to date. To update this value, execute
419
+ * the {@link #updateAttributes()} method
420
+ */
421
+ public long getInDrops () {
422
+ return inDrops ;
423
+ }
424
+
425
+ /**
426
+ * <p>
427
+ * Setter for the field <code>inDrops</code>.
428
+ * </p>
429
+ *
430
+ * @param inDrops
431
+ * The incoming (receive) dropped packets to set.
432
+ */
433
+ public void setInDrops (long inDrops ) {
434
+ this .inDrops = inDrops ;
435
+ }
436
+
437
+ /**
438
+ * <p>
439
+ * Getter for the field <code>collisions</code>.
440
+ * </p>
441
+ *
442
+ * @return Packet collisions. On Windows, returns discarded outgoing packets.
443
+ * <p>
444
+ * This value is set when the {@link oshi.hardware.NetworkIF} is
445
+ * instantiated and may not be up to date. To update this value, execute
446
+ * the {@link #updateAttributes()} method
447
+ */
448
+ public long getCollisions () {
449
+ return collisions ;
450
+ }
451
+
452
+ /**
453
+ * <p>
454
+ * Setter for the field <code>collisions</code>.
455
+ * </p>
456
+ *
457
+ * @param collisions
458
+ * The collisions to set.
459
+ */
460
+ public void setCollisions (long collisions ) {
461
+ this .collisions = collisions ;
462
+ }
463
+
395
464
/**
396
465
* <p>
397
466
* Getter for the field <code>speed</code>.
398
467
* </p>
399
468
*
400
- * @return The speed of the network interface in bits per second. This value is
401
- * set when the {@link oshi.hardware.NetworkIF} is instantiated and may
402
- * not be up to date. To update this value, execute the
403
- * {@link #updateAttributes()} method
469
+ * @return The speed of the network interface in bits per second.
470
+ * <p>
471
+ * This value is set when the {@link oshi.hardware.NetworkIF} is
472
+ * instantiated and may not be up to date. To update this value, execute
473
+ * the {@link #updateAttributes()} method
404
474
*/
405
475
public long getSpeed () {
406
476
return this .speed ;
@@ -444,27 +514,24 @@ public void setTimeStamp(long timeStamp) {
444
514
/**
445
515
* Updates interface network statistics on this interface. Statistics include
446
516
* packets and bytes sent and received, and interface speed.
517
+ *
518
+ * @return {@code true} if the update was successful, {@code false} otherwise.
447
519
*/
448
- public void updateAttributes () {
520
+ public boolean updateAttributes () {
449
521
switch (SystemInfo .getCurrentPlatformEnum ()) {
450
522
case WINDOWS :
451
- WindowsNetworks .updateNetworkStats (this );
452
- break ;
523
+ return WindowsNetworks .updateNetworkStats (this );
453
524
case LINUX :
454
- LinuxNetworks .updateNetworkStats (this );
455
- break ;
525
+ return LinuxNetworks .updateNetworkStats (this );
456
526
case MACOSX :
457
- MacNetworks .updateNetworkStats (this );
458
- break ;
527
+ return MacNetworks .updateNetworkStats (this );
459
528
case SOLARIS :
460
- SolarisNetworks .updateNetworkStats (this );
461
- break ;
529
+ return SolarisNetworks .updateNetworkStats (this );
462
530
case FREEBSD :
463
- FreeBsdNetworks .updateNetworkStats (this );
464
- break ;
531
+ return FreeBsdNetworks .updateNetworkStats (this );
465
532
default :
466
533
LOG .error ("Unsupported platform. No update performed." );
467
- break ;
534
+ return false ;
468
535
}
469
536
}
470
537
@@ -479,9 +546,11 @@ public String toString() {
479
546
sb .append (" IPv6: " ).append (Arrays .toString (getIPv6addr ())).append ("\n " );
480
547
sb .append (" Prefix Lengths: " ).append (Arrays .toString (getPrefixLengths ())).append ("\n " );
481
548
sb .append (" Traffic: received " ).append (getPacketsRecv ()).append (" packets/" )
482
- .append (FormatUtil .formatBytes (getBytesRecv ())).append (" (" + getInErrors () + " err);" );
549
+ .append (FormatUtil .formatBytes (getBytesRecv ())).append (" (" + getInErrors () + " err, " )
550
+ .append (getInDrops () + " drop);" );
483
551
sb .append (" transmitted " ).append (getPacketsSent ()).append (" packets/" )
484
- .append (FormatUtil .formatBytes (getBytesSent ())).append (" (" + getOutErrors () + " err)" );
552
+ .append (FormatUtil .formatBytes (getBytesSent ())).append (" (" + getOutErrors () + " err, " )
553
+ .append (getCollisions () + " coll);" );
485
554
return sb .toString ();
486
555
}
487
556
}
0 commit comments