ether.c revision 1.1 1 1.1 brezak /*
2 1.1 brezak * Copyright (c) 1992 Regents of the University of California.
3 1.1 brezak * All rights reserved.
4 1.1 brezak *
5 1.1 brezak * This software was developed by the Computer Systems Engineering group
6 1.1 brezak * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
7 1.1 brezak * contributed to Berkeley.
8 1.1 brezak *
9 1.1 brezak * Redistribution and use in source and binary forms, with or without
10 1.1 brezak * modification, are permitted provided that the following conditions
11 1.1 brezak * are met:
12 1.1 brezak * 1. Redistributions of source code must retain the above copyright
13 1.1 brezak * notice, this list of conditions and the following disclaimer.
14 1.1 brezak * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 brezak * notice, this list of conditions and the following disclaimer in the
16 1.1 brezak * documentation and/or other materials provided with the distribution.
17 1.1 brezak * 3. All advertising materials mentioning features or use of this software
18 1.1 brezak * must display the following acknowledgement:
19 1.1 brezak * This product includes software developed by the University of
20 1.1 brezak * California, Lawrence Berkeley Laboratory and its contributors.
21 1.1 brezak * 4. Neither the name of the University nor the names of its contributors
22 1.1 brezak * may be used to endorse or promote products derived from this software
23 1.1 brezak * without specific prior written permission.
24 1.1 brezak *
25 1.1 brezak * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 1.1 brezak * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 1.1 brezak * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 1.1 brezak * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 1.1 brezak * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 1.1 brezak * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 1.1 brezak * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 1.1 brezak * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 1.1 brezak * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 1.1 brezak * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 1.1 brezak * SUCH DAMAGE.
36 1.1 brezak *
37 1.1 brezak * from @(#) Header: net.c,v 1.9 93/08/06 19:32:15 leres Exp (LBL)
38 1.1 brezak */
39 1.1 brezak
40 1.1 brezak #include <sys/param.h>
41 1.1 brezak #include <sys/socket.h>
42 1.1 brezak #include <string.h>
43 1.1 brezak
44 1.1 brezak #include <net/if.h>
45 1.1 brezak
46 1.1 brezak #include <netinet/in.h>
47 1.1 brezak #include <netinet/if_ether.h>
48 1.1 brezak #include <netinet/in_systm.h>
49 1.1 brezak #include <netinet/ip.h>
50 1.1 brezak
51 1.1 brezak #include "stand.h"
52 1.1 brezak #include "net.h"
53 1.1 brezak #include "netif.h"
54 1.1 brezak
55 1.1 brezak const u_char bcea[6] = {
56 1.1 brezak 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
57 1.1 brezak };
58 1.1 brezak
59 1.1 brezak /* Caller must leave room for ethernet header in front!! */
60 1.1 brezak int
61 1.1 brezak sendether(d, buf, len, dea, etype)
62 1.1 brezak struct iodesc *d;
63 1.1 brezak void *buf;
64 1.1 brezak int len;
65 1.1 brezak u_char *dea;
66 1.1 brezak int etype;
67 1.1 brezak {
68 1.1 brezak register struct ether_header *eh;
69 1.1 brezak
70 1.1 brezak #ifdef ETHER_DEBUG
71 1.1 brezak if (debug)
72 1.1 brezak printf("sendether: called\n");
73 1.1 brezak #endif
74 1.1 brezak eh = ((struct ether_header *)buf) - 1;
75 1.1 brezak len += ETHER_SIZE;
76 1.1 brezak
77 1.1 brezak MACPY(d->myea, eh->ether_shost); /* by byte */
78 1.1 brezak MACPY(dea, eh->ether_dhost); /* by byte */
79 1.1 brezak eh->ether_type = htons(etype);
80 1.1 brezak return (netif_put(d, eh, len) - ETHER_SIZE);
81 1.1 brezak }
82 1.1 brezak
83 1.1 brezak /*
84 1.1 brezak * Convert Ethernet address to printable (loggable) representation.
85 1.1 brezak */
86 1.1 brezak static char digits[] = "0123456789abcdef";
87 1.1 brezak char *
88 1.1 brezak ether_sprintf(ap)
89 1.1 brezak register u_char *ap;
90 1.1 brezak {
91 1.1 brezak register i;
92 1.1 brezak static char etherbuf[18];
93 1.1 brezak register char *cp = etherbuf;
94 1.1 brezak
95 1.1 brezak for (i = 0; i < 6; i++) {
96 1.1 brezak *cp++ = digits[*ap >> 4];
97 1.1 brezak *cp++ = digits[*ap++ & 0xf];
98 1.1 brezak *cp++ = ':';
99 1.1 brezak }
100 1.1 brezak *--cp = 0;
101 1.1 brezak return (etherbuf);
102 1.1 brezak }
103