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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors