summaryrefslogtreecommitdiff
path: root/net/xl2tpd/patches/patch-misc.h
blob: da80e4fa14fb43b174cfff4f8d55247f5b00fbf2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
$NetBSD: patch-misc.h,v 1.2 2017/10/13 17:24:05 christos Exp $

Portable inlines are in header files.

--- misc.h.orig	2017-08-02 13:46:06.000000000 -0400
+++ misc.h	2017-10-13 12:49:29.042331434 -0400
@@ -65,7 +65,6 @@
 extern struct buffer *new_buf (int);
 extern void udppush_handler (int);
 extern int addfcs (struct buffer *buf);
-extern void swaps (void *, int);
 extern void do_packet_dump (struct buffer *);
 extern void status (const char *fmt, ...);
 extern void status_handler (int signal);
@@ -76,4 +75,30 @@
 extern void opt_destroy (struct ppp_opts *);
 extern struct ppp_opts *add_opt (struct ppp_opts *, char *, ...);
 extern void process_signal (void);
+
+
+static inline void swaps (void *buf_v, int len)
+{
+#ifdef __alpha
+    /* Reverse byte order alpha is little endian so lest save a step.
+       to make things work out easier */
+    int x;
+    unsigned char t1;
+    unsigned char *tmp = (_u16 *) buf_v;
+    for (x = 0; x < len; x += 2)
+    {
+        t1 = tmp[x];
+        tmp[x] = tmp[x + 1];
+        tmp[x + 1] = t1;
+    }
+#else
+
+    /* Reverse byte order (if proper to do so) 
+       to make things work out easier */
+    int x;
+    struct hw { _u16 s; } __attribute__((__packed__)) *p = (struct hw *) buf_v;
+    for (x = 0; x < len / 2; x++, p++)
+	    p->s = ntohs(p->s); 
+#endif
+}
 #endif