summaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorJeremy Laine <jeremy.laine@m4x.org>2008-03-26 08:46:59 +0000
committerJeremy Laine <jeremy.laine@m4x.org>2008-03-26 08:46:59 +0000
commitea94804e9778a03fb3fba0248678b51b8e0ef903 (patch)
tree7216398f6bd2eaccd8c37d96ecd088978f337415 /packages
parente06addd05bcd53f6c010cc5bf708bba1828c9cd2 (diff)
pump_0.8.24.bb: add pump DHCP/BOOTP client
Diffstat (limited to 'packages')
-rw-r--r--packages/pump/.mtn2git_empty0
-rw-r--r--packages/pump/pump/.mtn2git_empty0
-rw-r--r--packages/pump/pump/debian.patch2141
-rw-r--r--packages/pump/pump_0.8.24.bb19
4 files changed, 2160 insertions, 0 deletions
diff --git a/packages/pump/.mtn2git_empty b/packages/pump/.mtn2git_empty
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/packages/pump/.mtn2git_empty
diff --git a/packages/pump/pump/.mtn2git_empty b/packages/pump/pump/.mtn2git_empty
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/packages/pump/pump/.mtn2git_empty
diff --git a/packages/pump/pump/debian.patch b/packages/pump/pump/debian.patch
new file mode 100644
index 0000000000..63001b88df
--- /dev/null
+++ b/packages/pump/pump/debian.patch
@@ -0,0 +1,2141 @@
+--- pump-0.8.24.orig/dhcp.c
++++ pump-0.8.24/dhcp.c
+@@ -31,9 +31,11 @@
+ #include <netinet/in.h>
+ #include <netinet/ip.h>
+ #include <netinet/udp.h>
++#include <netpacket/packet.h>
+ #include <popt.h>
+ #include <resolv.h>
+ #include <signal.h>
++#include <stdint.h>
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
+@@ -82,9 +84,6 @@
+ #define DHCP_OPTION_CLASS_IDENTIFIER 60
+ #define DHCP_OPTION_CLIENT_IDENTIFIER 61
+
+-#define BOOTP_CLIENT_PORT 68
+-#define BOOTP_SERVER_PORT 67
+-
+ #define BOOTP_OPCODE_REQUEST 1
+ #define BOOTP_OPCODE_REPLY 2
+
+@@ -126,6 +125,12 @@
+ bp_int16 len;
+ };
+
++struct ippkt {
++ struct ip ip;
++ struct udphdr udp;
++ char payload[sizeof(struct bootpRequest)];
++} __attribute__ ((packed));
++
+ static void parseReply(struct bootpRequest * breq, struct pumpNetIntf * intf);
+ static char * prepareRequest(struct bootpRequest * breq,
+ int sock, char * device, time_t startTime);
+@@ -134,36 +139,24 @@
+ static char * handleTransaction(int s, struct pumpOverrideInfo * override,
+ struct bootpRequest * breq,
+ struct bootpRequest * bresp,
+- struct sockaddr_in * serverAddr,
++ struct sockaddr * serverAddr,
++ socklen_t serverAddrLen,
+ struct sockaddr_in * respondant,
+- int useBootpPacket,
++ int useBootpPacket, int raw,
+ time_t startTime, int dhcpResponseType);
+ static int dhcpMessageType(struct bootpRequest * response);
+-static int oldKernel(void);
+ static char * getInterfaceInfo(struct pumpNetIntf * intf, int s);
+ static char * perrorstr(char * msg);
+ static void addClientIdentifier(int flags, struct bootpRequest * req);
+ static void buildRequest(struct bootpRequest * req, int flags, int type,
+ char * reqHostname, char *class, int lease);
+ static void updateSecCount(struct bootpRequest * breq, time_t startTime);
++static void makeraw(struct ippkt *buf, const void *payload, size_t len);
++static uint32_t checksum(const void *, size_t, uint32_t);
++static uint32_t wrapsum(uint32_t);
+
+ static const char vendCookie[] = { 99, 130, 83, 99, 255 };
+
+-static int oldKernel(void) {
+- struct utsname ubuf;
+- int major1, major2;
+-
+- uname(&ubuf);
+- if (!strcasecmp(ubuf.sysname, "linux")) {
+- if (sscanf(ubuf.release, "%d.%d", &major1, &major2) != 2 ||
+- (major1 < 2) || (major1 == 2 && major2 == 0)) {
+- return 1;
+- }
+- }
+-
+- return 0;
+-}
+-
+ static char * getInterfaceInfo(struct pumpNetIntf * intf, int s) {
+ struct ifreq req;
+ struct sockaddr_in * addrp;
+@@ -177,6 +170,10 @@
+ intf->broadcast = addrp->sin_addr;
+ intf->set = PUMP_INTFINFO_HAS_BROADCAST;
+
++ if (ioctl(s, SIOCGIFINDEX, &req))
++ return perrorstr("SIOCGIFINDEX");
++ intf->ifindex = req.ifr_ifindex;
++
+ return NULL;
+ }
+
+@@ -205,15 +202,18 @@
+ }
+
+
+-char * pumpDisableInterface(char * device) {
++char * pumpDisableInterface(struct pumpNetIntf * intf) {
+ struct ifreq req;
+ int s;
+
++ if (intf->flags & PUMP_FLAG_NOSETUP)
++ return NULL;
++
+ s = socket(AF_INET, SOCK_DGRAM, 0);
+
+ memset(&req,0,sizeof(req));
+
+- strcpy(req.ifr_name, device);
++ strcpy(req.ifr_name, intf->device);
+ if (ioctl(s, SIOCGIFFLAGS, &req)) {
+ close(s);
+ return perrorstr("SIOCGIFFLAGS");
+@@ -235,6 +235,12 @@
+ struct ifreq req;
+ struct rtentry route;
+ int s;
++ char * rc;
++
++ if (intf->flags & PUMP_FLAG_NOSETUP)
++ return NULL;
++
++ if ((rc = pumpDisableInterface(intf))) return rc;
+
+ s = socket(AF_INET, SOCK_DGRAM, 0);
+
+@@ -246,34 +252,46 @@
+ strcpy(req.ifr_name, intf->device);
+
+ addrp->sin_addr = intf->ip;
+- if (ioctl(s, SIOCSIFADDR, &req))
+- return perrorstr("SIOCSIFADDR");
++ if (ioctl(s, SIOCSIFADDR, &req)) {
++ rc = perrorstr("SIOCSIFADDR");
++ goto out;
++ }
+
+ addrp->sin_addr = intf->netmask;
+- if (ioctl(s, SIOCSIFNETMASK, &req))
+- return perrorstr("SIOCSIFNETMASK");
++ if (ioctl(s, SIOCSIFNETMASK, &req)) {
++ rc = perrorstr("SIOCSIFNETMASK");
++ goto out;
++ }
+
+ addrp->sin_addr = intf->broadcast;
+- if (ioctl(s, SIOCSIFBRDADDR, &req))
+- return perrorstr("SIOCSIFBRDADDR");
++ if (ioctl(s, SIOCSIFBRDADDR, &req)) {
++ rc = perrorstr("SIOCSIFBRDADDR");
++ goto out;
++ }
+
+ if (intf->set & PUMP_INTFINFO_HAS_MTU) {
+- req.ifr_mtu = intf->mtu;
+- if (ioctl(s, SIOCSIFMTU, &req))
+- return perrorstr("SIOCSIFMTU");
++ req.ifr_mtu = intf->mtu;
++ if (ioctl(s, SIOCSIFMTU, &req)) {
++ rc = perrorstr("SIOCSIFMTU");
++ goto out;
++ }
+ }
+
+ /* Bring up the device, and specifically allow broadcasts through it.
+ Don't mess with flags we don't understand though. */
+- if (ioctl(s, SIOCGIFFLAGS, &req))
+- return perrorstr("SIOCGIFFLAGS");
++ if (ioctl(s, SIOCGIFFLAGS, &req)) {
++ rc = perrorstr("SIOCGIFFLAGS");
++ goto out;
++ }
+
+ req.ifr_flags |= IFF_UP | IFF_RUNNING | IFF_BROADCAST;
+
+- if (ioctl(s, SIOCSIFFLAGS, &req))
+- return perrorstr("SIOCSIFFLAGS");
++ if (ioctl(s, SIOCSIFFLAGS, &req)) {
++ rc = perrorstr("SIOCSIFFLAGS");
++ goto out;
++ }
+
+- if (!strcmp(intf->device, "lo") || oldKernel()) {
++ if (!strcmp(intf->device, "lo")) {
+ /* add a route for this network */
+ route.rt_dev = intf->device;
+ route.rt_flags = RTF_UP;
+@@ -288,11 +306,14 @@
+
+ if (ioctl(s, SIOCADDRT, &route)) {
+ /* the route cannot already exist, as we've taken the device down */
+- return perrorstr("SIOCADDRT 1");
++ rc = perrorstr("SIOCADDRT 1");
++ goto out;
+ }
+ }
+
+- return NULL;
++out:
++ close(s);
++ return rc;
+ }
+
+ int pumpSetupDefaultGateway(struct in_addr * gw) {
+@@ -317,23 +338,30 @@
+ route.rt_dev = NULL;
+
+ if (ioctl(s, SIOCADDRT, &route)) {
++ close(s);
+ syslog(LOG_ERR, "failed to set default route: %s", strerror(errno));
+ return -1;
+ }
+
++ close(s);
+ return 0;
+ }
+
+ char * pumpPrepareInterface(struct pumpNetIntf * intf, int s) {
+ struct sockaddr_in * addrp;
+ struct ifreq req;
+- struct rtentry route;
+
+ memset(&req,0,sizeof(req));
++ strcpy(req.ifr_name, intf->device);
+
+- addrp = (struct sockaddr_in *) &req.ifr_addr;
++ if (ioctl(s, SIOCGIFINDEX, &req))
++ return perrorstr("SIOCGIFINDEX");
++ intf->ifindex = req.ifr_ifindex;
+
+- strcpy(req.ifr_name, intf->device);
++ if (intf->flags & PUMP_FLAG_NOSETUP)
++ return NULL;
++
++ addrp = (struct sockaddr_in *) &req.ifr_addr;
+ addrp->sin_family = AF_INET;
+ addrp->sin_port = 0;
+ memset(&addrp->sin_addr, 0, sizeof(addrp->sin_addr));
+@@ -344,48 +372,19 @@
+ if (ioctl(s, SIOCSIFADDR, &req))
+ return perrorstr("SIOCSIFADDR");
+
+- if (oldKernel()) {
+- if (ioctl(s, SIOCSIFNETMASK, &req))
+- return perrorstr("SIOCSIFNETMASK");
+-
+- /* the broadcast address is 255.255.255.255 */
+- memset(&addrp->sin_addr, 255, sizeof(addrp->sin_addr));
+- if (ioctl(s, SIOCSIFBRDADDR, &req))
+- return perrorstr("SIOCSIFBRDADDR");
+- }
+-
+ if (ioctl(s, SIOCGIFFLAGS, &req))
+ return perrorstr("SIOCGIFFLAGS");
+ req.ifr_flags |= IFF_UP | IFF_BROADCAST | IFF_RUNNING;
+ if (ioctl(s, SIOCSIFFLAGS, &req))
+ return perrorstr("SIOCSIFFLAGS");
+
+- memset(&route, 0, sizeof(route));
+- memcpy(&route.rt_gateway, addrp, sizeof(*addrp));
+-
+- addrp->sin_family = AF_INET;
+- addrp->sin_port = 0;
+- addrp->sin_addr.s_addr = INADDR_ANY;
+- memcpy(&route.rt_dst, addrp, sizeof(*addrp));
+- memcpy(&route.rt_genmask, addrp, sizeof(*addrp));
+-
+- route.rt_dev = intf->device;
+- route.rt_flags = RTF_UP;
+- route.rt_metric = 0;
+-
+- if (ioctl(s, SIOCADDRT, &route)) {
+- if (errno != EEXIST) {
+- close(s);
+- return perrorstr("SIOCADDRT 3");
+- }
+- }
+-
+ return NULL;
+ }
+
+ static int dhcpMessageType(struct bootpRequest * response) {
+ unsigned char * chptr;
+ unsigned char option, length;
++
+
+ chptr = response->vendor;
+
+@@ -516,9 +515,17 @@
+ break;
+
+ case BOOTP_OPTION_GATEWAY:
+- memcpy(&intf->gateway, chptr, 4);
++ intf->numGateways = 0;
++ for (i = 0; i < length; i += 4) {
++ if (intf->numGateways < MAX_GATEWAYS) {
++ memcpy(&intf->gateways[intf->numGateways++], chptr + i,
++ 4);
++ syslog(LOG_DEBUG, "intf: gateways[%i]: %s",
++ i/4, inet_ntoa (intf->gateways[i/4]));
++ }
++ }
+ intf->set |= PUMP_NETINFO_HAS_GATEWAY;
+- syslog (LOG_DEBUG, "intf: gateway: %s", inet_ntoa (intf->gateway));
++ syslog (LOG_DEBUG, "intf: numGateways: %i", intf->numGateways);
+ break;
+
+ case BOOTP_OPTION_HOSTNAME:
+@@ -692,6 +699,9 @@
+ struct in_addr address;
+ unsigned char *vndptr;
+ unsigned char option, length;
++
++ if (!verbose)
++ return;
+
+ memset(&address,0,sizeof(address));
+
+@@ -744,12 +754,12 @@
+ sprintf (vendor, "%3u %3u", option, length);
+ for (i = 0; i < length; i++)
+ {
+- if (strlen (vendor) > 22)
++ if (strlen (vendor) > sizeof(vendor2) - 6)
+ {
+ syslog (LOG_DEBUG, "%s: vendor: %s", name, vendor);
+ strcpy (vendor, "++++++");
+ }
+- snprintf (vendor2, 27, "%s 0x%02x", vendor, *vndptr++);
++ snprintf (vendor2, sizeof(vendor2), "%s 0x%02x", vendor, *vndptr++);
+ strcpy (vendor, vendor2);
+
+ }
+@@ -763,11 +773,12 @@
+ }
+
+ static char * handleTransaction(int s, struct pumpOverrideInfo * override,
+- struct bootpRequest * breq,
++ struct bootpRequest * breq,
+ struct bootpRequest * bresp,
+- struct sockaddr_in * serverAddr,
++ struct sockaddr * serverAddr,
++ socklen_t serverAddrLen,
+ struct sockaddr_in * respondant,
+- int useBootpPacket,
++ const int useBootpPacket, const int raw,
+ time_t startTime, int dhcpResponseType) {
+ struct timeval tv;
+ fd_set readfs;
+@@ -786,6 +797,9 @@
+ struct udphdr * udpHdr = NULL;
+ struct psuedohUdpHeader pHdr;
+ time_t start = pumpUptime();
++ struct ippkt buf;
++ void * pkt;
++ size_t pktlen, breqlen;
+
+ memset(&pHdr,0,sizeof(pHdr));
+ debugbootpRequest("breq", breq);
+@@ -802,17 +816,26 @@
+ return strerror(errno);
+ }
+
+- while (!gotit && tries) {
+- i = sizeof(*breq);
+- if (useBootpPacket)
+- i -= (DHCP_VENDOR_LENGTH - BOOTP_VENDOR_LENGTH);
++ pkt = breq;
++ breqlen = sizeof(*breq);
++ if (useBootpPacket)
++ breqlen -= (DHCP_VENDOR_LENGTH - BOOTP_VENDOR_LENGTH);
++ pktlen = breqlen;
++ if (raw) {
++ pkt = &buf;
++ pktlen += sizeof(struct ip) + sizeof(struct udphdr);
++ }
+
++ while (!gotit && tries) {
+ if (resend) {
+ if (startTime != -1)
+ updateSecCount(breq, startTime);
+
+- if (sendto(s, breq, i, 0, (struct sockaddr *) serverAddr,
+- sizeof(*serverAddr)) != i) {
++ if (raw)
++ makeraw(&buf, breq, breqlen);
++
++ if (sendto(s, pkt, pktlen, 0, (struct sockaddr *) serverAddr,
++ serverAddrLen) != pktlen) {
+ close(sin);
+ return perrorstr("sendto");
+ }
+@@ -890,9 +913,9 @@
+ continue;
+ */
+
+- if (ntohs(udpHdr->source) != BOOTP_SERVER_PORT)
++ if (udpHdr->source != bootp_server_port)
+ continue;
+- if (ntohs(udpHdr->dest) != BOOTP_CLIENT_PORT)
++ if (udpHdr->dest != bootp_client_port)
+ continue;
+ /* Go on with this packet; it looks sane */
+
+@@ -1022,12 +1045,12 @@
+ }
+
+ if (setsockopt(s, SOL_SOCKET, SO_BINDTODEVICE, device, strlen(device)+1)) {
+- syslog(LOG_ERR, "SO_BINDTODEVICE %s (%zd) failed: %s", device, strlen(device), strerror(errno));
++ syslog(LOG_ERR, "SO_BINDTODEVICE %s (%zu) failed: %s", device, strlen(device), strerror(errno));
+ }
+
+ memset(&clientAddr.sin_addr, 0, sizeof(&clientAddr.sin_addr));
+ clientAddr.sin_family = AF_INET;
+- clientAddr.sin_port = htons(BOOTP_CLIENT_PORT); /* bootp client */
++ clientAddr.sin_port = bootp_client_port; /* bootp client */
+
+ if (bind(s, (struct sockaddr *) &clientAddr, sizeof(clientAddr))) {
+ close(s);
+@@ -1046,7 +1069,7 @@
+ char hostname[1024];
+
+ if (!(intf->set & PUMP_INTFINFO_HAS_LEASE)) {
+- pumpDisableInterface(intf->device);
++ pumpDisableInterface(intf);
+ syslog(LOG_INFO, "disabling interface %s", intf->device);
+
+ return 0;
+@@ -1057,7 +1080,7 @@
+ if ((chptr = prepareRequest(&breq, s, intf->device, pumpUptime()))) {
+ close(s);
+ while (1) {
+- pumpDisableInterface(intf->device);
++ pumpDisableInterface(intf);
+ return 0;
+ }
+ }
+@@ -1072,6 +1095,7 @@
+ strlen(intf->hostname) + 1, intf->hostname);
+ } else {
+ gethostname(hostname, sizeof(hostname));
++ hostname[sizeof(hostname) - 1] = 0;
+ if (strcmp(hostname, "localhost") &&
+ strcmp(hostname, "localhost.localdomain")) {
+ addVendorCode(&breq, BOOTP_OPTION_HOSTNAME,
+@@ -1080,13 +1104,13 @@
+ }
+
+ serverAddr.sin_family = AF_INET;
+- serverAddr.sin_port = htons(BOOTP_SERVER_PORT); /* bootp server */
++ serverAddr.sin_port = bootp_server_port; /* bootp server */
+ serverAddr.sin_addr = intf->bootServer;
+
+- handleTransaction(s, NULL, &breq, &bresp, &serverAddr, NULL, 0,
+- -1, NORESPONSE);
++ handleTransaction(s, NULL, &breq, &bresp, (struct sockaddr *) &serverAddr,
++ sizeof(serverAddr), NULL, 0, 0, -1, NORESPONSE);
+
+- pumpDisableInterface(intf->device);
++ pumpDisableInterface(intf);
+ close(s);
+
+ if (intf->set & PUMP_NETINFO_HAS_HOSTNAME)
+@@ -1116,7 +1140,7 @@
+
+ if ((chptr = prepareRequest(&breq, s, intf->device, pumpUptime()))) {
+ close(s);
+- while (1); /* problem */
++ return 1;
+ }
+
+ messageType = DHCP_TYPE_REQUEST;
+@@ -1132,6 +1156,7 @@
+ intf->hostname);
+ } else {
+ gethostname(hostname, sizeof(hostname));
++ hostname[sizeof(hostname) - 1] = 0;
+ if (strcmp(hostname, "localhost") &&
+ strcmp(hostname, "localhost.localdomain")) {
+ addVendorCode(&breq, BOOTP_OPTION_HOSTNAME,
+@@ -1143,11 +1168,12 @@
+ addVendorCode(&breq, DHCP_OPTION_LEASE, 4, &i);
+
+ serverAddr.sin_family = AF_INET;
+- serverAddr.sin_port = htons(BOOTP_SERVER_PORT); /* bootp server */
++ serverAddr.sin_port = bootp_server_port; /* bootp server */
+ serverAddr.sin_addr = intf->bootServer;
+
+- if (handleTransaction(s, NULL, &breq, &bresp, &serverAddr, NULL, 0,
+- startTime, DHCP_TYPE_ACK)) {
++ if (handleTransaction(s, NULL, &breq, &bresp,
++ (struct sockaddr *) &serverAddr, sizeof(serverAddr),
++ NULL, 0, 0, startTime, DHCP_TYPE_ACK)) {
+ close(s);
+ return 1;
+ }
+@@ -1232,6 +1258,7 @@
+ if (!reqHostname) {
+ reqHostname = alloca(200);
+ gethostname(reqHostname, 200);
++ reqHostname[199] = 0;
+ if (!strcmp(reqHostname, "localhost") ||
+ !strcmp(reqHostname, "localhost.localdomain"))
+ reqHostname = NULL;
+@@ -1254,15 +1281,13 @@
+ struct pumpOverrideInfo * override) {
+ int s;
+ struct sockaddr_in serverAddr;
+- struct sockaddr_in clientAddr;
+- struct sockaddr_in broadcastAddr;
++ struct sockaddr_ll broadcastAddr;
+ struct bootpRequest breq, bresp;
+ char * chptr;
+ time_t startTime = pumpUptime();
+- int true = 1;
+- int ttl = 16;
+ char * saveDeviceName;
+ unsigned char messageType;
++ struct pumpOverrideInfo saveOverride;
+
+ /* If device is the same as intf->device, don't let the memset()
+ blow away the device name */
+@@ -1270,25 +1295,25 @@
+ strcpy(saveDeviceName, device);
+ device = saveDeviceName;
+
++ memcpy(&saveOverride, override, sizeof(*override));
++ override = &saveOverride;
++
+ memset(intf, 0, sizeof(*intf));
+ strcpy(intf->device, device);
+ intf->reqLease = reqLease;
+ intf->set |= PUMP_INTFINFO_HAS_REQLEASE;
++ memcpy(&intf->override, override, sizeof(*override));
+
+- s = socket(AF_INET, SOCK_DGRAM, 0);
++ /* Save these for later */
++ intf->flags = flags & PUMP_FLAG_WINCLIENTID;
++ if (override && (override->flags & OVERRIDE_FLAG_NOSETUP))
++ intf->flags |= PUMP_FLAG_NOSETUP;
++
++ s = socket(AF_PACKET, SOCK_DGRAM, ntohs(ETH_P_IP));
+ if (s < 0) {
+ return perrorstr("socket");
+ }
+
+- if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, &true, sizeof(true))) {
+- close(s);
+- return perrorstr("setsockopt");
+- }
+- if (setsockopt(s, SOL_IP, IP_TTL, &ttl, sizeof(ttl))) {
+- close(s);
+- return perrorstr("setsockopt");
+- }
+-
+ if (flags & PUMP_FLAG_NOCONFIG) {
+ if ((chptr = getInterfaceInfo(intf, s))) {
+ close(s);
+@@ -1301,7 +1326,7 @@
+
+ if ((chptr = prepareRequest(&breq, s, intf->device, startTime))) {
+ close(s);
+- pumpDisableInterface(intf->device);
++ pumpDisableInterface(intf);
+ return chptr;
+ }
+
+@@ -1318,19 +1343,10 @@
+ addVendorCode(&breq, DHCP_OPTION_CLASS_IDENTIFIER,
+ strlen(class) + 1, class);
+ }
+- memset(&clientAddr.sin_addr, 0, sizeof(&clientAddr.sin_addr));
+- clientAddr.sin_family = AF_INET;
+- clientAddr.sin_port = htons(BOOTP_CLIENT_PORT); /* bootp client */
+-
+- if (bind(s, (struct sockaddr *) &clientAddr, sizeof(clientAddr))) {
+- pumpDisableInterface(intf->device);
+- close(s);
+- return perrorstr("bind");
+- }
+
+ memset(&serverAddr,0,sizeof(serverAddr));
+ serverAddr.sin_family = AF_INET;
+- serverAddr.sin_port = htons(BOOTP_SERVER_PORT); /* bootp server */
++ serverAddr.sin_port = bootp_server_port; /* bootp server */
+
+ #if 0
+ /* seems like a good idea?? */
+@@ -1339,27 +1355,21 @@
+ #endif
+
+ memset(&broadcastAddr,0,sizeof(broadcastAddr));
+- broadcastAddr.sin_family = AF_INET;
+- broadcastAddr.sin_port = htons(BOOTP_SERVER_PORT);
+-
+-#if 0
+- /* this too! */
+- if (intf->set & PUMP_INTFINFO_HAS_BROADCAST)
+- broadcastAddr.sin_addr = intf->broadcast;
+-#endif
+-
+- memset(&broadcastAddr.sin_addr, 0xff,
+- sizeof(broadcastAddr.sin_addr)); /* all 1's broadcast */
++ memset(&broadcastAddr.sll_addr, ~0, ETH_ALEN);
++ broadcastAddr.sll_halen = ETH_ALEN;
++ broadcastAddr.sll_ifindex = intf->ifindex;
++ broadcastAddr.sll_protocol = htons(ETH_P_IP);
+
+ syslog (LOG_DEBUG, "PUMP: sending discover\n");
+
+ if (override && (override->flags & OVERRIDE_FLAG_NOBOOTP))
+ syslog (LOG_DEBUG, "PUMP: Ignoring non-DHCP BOOTP responses\n");
+
+- if ((chptr = handleTransaction(s, override, &breq, &bresp, &broadcastAddr,
+- NULL, (override && (override->flags & OVERRIDE_FLAG_NOBOOTP))?0:1, startTime, DHCP_TYPE_OFFER))) {
++ if ((chptr = handleTransaction(s, override, &breq, &bresp,
++ (struct sockaddr *) &broadcastAddr,
++ sizeof(broadcastAddr), NULL, (override && (override->flags & OVERRIDE_FLAG_NOBOOTP))?0:1, 1, startTime, DHCP_TYPE_OFFER))) {
+ close(s);
+- pumpDisableInterface(intf->device);
++ pumpDisableInterface(intf);
+ return chptr;
+ }
+
+@@ -1378,17 +1388,19 @@
+
+ /* Send another DHCP_DISCOVER with the proper option list */
+ if ((chptr = handleTransaction(s, override, &breq, &bresp,
+- &broadcastAddr, NULL, 0,
++ (struct sockaddr *) &broadcastAddr,
++ sizeof(broadcastAddr),
++ NULL, 0, 1,
+ startTime, DHCP_TYPE_OFFER))) {
+ close(s);
+- pumpDisableInterface(intf->device);
++ pumpDisableInterface(intf);
+ return chptr;
+ }
+
+
+ if (dhcpMessageType(&bresp) != DHCP_TYPE_OFFER) {
+ close(s);
+- pumpDisableInterface(intf->device);
++ pumpDisableInterface(intf);
+ return "dhcp offer expected";
+ }
+
+@@ -1396,7 +1408,7 @@
+
+ if (getVendorCode(&bresp, DHCP_OPTION_SERVER, &serverAddr.sin_addr, sizeof(struct in_addr))) {
+ syslog (LOG_DEBUG, "DHCPOFFER didn't include server address");
+- intf->bootServer = broadcastAddr.sin_addr;
++ intf->bootServer.s_addr = INADDR_BROADCAST;
+ }
+
+ initVendorCodes(&breq);
+@@ -1409,10 +1421,12 @@
+ /* why do we need to use the broadcast address here? better reread the
+ spec! */
+ if ((chptr = handleTransaction(s, override, &breq, &bresp,
+- &broadcastAddr, NULL, 0,
++ (struct sockaddr *) &broadcastAddr,
++ sizeof(broadcastAddr),
++ NULL, 0, 1,
+ startTime, DHCP_TYPE_ACK))) {
+ close(s);
+- pumpDisableInterface(intf->device);
++ pumpDisableInterface(intf);
+ return chptr;
+ }
+
+@@ -1422,7 +1436,7 @@
+
+ if (getVendorCode(&bresp, DHCP_OPTION_SERVER, &intf->bootServer, sizeof(struct in_addr))) {
+ syslog (LOG_DEBUG, "DHCPACK didn't include server address");
+- intf->bootServer = broadcastAddr.sin_addr;
++ intf->bootServer.s_addr = INADDR_BROADCAST;
+ }
+
+ intf->set |= PUMP_INTFINFO_HAS_BOOTSERVER;
+@@ -1434,9 +1448,6 @@
+ if (flags & PUMP_FLAG_FORCEHNLOOKUP)
+ intf->set &= ~(PUMP_NETINFO_HAS_DOMAIN | PUMP_NETINFO_HAS_HOSTNAME);
+
+- /* Save these for later */
+- intf->flags = flags & PUMP_FLAG_WINCLIENTID;
+-
+ return NULL;
+ }
+
+@@ -1448,10 +1459,9 @@
+ }
+
+ void pumpInitOverride(struct pumpOverrideInfo * override) {
+- strcpy(override->intf.device, "MASTER");
++ strcpy(override->device, "MASTER");
+ override->timeout = DEFAULT_TIMEOUT;
+ override->numRetries = DEFAULT_NUM_RETRIES;
+- override->script = NULL;
+ }
+
+ /*
+@@ -1487,3 +1497,68 @@
+ return (time_t)secs;
+ }
+
++static void makeraw(struct ippkt *buf, const void *payload, size_t len) {
++ size_t total = sizeof(struct ip) + sizeof(struct udphdr) + len;
++
++ buf->ip.ip_v = 4;
++ buf->ip.ip_hl = 5;
++ buf->ip.ip_tos = IPTOS_LOWDELAY;
++ buf->ip.ip_len = htons(total);
++ buf->ip.ip_id = 0;
++ buf->ip.ip_off = 0;
++ buf->ip.ip_ttl = 16;
++ buf->ip.ip_p = IPPROTO_UDP;
++ buf->ip.ip_sum = 0;
++ buf->ip.ip_src.s_addr = INADDR_ANY;
++ buf->ip.ip_dst.s_addr = INADDR_BROADCAST;
++
++ buf->ip.ip_sum = wrapsum(checksum(&buf->ip, sizeof(buf->ip), 0));
++
++ buf->udp.source = bootp_client_port;
++ buf->udp.dest = bootp_server_port;
++ buf->udp.len = htons(sizeof(struct udphdr) + len);
++ buf->udp.check = 0;
++
++ buf->udp.check =
++ wrapsum(
++ checksum(
++ &buf->udp, sizeof(buf->udp),
++ checksum(
++ payload, len,
++ checksum(
++ &buf->ip.ip_src,
++ 2 * sizeof(buf->ip.ip_src),
++ IPPROTO_UDP +
++ (uint32_t)
++ ntohs(buf->udp.len)
++ )
++ )
++ )
++ );
++
++ memcpy(buf->payload, payload, len);
++}
++
++uint32_t checksum(const void *buf, size_t len, uint32_t sum) {
++ const char *p = buf;
++ size_t i;
++
++ for (i = 0; i < (len & ~1); i += 2) {
++ sum += ntohs(*(uint16_t *)(p + i));
++ if (sum > 0xffff)
++ sum -= 0xffff;
++ }
++
++ if (i < len) {
++ sum += p[i] << 8;
++ if (sum > 0xffff)
++ sum -= 0xffff;
++ }
++
++ return sum;
++}
++
++uint32_t wrapsum(uint32_t sum) {
++ sum = ~sum & 0xffff;
++ return htons(sum);
++}
+--- pump-0.8.24.orig/config.c
++++ pump-0.8.24/config.c
+@@ -101,8 +101,9 @@
+ }
+
+ *nextO = *override;
+- strcpy(nextO->intf.device, rest);
+- nextO->script = override->script ? strdup(override->script) : NULL;
++ strcpy(nextO->device, rest);
++ if (override->script[0])
++ strcpy(nextO->script, override->script);
+
+ (*lineNum)++;
+ if (readStanza(&next, overrideList, nextO, lineNum)) return 1;
+@@ -155,6 +156,8 @@
+
+ override->numRetries = num;
+ } else if (!strcmp(start, "domainsearch")) {
++ size_t len;
++
+ if (overrideList != override) {
+ parseError(*lineNum, "domainsearch directive may not occur "
+ "inside of device specification");
+@@ -169,12 +172,18 @@
+ return 1;
+ }
+
++ len = strlen(argv[0]);
++ if (len >= sizeof(override->searchPath)) {
++ parseError(*lineNum, "domainsearch directive is too long");
++ return 1;
++ }
++
+ /*
+ We don't free this as other configurations may have inherited
+ it. This could be the wrong decision, but leak would be tiny
+ so why worry?
+ */
+- override->searchPath = strdup(argv[0]);
++ memcpy(override->searchPath, argv[0], len + 1);
+ free(argv);
+ } else if (!strcmp(start, "nodns")) {
+ if (*rest) {
+@@ -200,7 +209,25 @@
+ return 1;
+ }
+ override->flags |= OVERRIDE_FLAG_NONISDOMAIN;
++ } else if (!strcmp(start, "nosetup")) {
++ if (*rest) {
++ parseError(*lineNum, "unexpected argument to nosetup directive");
++ return 1;
++ }
++ override->flags |=
++ OVERRIDE_FLAG_NOSETUP |
++ OVERRIDE_FLAG_NODNS |
++ OVERRIDE_FLAG_NOGATEWAY |
++ OVERRIDE_FLAG_NONISDOMAIN;
++ } else if (!strcmp(start, "noresolvconf")) {
++ if (*rest) {
++ parseError(*lineNum, "unexpected argument to noresolvconf directive");
++ return 1;
++ }
++ override->flags |= OVERRIDE_FLAG_NORESOLVCONF;
+ } else if (!strcmp(start, "script")) {
++ size_t len;
++
+ if (overrideList != override) {
+ parseError(*lineNum, "script directive may not occur "
+ "inside of device specification");
+@@ -214,7 +241,14 @@
+ "single argument");
+ return 1;
+ }
+- override->script = strdup(argv[0]);
++
++ len = strlen(argv[0]);
++ if (len >= sizeof(override->script)) {
++ parseError(*lineNum, "script directive is too long");
++ return 1;
++ }
++
++ memcpy(override->script, argv[0], len + 1);
+ free(argv);
+ } else {
+ char * error;
+@@ -245,7 +279,6 @@
+ if ((fd = open(configFile, O_RDONLY)) < 0) {
+ *overrides = calloc(sizeof(**overrides), 2);
+ pumpInitOverride(*overrides);
+- close(fd);
+ return 0;
+ }
+
+--- pump-0.8.24.orig/Makefile
++++ pump-0.8.24/Makefile
+@@ -6,7 +6,7 @@
+ USRLIBPATH = $(libdir)
+ INCPATH = $(includedir)
+ MAN8PATH = $(mandir)/man8
+-CFLAGS = -fPIC -I. -Wall -Werror -g $(RPM_OPT_FLAGS) -D__STANDALONE__ -DVERSION=\"$(VERSION)\"
++CFLAGS = $(DEB_CFLAGS) -I. -Wall -Werror -g $(RPM_OPT_FLAGS) -D__STANDALONE__ -DVERSION=\"$(VERSION)\" -D_GNU_SOURCE
+ CVSROOT = $(shell cat CVS/Root 2>/dev/null)
+
+ ARCH := $(patsubst i%86,i386,$(shell uname -m))
+--- pump-0.8.24.orig/pump.8
++++ pump-0.8.24/pump.8
+@@ -1,4 +1,5 @@
+ .\" Copyright 1999 Red Hat Software, Inc.
++.\" August 2004: Updated by Thomas Hood <jdthood@yahoo.co.uk>
+ .\"
+ .\" This man page is free documentation; you can redistribute it and/or modify
+ .\" it under the terms of the GNU General Public License as published by
+@@ -14,69 +15,120 @@
+ .\" along with this man page; if not, write to the Free Software
+ .\" Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ .\"
+-.TH PUMP 8 "December 07, 1999" "Linux" "Linux Administrator's Manual"
++.TH PUMP 8 "26 August 2004" "Linux" "Linux Administrator's Manual"
+ .SH NAME
+ pump \- configure network interface via BOOTP or DHCP protocol
+ .SH SYNOPSIS
+-/sbin/pump [-krRsd?] [-c \fIARG\fP] [-h \fIhostname\fP] [-i \fIiface\fP] [-l \fIhours\fP] [--lookup-hostname] [--usage]
++.B pump
++.BR "" [ \-krRsd ]
++.BR "" [ \-c | \-\-config\-file
++.IR FILE ]
++.BR "" [ \-h | \-\-hostname
++.IR HOSTNAME ]
++.BR "" [ \-i | \-\-interface
++.IR IFACE ]
++.BR "" [ \-l | \-\-lease
++.IR HOURS ]
++.BR "" [ \-\-lookup\-hostname ]
++.BR "" [ \-\-no\-dns "] [" \-\-no\-gateway "] [" \-\-no\-setup "] [" \-\-no\-resolvconf ]
++.BR "" [ \-\-release "] [" \-\-renew "] [" \-\-script =
++.IR ISCRIPT ]
++.BR "" [ \-\-status ]
++.BR "" [ \-\-win\-client\-ident ]
++.P
++.B pump
++.BR "" [ \-? | \-\-help "] [" \-\-usage ]
+ .SH DESCRIPTION
+-pump is a daemon that manages network interfaces that are
+-controlled by either the DHCP or BOOTP protocol.
+-
+-While pump may be started manually, it is normally started
+-automatically by the /sbin/ifup script for devices configured
+-via BOOTP or DHCP.
+-
+-Once pump is managing an interface, you can run pump to query
++.B pump
++is a daemon that manages network interfaces that are controlled
++by either the DHCP or BOOTP protocol.
++
++While
++.B pump
++may be started manually, it is normally started automatically by
++.BR ifup (8)
++for devices configured via BOOTP or DHCP.
++
++If
++.B pump
++is managing an interface, you can run it again to query
+ the status of that interface. For example,
+ .br
+-\f(CW/sbin/pump -i eth0 --status \fR
++ \f(CWpump \-i eth0 \-\-status\fR
+ .br
+ will print the current status of device eth0.
+-.SH "COMMAND-LINE OPTIONS"
++.SH "COMMAND LINE OPTIONS"
+ .TS
+ lB lB lB
+ lfCW lfCW l.
+ switch long option description
+-.TH
+--c --config-file=ARG Configuration file to use instead of
+- /etc/pump.conf
+--h --hostname=hostname Hostname to request
+--i --interface=iface Interface to configure (normally eth0)
+--k --kill Kill daemon (and disable all interfaces)
+--l --lease=hours Lease time to request (in hours)
+- --lookup-hostname Always look up hostname and domain in DNS
+--r --release Release interface
+--R --renew Force immediate lease renewal
+--s --status Display interface status
+--d --no-dns Don't update resolv.conf
+- --no-gateway Don't configurate a default route for this interface
+- --win-client-id Specify a Windows-like client identifier
+--? --help Show this help message
+- --usage Display brief usage message
++\-? \-\-help Show this help message
++\-c \-\-config\-file=\fIFILE\fR Get configuration from \fIFILE\fR instead of /etc/pump.conf
++\-d \-\-no\-dns Don't update DNS resolver configuration
++\-h \-\-hostname=\fIHOSTNAME\fR Request \fIHOSTNAME\fR
++\-i \-\-interface=\fIIFACE\fR Manage \fIIFACE\fR rather than eth0
++\-k \-\-kill Kill daemon (and disable all interfaces)
++\-l \-\-lease=\fIHOURS\fR Request least time of \fIHOURS\fR
++ \-\-lookup\-hostname Look up hostname in DNS
++\-R \-\-renew Renew lease immediately
++\-r \-\-release Release interface
++ \-\-no\-gateway Don't configurate a default route for this interface
++ \-\-no\-resolvconf Don't use the \fBresolvconf\fR program to update resolv.conf
++ \-\-no\-setup Don't set up anything
++ \-\-script=\fISCRIPT\fR Call \fISCRIPT\fR (or null string to disable)
++\-s \-\-status Display interface status
++ \-\-usage Display a brief usage message
++ \-\-win\-client\-ident Specify a Windows(tm)-like client identifier
+ .TE
+-.SH LOGGING
+-Pump logs a good deal of information to syslog, much of it at the DEBUG
+-level. If you're having trouble, it's a good idea to turn up syslog's logging
+-level.
+-
+-.SH CONFIG FILE
+-Pump supports a simple configuration file which lets you tune its behavior.
+-By default, it looks at \fI/etc/pump.conf\fR, though the \fB-c\fR option
+-lets you override that.
+-
+-The configuration file is line oriented, and most line contains a
+-directive followed by zero or more arguments. Arguments are handled
+-similar to how shells handle command arguments, allowing the use of
+-quotes and backslash escapes. Comments are allowed, and must begin with
+-a # character, and spaces and tabs are ignored.
+-
+-Directives may be specified at two levels, global and specific. Global
+-directives change pump's behavior for all of the devices which it manages,
+-while specific directives change pump's behavior for a single device.
++.SH "OPTION NOTES"
++The
++.B \-\-lookup\-hostname
++option causes
++.B pump
++to ignore the host and domain names returned by the server
++and instead
++to look these up in DNS using the IP address of the interface.
++The name that is looked up is used in forming the
++.B search
++line in the resolv.conf file.
++Thus, if either the
++.B \-\-no\-dns
++or
++.B domainsearch
++option is used then
++.B \-\-lookup\-hostname
++has no effect.
++.P
++Note that
++.B pump
++itself never sets the computer's hostname.
++
++.SH "CONFIGURATION FILE"
++You can tune the behavior of
++.B pump
++using a configuration file.
++By default
++.B pump
++reads \fI/etc/pump.conf\fR but you can change this using the
++\fB\-\-config\-file\fR option.
++
++The configuration file is line-oriented.
++Most lines contain a directive followed by zero or more arguments.
++Arguments are handled similarly to how shells handle command arguments,
++allowing the use of quotes and backslash escapes.
++Comments are allowed, and must begin with a # character.
++Spaces and tabs are ignored.
++
++Directives may be specified at two levels: global and specific.
++Global directives change
++.BR pump 's
++behavior for all of the devices that it manages
++whereas specific directives change
++.BR pump 's
++behavior for a single device.
+ Later directives always override earlier ones.
+
+-Here is an example /etc/pump.conf: