20 |
* along with this program; if not, write to the Free Software |
* along with this program; if not, write to the Free Software |
21 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
22 |
*/ |
*/ |
23 |
|
#include "common.h" |
24 |
|
#include "dhcpd.h" |
25 |
|
#include "dhcpc.h" |
26 |
|
|
27 |
|
|
28 |
#include <features.h> |
//#include <features.h> |
29 |
#include <asm/types.h> |
#include <asm/types.h> |
30 |
#if (defined(__GLIBC__) && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1) || defined(_NEWLIB_VERSION) |
#if (defined(__GLIBC__) && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1) || defined(_NEWLIB_VERSION) |
31 |
#include <netpacket/packet.h> |
#include <netpacket/packet.h> |
36 |
#endif |
#endif |
37 |
#include <linux/filter.h> |
#include <linux/filter.h> |
38 |
|
|
|
#include "common.h" |
|
|
#include "dhcpd.h" |
|
|
#include "dhcpc.h" |
|
|
|
|
39 |
int FAST_FUNC udhcp_raw_socket(int ifindex) |
int FAST_FUNC udhcp_raw_socket(int ifindex) |
40 |
{ |
{ |
41 |
int fd; |
int fd; |
85 |
.filter = (struct sock_filter *) filter_instr, |
.filter = (struct sock_filter *) filter_instr, |
86 |
}; |
}; |
87 |
|
|
88 |
DEBUG("opening raw socket on ifindex %d", ifindex); |
log1("Opening raw socket on ifindex %d", ifindex); //log2? |
89 |
|
|
90 |
fd = xsocket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP)); |
fd = xsocket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP)); |
91 |
DEBUG("got raw socket fd %d", fd); |
log1("Got raw socket fd %d", fd); //log2? |
92 |
|
|
93 |
if (SERVER_PORT == 67 && CLIENT_PORT == 68) { |
if (SERVER_PORT == 67 && CLIENT_PORT == 68) { |
94 |
/* Use only if standard ports are in use */ |
/* Use only if standard ports are in use */ |
95 |
/* Ignoring error (kernel may lack support for this) */ |
/* Ignoring error (kernel may lack support for this) */ |
96 |
if (setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, &filter_prog, |
if (setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, &filter_prog, |
97 |
sizeof(filter_prog)) >= 0) |
sizeof(filter_prog)) >= 0) |
98 |
DEBUG("attached filter to raw socket fd %d", fd); |
log1("Attached filter to raw socket fd %d", fd); // log? |
99 |
} |
} |
100 |
|
|
101 |
sock.sll_family = AF_PACKET; |
sock.sll_family = AF_PACKET; |
102 |
sock.sll_protocol = htons(ETH_P_IP); |
sock.sll_protocol = htons(ETH_P_IP); |
103 |
sock.sll_ifindex = ifindex; |
sock.sll_ifindex = ifindex; |
104 |
xbind(fd, (struct sockaddr *) &sock, sizeof(sock)); |
xbind(fd, (struct sockaddr *) &sock, sizeof(sock)); |
105 |
DEBUG("bound to raw socket fd %d", fd); |
log1("Created raw socket"); |
106 |
|
|
107 |
return fd; |
return fd; |
108 |
} |
} |