]>
Commit | Line | Data |
---|---|---|
a98c2da5 AJ |
1 | /* |
2 | * Squid Change History: | |
3 | * | |
cd937acb | 4 | * 2009-10-16 : import eui64_aton() function from NetBSD eui64.c |
a98c2da5 AJ |
5 | */ |
6 | ||
7 | /* $NetBSD: eui64.c,v 1.1 2005/07/11 15:35:25 kiyohara Exp $ */ | |
8 | /* | |
9 | * Copyright 2004 The Aerospace Corporation. All rights reserved. | |
10 | * | |
11 | * Redistribution and use in source and binary forms, with or without | |
12 | * modification, are permitted provided that the following conditions | |
13 | * are met: | |
14 | * | |
15 | * 1. Redistributions of source code must retain the above copyright | |
16 | * notice, this list of conditions, and the following disclaimer. | |
17 | * 2. Redistributions in binary form must reproduce the above copyright | |
18 | * notice, this list of conditions, and the following disclaimer in the | |
19 | * documentation and/or other materials provided with the distribution. | |
20 | * 3. The name of The Aerospace Corporation may not be used to endorse or | |
21 | * promote products derived from this software. | |
22 | * | |
23 | * THIS SOFTWARE IS PROVIDED BY THE AEROSPACE CORPORATION "AS IS" AND | |
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AEROSPACE CORPORATION BE LIABLE | |
27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
33 | * SUCH DAMAGE. | |
34 | * | |
35 | * Copyright (c) 1995 | |
36 | * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved. | |
37 | * | |
38 | * Redistribution and use in source and binary forms, with or without | |
39 | * modification, are permitted provided that the following conditions | |
40 | * are met: | |
41 | * 1. Redistributions of source code must retain the above copyright | |
42 | * notice, this list of conditions and the following disclaimer. | |
43 | * 2. Redistributions in binary form must reproduce the above copyright | |
44 | * notice, this list of conditions and the following disclaimer in the | |
45 | * documentation and/or other materials provided with the distribution. | |
46 | * 3. All advertising materials mentioning features or use of this software | |
47 | * must display the following acknowledgement: | |
48 | * This product includes software developed by Bill Paul. | |
49 | * 4. Neither the name of the author nor the names of any co-contributors | |
50 | * may be used to endorse or promote products derived from this software | |
51 | * without specific prior written permission. | |
52 | * | |
53 | * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND | |
54 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
55 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
56 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
57 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
58 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
59 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
60 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
61 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
62 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
63 | * SUCH DAMAGE. | |
64 | * | |
65 | * EUI-64 conversion and lookup routines | |
66 | * | |
67 | * | |
68 | * Converted from ether_addr.c rev | |
69 | * FreeBSD: src/lib/libc/net/eui64.c,v 1.15 2002/04/08 07:51:10 ru Exp | |
70 | * by Brooks Davis | |
71 | * | |
72 | * Written by Bill Paul <wpaul@ctr.columbia.edu> | |
73 | * Center for Telecommunications Research | |
74 | * Columbia University, New York City | |
75 | */ | |
76 | ||
f7f3304a | 77 | #include "squid.h" |
cd937acb | 78 | #include "compat/eui64_aton.h" |
a98c2da5 | 79 | |
4de1e2da AJ |
80 | #if SQUID_EUI64_ATON |
81 | ||
a98c2da5 AJ |
82 | /* |
83 | * Convert an ASCII representation of an EUI-64 to binary form. | |
84 | */ | |
85 | int | |
86 | eui64_aton(const char *a, struct eui64 *e) | |
87 | { | |
05320519 A |
88 | int i; |
89 | unsigned int o0, o1, o2, o3, o4, o5, o6, o7; | |
a98c2da5 | 90 | |
05320519 A |
91 | /* canonical form */ |
92 | i = sscanf(a, "%x-%x-%x-%x-%x-%x-%x-%x", | |
93 | &o0, &o1, &o2, &o3, &o4, &o5, &o6, &o7); | |
94 | if (i == EUI64_LEN) | |
95 | goto good; | |
96 | /* ethernet form */ | |
97 | i = sscanf(a, "%x:%x:%x:%x:%x:%x:%x:%x", | |
98 | &o0, &o1, &o2, &o3, &o4, &o5, &o6, &o7); | |
99 | if (i == EUI64_LEN) | |
100 | goto good; | |
101 | /* classic fwcontrol/dconschat form */ | |
102 | i = sscanf(a, "0x%2x%2x%2x%2x%2x%2x%2x%2x", | |
103 | &o0, &o1, &o2, &o3, &o4, &o5, &o6, &o7); | |
104 | if (i == EUI64_LEN) | |
105 | goto good; | |
106 | /* MAC format (-) */ | |
107 | i = sscanf(a, "%x-%x-%x-%x-%x-%x", | |
108 | &o0, &o1, &o2, &o5, &o6, &o7); | |
109 | if (i == 6) { | |
110 | o3 = 0xff; | |
111 | o4 = 0xfe; | |
112 | goto good; | |
113 | } | |
114 | /* MAC format (:) */ | |
115 | i = sscanf(a, "%x:%x:%x:%x:%x:%x", | |
116 | &o0, &o1, &o2, &o5, &o6, &o7); | |
117 | if (i == 6) { | |
118 | o3 = 0xff; | |
119 | o4 = 0xfe; | |
120 | goto good; | |
121 | } | |
a98c2da5 | 122 | |
05320519 | 123 | return (-1); |
a98c2da5 AJ |
124 | |
125 | good: | |
05320519 A |
126 | e->octet[0]=o0; |
127 | e->octet[1]=o1; | |
128 | e->octet[2]=o2; | |
129 | e->octet[3]=o3; | |
130 | e->octet[4]=o4; | |
131 | e->octet[5]=o5; | |
132 | e->octet[6]=o6; | |
133 | e->octet[7]=o7; | |
a98c2da5 | 134 | |
05320519 | 135 | return (0); |
a98c2da5 | 136 | } |
4de1e2da AJ |
137 | |
138 | #endif /* !SQUID_EUI64_ATON */ |