2 * clientsocket.c -- DHCP client socket creation
6 * Russ Dill <Russ.Dill@asu.edu> July 2001
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <sys/types.h>
24 #include <sys/socket.h>
26 #include <netinet/in.h>
28 #if __GLIBC__ >=2 && __GLIBC_MINOR >= 1
29 #include <netpacket/packet.h>
30 #include <net/ethernet.h>
32 #include <asm/types.h>
33 #include <linux/if_packet.h>
34 #include <linux/if_ether.h>
37 #include "clientsocket.h"
41 int raw_socket(int ifindex)
44 struct sockaddr_ll sock;
46 DEBUG(LOG_INFO, "Opening raw socket on ifindex %d", ifindex);
47 if ((fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP))) < 0) {
48 DEBUG(LOG_ERR, "socket call failed: %m");
52 sock.sll_family = AF_PACKET;
53 sock.sll_protocol = htons(ETH_P_IP);
54 sock.sll_ifindex = ifindex;
55 if (bind(fd, (struct sockaddr *) &sock, sizeof(sock)) < 0) {
56 DEBUG(LOG_ERR, "bind call failed: %m");