source: mainline/uspace/lib/inet/include/inet/eth_addr.h@ 241ab7e

serial ticket/834-toolchain-update topic/fix-logger-deadlock topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 241ab7e was 241ab7e, checked in by Jiri Svoboda <jiri@…>, 5 years ago

Declare buffer as uint8_t * for stricter type checking

  • Property mode set to 100644
File size: 2.9 KB
Line 
1/*
2 * Copyright (c) 2021 Jiri Svoboda
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup inet
30 * @{
31 */
32/**
33 * @file
34 * @brief
35 */
36
37#ifndef _LIBC_INET_ETH_ADDR_H_
38#define _LIBC_INET_ETH_ADDR_H_
39
40#include <stdint.h>
41
42#define ETH_ADDR_SIZE 6
43#define ETH_ADDR_STR_SIZE (6 * 2 + 5)
44
45#define ETH_ADDR_INITIALIZER(aa, bb, cc, dd, ee, ff) \
46 { .a = ((uint64_t)(aa) << 40) | ((uint64_t)(bb) << 32) | \
47 ((uint64_t)(cc) << 24) | ((uint64_t)(dd) << 16) | \
48 ((uint64_t)(ee) << 8) | (ff) }
49
50/** Ethernet address.
51 *
52 * Defined as a structure. This provides strong type checking.
53 *
54 * Since the structure is not opaque, this allows eth_addr_t to be
55 * allocated statically and copied around using the assignment operator.
56 *
57 * It is stored in the lower 48 bits of a 64-bit integer. This is an internal
58 * representation that allows simple and efficient operation. Most CPUs
59 * will be much faster (and we will need less instructions) operating
60 * on a single 64-bit integer than on six individual 8-bit integers.
61 *
62 * Kind reader will appreciate the cleverness and elegance of this
63 * representation.
64 */
65typedef struct {
66 uint64_t a;
67} eth_addr_t;
68
69/** Ethernet address in the form of a string */
70typedef struct {
71 char str[ETH_ADDR_STR_SIZE + 1];
72} eth_addr_str_t;
73
74extern const eth_addr_t eth_addr_broadcast;
75
76extern void eth_addr_encode(eth_addr_t *, uint8_t *);
77extern void eth_addr_decode(const uint8_t *, eth_addr_t *);
78
79extern int eth_addr_compare(const eth_addr_t *, const eth_addr_t *);
80extern void eth_addr_format(eth_addr_t *, eth_addr_str_t *);
81
82#endif
83
84/** @}
85 */
Note: See TracBrowser for help on using the repository browser.