3 BSD raw socket interface code... */
7 It's not clear how this should work, and that lack of clarity is
8 terribly detrimental to the NetBSD 1.1 kernel - it crashes and
11 Using raw sockets ought to be a big win over using BPF or something
12 like it, because you don't need to deal with the complexities of
13 the physical layer, but it appears not to be possible with existing
14 raw socket implementations. This may be worth revisiting in the
15 future. For now, this code can probably be considered a curiosity.
19 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
20 * Copyright (c) 1995-2003 by Internet Software Consortium
22 * Permission to use, copy, modify, and distribute this software for any
23 * purpose with or without fee is hereby granted, provided that the above
24 * copyright notice and this permission notice appear in all copies.
26 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
27 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
28 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
29 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
30 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
31 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
32 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
34 * Internet Systems Consortium, Inc.
36 * Redwood City, CA 94063
40 * This software has been written for Internet Systems Consortium
41 * by Ted Lemon in cooperation with Vixie Enterprises and Nominum, Inc.
42 * To learn more about Internet Systems Consortium, see
43 * ``http://www.isc.org/''. To learn more about Vixie Enterprises,
44 * see ``http://www.vix.com''. To learn more about Nominum, Inc., see
45 * ``http://www.nominum.com''.
49 static char copyright
[] =
50 "$Id$ Copyright (c) 2004 Internet Systems Consortium. All rights reserved.\n";
55 #if defined (USE_RAW_SEND)
58 /* Generic interface registration routine... */
59 void if_register_send (info
)
60 struct interface_info
*info
;
62 struct sockaddr_in name
;
67 /* Set up the address we're going to connect to. */
68 name
.sin_family
= AF_INET
;
69 name
.sin_port
= local_port
;
70 name
.sin_addr
.s_addr
= htonl (INADDR_BROADCAST
);
71 memset (name
.sin_zero
, 0, sizeof (name
.sin_zero
));
73 /* List addresses on which we're listening. */
74 if (!quiet_interface_discovery
)
75 log_info ("Sending on %s, port %d",
76 inet_ntoa (info
->primary_address
), htons (local_port
));
77 if ((sock
= socket (AF_INET
, SOCK_RAW
, IPPROTO_RAW
)) < 0)
78 log_fatal ("Can't create dhcp socket: %m");
80 /* Set the BROADCAST option so that we can broadcast DHCP responses. */
82 if (setsockopt (sock
, SOL_SOCKET
, SO_BROADCAST
,
83 &flag
, sizeof flag
) < 0)
84 log_fatal ("Can't set SO_BROADCAST option on dhcp socket: %m");
86 /* Set the IP_HDRINCL flag so that we can supply our own IP
88 if (setsockopt (sock
, IPPROTO_IP
, IP_HDRINCL
, &flag
, sizeof flag
) < 0)
89 log_fatal ("Can't set IP_HDRINCL flag: %m");
91 info
-> wfdesc
= sock
;
92 if (!quiet_interface_discovery
)
93 log_info ("Sending on Raw/%s%s%s",
95 (info
-> shared_network
? "/" : ""),
96 (info
-> shared_network
?
97 info
-> shared_network
-> name
: ""));
100 void if_deregister_send (info
)
101 struct interface_info
*info
;
103 #ifdef SOCKET_IS_NOT_A_FILE
104 CloseSocket (info
-> wfdesc
);
106 close (info
-> wfdesc
);
110 if (!quiet_interface_discovery
)
111 log_info ("Disabling output on Raw/%s%s%s",
113 (info
-> shared_network
? "/" : ""),
114 (info
-> shared_network
?
115 info
-> shared_network
-> name
: ""));
118 ssize_t
send_packet (interface
, packet
, raw
, len
, from
, to
, hto
)
119 struct interface_info
*interface
;
120 struct packet
*packet
;
121 struct dhcp_packet
*raw
;
124 struct sockaddr_in
*to
;
125 struct hardware
*hto
;
127 unsigned char buf
[256];
131 /* Assemble the headers... */
132 assemble_udp_ip_header (interface
, buf
, &bufp
, from
.s_addr
,
133 to
-> sin_addr
.s_addr
, to
-> sin_port
,
134 (unsigned char *)raw
, len
);
137 result
= sendto(interface
-> wfdesc
, buf
, bufp
, 0, (struct sockaddr
*)to
, sizeof *to
);
139 result
= sendto(interface
-> wfdesc
, buf
, bufp
, 0, (struct sockaddr
*)to
, sizeof *to
);
141 log_error ("send_packet: %m");
145 int can_unicast_without_arp (ip
)
146 struct interface_info
*ip
;
151 int supports_multiple_interfaces (ip
)
152 struct interface_info
*ip
;
157 void maybe_setup_fallback ()
161 void if_reinitialize_send (info
)
162 struct interface_info
*info
;
166 int can_receive_unicast_unconfigured (ip
)
167 struct interface_info
*ip
;
172 #endif /* USE_SOCKET_SEND */