Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 187561 | Differences between
and this patch

Collapse All | Expand All

(-)arp.c (-14 / +42 lines)
Lines 24-30 Link Here
24
#include <sys/select.h>
24
#include <sys/select.h>
25
#include <sys/socket.h>
25
#include <sys/socket.h>
26
#include <netinet/in_systm.h>
26
#include <netinet/in_systm.h>
27
#ifdef __linux
27
#ifdef __linux__
28
#include <netinet/ether.h>
28
#include <netinet/ether.h>
29
#include <netpacket/packet.h>
29
#include <netpacket/packet.h>
30
#endif
30
#endif
Lines 76-81 Link Here
76
	int arpsize = arphdr_len2 (iface->hwlen, sizeof (struct in_addr));
76
	int arpsize = arphdr_len2 (iface->hwlen, sizeof (struct in_addr));
77
	int retval;
77
	int retval;
78
78
79
	logger (LOG_DEBUG, "hwlen %d family %d arpsize %d", iface->hwlen, iface->family, arpsize);
80
81
79
	arp = xmalloc (arpsize);
82
	arp = xmalloc (arpsize);
80
	memset (arp, 0, arpsize);
83
	memset (arp, 0, arpsize);
81
84
Lines 90-95 Link Here
90
		memcpy (ar_tha (arp), taddr, arp->ar_hln); 
93
		memcpy (ar_tha (arp), taddr, arp->ar_hln); 
91
	memcpy (ar_tpa (arp), &tip, arp->ar_pln);
94
	memcpy (ar_tpa (arp), &tip, arp->ar_pln);
92
95
96
	logger (LOG_DEBUG, "arphdr_len %d", arphdr_len (arp));
97
93
	retval = send_packet (iface, ETHERTYPE_ARP,
98
	retval = send_packet (iface, ETHERTYPE_ARP,
94
						  (unsigned char *) arp, arphdr_len (arp));
99
						  (unsigned char *) arp, arphdr_len (arp));
95
	free (arp);
100
	free (arp);
Lines 105-110 Link Here
105
	int nprobes = 0;
110
	int nprobes = 0;
106
	int nclaims = 0;
111
	int nclaims = 0;
107
	struct in_addr null_address;
112
	struct in_addr null_address;
113
	struct timeval stopat;
114
	struct timeval now;
