]> git.ipfire.org Git - thirdparty/squid.git/blob - compat/eui64_aton.c
Renamed squid.h to squid-old.h and config.h to squid.h
[thirdparty/squid.git] / compat / eui64_aton.c
1 /*
2 * Squid Change History:
3 *
4 * 2009-10-16 : import eui64_aton() function from NetBSD eui64.c
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
77 #include "squid.h"
78 #include "compat/eui64_aton.h"
79
80 /*
81 * Convert an ASCII representation of an EUI-64 to binary form.
82 */
83 int
84 eui64_aton(const char *a, struct eui64 *e)
85 {
86 int i;
87 unsigned int o0, o1, o2, o3, o4, o5, o6, o7;
88
89 /* canonical form */
90 i = sscanf(a, "%x-%x-%x-%x-%x-%x-%x-%x",
91 &o0, &o1, &o2, &o3, &o4, &o5, &o6, &o7);
92 if (i == EUI64_LEN)
93 goto good;
94 /* ethernet form */
95 i = sscanf(a, "%x:%x:%x:%x:%x:%x:%x:%x",
96 &o0, &o1, &o2, &o3, &o4, &o5, &o6, &o7);
97 if (i == EUI64_LEN)
98 goto good;
99 /* classic fwcontrol/dconschat form */
100 i = sscanf(a, "0x%2x%2x%2x%2x%2x%2x%2x%2x",
101 &o0, &o1, &o2, &o3, &o4, &o5, &o6, &o7);
102 if (i == EUI64_LEN)
103 goto good;
104 /* MAC format (-) */
105 i = sscanf(a, "%x-%x-%x-%x-%x-%x",
106 &o0, &o1, &o2, &o5, &o6, &o7);
107 if (i == 6) {
108 o3 = 0xff;
109 o4 = 0xfe;
110 goto good;
111 }
112 /* MAC format (:) */
113 i = sscanf(a, "%x:%x:%x:%x:%x:%x",
114 &o0, &o1, &o2, &o5, &o6, &o7);
115 if (i == 6) {
116 o3 = 0xff;
117 o4 = 0xfe;
118 goto good;
119 }
120
121 return (-1);
122
123 good:
124 e->octet[0]=o0;
125 e->octet[1]=o1;
126 e->octet[2]=o2;
127 e->octet[3]=o3;
128 e->octet[4]=o4;
129 e->octet[5]=o5;
130 e->octet[6]=o6;
131 e->octet[7]=o7;
132
133 return (0);
134 }