Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/net Provide an inline to return the data part of the arp...



details:   https://anonhg.NetBSD.org/src/rev/89202db35d0c
branches:  trunk
changeset: 320292:89202db35d0c
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Jun 30 15:08:04 2018 +0000

description:
Provide an inline to return the data part of the arp packet instead of
open-coding it in multiple places.

diffstat:

 sys/net/if_arp.h |  19 ++++++++++++-------
 1 files changed, 12 insertions(+), 7 deletions(-)

diffs (55 lines):

diff -r 02bf292dd401 -r 89202db35d0c sys/net/if_arp.h
--- a/sys/net/if_arp.h  Sat Jun 30 14:59:38 2018 +0000
+++ b/sys/net/if_arp.h  Sat Jun 30 15:08:04 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_arp.h,v 1.32 2018/04/19 21:20:43 christos Exp $     */
+/*     $NetBSD: if_arp.h,v 1.33 2018/06/30 15:08:04 christos Exp $     */
 
 /*
  * Copyright (c) 1986, 1993
@@ -74,15 +74,21 @@
 } __packed;
 
 static __inline uint8_t *
+ar_data(struct arphdr *ap)
+{
+       return (uint8_t *)(void *)(ap + 1);
+}
+
+static __inline uint8_t *
 ar_sha(struct arphdr *ap)
 {
-       return ((uint8_t *)(ap + 1)) + 0;
+       return ar_data(ap) + 0;
 }
 
 static __inline uint8_t *
 ar_spa(struct arphdr *ap)
 {
-       return ((uint8_t *)(ap + 1)) + ap->ar_hln;
+       return ar_data(ap) + ap->ar_hln;
 }
 
 static __inline uint8_t *
@@ -91,7 +97,7 @@
        if (ntohs(ap->ar_hrd) == ARPHRD_IEEE1394) {
                return NULL;
        } else {
-               return ((uint8_t *)(ap + 1)) + ap->ar_hln + ap->ar_pln;
+               return ar_data(ap) + ap->ar_hln + ap->ar_pln;
        }
 }
 
@@ -99,10 +105,9 @@
 ar_tpa(struct arphdr *ap)
 {
        if (ntohs(ap->ar_hrd) == ARPHRD_IEEE1394) {
-               return ((uint8_t *)(ap + 1)) + ap->ar_hln + ap->ar_pln;
+               return ar_data(ap) + ap->ar_hln + ap->ar_pln;
        } else {
-               return ((uint8_t *)(ap + 1)) + ap->ar_hln + ap->ar_pln +
-                   ap->ar_hln;
+               return ar_data(ap) + ap->ar_hln + ap->ar_pln + ap->ar_hln;
        }
 }
 



Home | Main Index | Thread Index | Old Index