108
115
109
	if (! iface->arpable) {
116
	if (! iface->arpable) {
110
		logger (LOG_DEBUG, "interface `%s' is not ARPable", iface->name);
117
		logger (LOG_DEBUG, "interface `%s' is not ARPable", iface->name);
Lines 130-149 Link Here
130
		int buflen = sizeof (char *) * iface->buffer_length;
137
		int buflen = sizeof (char *) * iface->buffer_length;
131
		fd_set rset;
138
		fd_set rset;
132
		int bytes;
139
		int bytes;
133
		int s;
140
		int s = 0;
134
141
135
		tv.tv_sec = 0; 
142
		/* Only select if we have a timeout */
136
		tv.tv_usec = timeout;
143
		if (timeout > 0) {
144
			tv.tv_sec = 0; 
145
			tv.tv_usec = timeout;
137
146
138
		FD_ZERO (&rset);
147
			FD_ZERO (&rset);
139
		FD_SET (iface->fd, &rset);
148
			FD_SET (iface->fd, &rset);
140
		errno = 0;
149
141
		if ((s = select (FD_SETSIZE, &rset, NULL, NULL, &tv)) == -1) {
150
			errno = 0;
142
			if (errno != EINTR)
151
			if ((s = select (FD_SETSIZE, &rset, NULL, NULL, &tv)) == -1) {
143
				logger (LOG_ERR, "select: `%s'", strerror (errno));
152
				if (errno != EINTR)
144
			break;
153
					logger (LOG_ERR, "select: `%s'", strerror (errno));
145
		} else if (s == 0) {
154
				break;
146
			/* Timed out */
155
			}
156
		}
157
158
		/* Timed out */
159
		if (s == 0) {
147
			if (nprobes < NPROBES) {
160
			if (nprobes < NPROBES) {
148
				nprobes ++;
161
				nprobes ++;
149
				timeout = PROBE_INTERVAL;
162
				timeout = PROBE_INTERVAL;
Lines 159-166 Link Here
159
				retval = 0;
172
				retval = 0;
160
				break;
173
				break;
161
			}
174
			}
175
176
			/* Setup our stop time */
177
			if (get_time (&stopat) != 0)
178
				break;
179
			stopat.tv_usec += timeout;
180
181
			continue;
162
		}
182
		}
163
		
183
184
		/* We maybe ARP flooded, so check our time */
185
		if (get_time (&now) != 0)
186
			break;
187
		if (timercmp (&now, &stopat, >)) {
188
			timeout = 0;
189
			continue;
190
		}
191
164
		if (! FD_ISSET (iface->fd, &rset))
192
		if (! FD_ISSET (iface->fd, &rset))
165
			continue;
193
			continue;
166
194
(-)Makefile (-5 / +9 lines)
Lines 1-4 Link Here
1
VERSION = 3.1.3
1
VERSION = 3.1.4_pre2
2
CFLAGS ?= -O2 -pipe
2
CFLAGS ?= -O2 -pipe
3
3
4
# Should work for both GNU make and BSD make
4
# Should work for both GNU make and BSD make
Lines 49-60 Link Here
49
dhcpcd_OBJS = arp.o client.o common.o configure.o dhcp.o dhcpcd.o duid.o \
49
dhcpcd_OBJS = arp.o client.o common.o configure.o dhcp.o dhcpcd.o duid.o \
50
		info.o interface.o ipv4ll.o logger.o signals.o socket.o
50
		info.o interface.o ipv4ll.o logger.o signals.o socket.o
51
51
52
# By default we don't need to link to anything
52
# These are nasty hacks to work out what libs we need to link to
53
# Except on Darwin where we need -lresolv, so they need to uncomment this
53
# We require librt for glibc bases systems
54
#dhcpcd_LIBS = -lresolv
54
LIBRT != ldd /bin/date 2>/dev/null | grep -q /librt.so && echo "-lrt" || exit 0
55
LIBRT ?= $(shell ldd /bin/date 2>/dev/null | grep -q /librt.so && echo "-lrt")
55
56
57
# Darwin needs this, but we have no way of detecting this atm
58
#LIBRESOLV = -lresolv
59
56
dhcpcd: $(dhcpcd_H) $(dhcpcd_OBJS)
60
dhcpcd: $(dhcpcd_H) $(dhcpcd_OBJS)
57
	$(CC) $(LDFLAGS) $(dhcpcd_OBJS) $(dhcpcd_LIBS) -o dhcpcd
61
	$(CC) $(LDFLAGS) $(dhcpcd_OBJS) $(LIBRT) $(LIBRESOLV) -o dhcpcd
58
62
59
version.h:
63
version.h:
60
	echo '#define VERSION "$(VERSION)"' > version.h
64
	echo '#define VERSION "$(VERSION)"' > version.h
(-)common.c (-8 / +13 lines)
Lines 76-92 Link Here
76
#  endif
76
#  endif
77
#endif
77
#endif
78
78
79
/* This requires us to link to rt on glibc, so we use sysinfo instead */
79
/* Handy function to get the time. */
80
#ifdef __linux__
80
int get_time(struct timeval *tp)
81
#include <sys/sysinfo.h>
82
long uptime (void)
83
{
81
{
84
	struct sysinfo info;
82
	struct timespec ts;
85
83
86
	sysinfo (&info);
84
	if (clock_gettime (CLOCK_MONOTONIC, &ts) == -1) {
87
	return info.uptime;
85
		logger (LOG_ERR, "clock_gettime: %s", strerror (errno));
86
		return (-1);
87
	}
88
89
	tp->tv_sec = ts.tv_sec;
90
	tp->tv_usec = ts.tv_nsec / 1000;
91
	return (0);
88
}
92
}
89
#elif __APPLE__
93
94
#ifdef __APPLE__
90
/* Darwin doesn't appear to have an uptime, so try and make one ourselves */
95
/* Darwin doesn't appear to have an uptime, so try and make one ourselves */
91
long uptime (void)
96
long uptime (void)
92
{
97
{
(-)common.h (+2 lines)
Lines 23-28 Link Here
23
#define COMMON_H
23
#define COMMON_H
24
24
25
/* string.h pulls in features.h so the below define checks work */
25
/* string.h pulls in features.h so the below define checks work */
26
#include <sys/time.h>
26
#include <string.h>
27
#include <string.h>
27
28
28
/* Only GLIBC doesn't support strlcpy */
29
/* Only GLIBC doesn't support strlcpy */
Lines 36-41 Link Here
36
void srandomdev (void);
37
void srandomdev (void);
37
#endif
38
#endif
38
39
40
int get_time(struct timeval *tp);
39
long uptime (void);
41
long uptime (void);
40
void *xmalloc (size_t size);
42
void *xmalloc (size_t size);
41
char *xstrdup (const char *str);
43
char *xstrdup (const char *str);

Return to bug 187561