--- a/dhcping.c
+++ b/dhcping.c
@@ -33,6 +33,7 @@
#include <sys/time.h>
#include <sys/uio.h>
#include <netinet/in.h>
+#include <net/if.h>
#include <unistd.h>
#include <netdb.h>
#include <stdio.h>
@@ -65,10 +66,16 @@
int _serveripaddress;
int inform,request,verbose,quiet;
-char *ci,*gi,*server,*hw;
+char *ci,*gi,*server,*hw,*iface;
unsigned char serveridentifier[4];
int maxwait=3;
+static void usage(void)
+{
+ printf("dhcping -c ciaddr -g giaddr -h chaddr <-r|-i> -s server -t maxwait -v -q [dev]\n");
+ exit(1);
+}
+
void doargs(int argc,char **argv) {
int ch;
@@ -76,10 +83,10 @@
ci=gi="0.0.0.0";
server="255.255.255.255";
hw="00:00:00:00:00:00";
+ iface=NULL;
if (argc==1) {
- printf("dhcping -c ciaddr -g giaddr -h chaddr -r -s server -t maxwait -i -v -q\n");
- exit(1);
+ usage();
}
while ((ch = getopt(argc,argv,"c:g:h:iqrs:t:v"))>0) {
@@ -101,6 +108,10 @@
exit(1);
}
+ if (argc-optind>1) usage();
+
+ if (argc>optind) iface=argv[optind];
+
// DHCPREQUEST is by default.
if (!inform) request=1;
}
@@ -207,6 +218,13 @@
exit(1);
}
+ if (iface) {
+ if (setsockopt(dhcp_socket,SOL_SOCKET,SO_BINDTODEVICE, iface, strnlen(iface, IFNAMSIZ)) < 0) {
+ perror ("dhcp_socket/setsockopt: SO_BINDTODEVICE");
+ exit(1);
+ }
+ }
+
if ((clientent=getservbyname("bootpc",0))==NULL) {
perror("getservbyname: bootpc");
exit(1);
--- a/dhcping.8
+++ b/dhcping.8
@@ -191,12 +191,13 @@
\fBdhcping\fR \- send a DHCP request to DHCP server to see if it's up and running
.SH "SYNOPSIS"
\fBdhcping\fR
-[\fB\-v\fR] [\fB\-q\fR] [\fB\-i\fR] [\fB\-r\fR]
-\fB\-t\fR \fImaxwait\fR
-\fB\-c\fR \fIclient-IP\-address\fR
-\fB\-s\fR \fIserver-IP\-address\fR
-\fB\-h\fR \fIclient-hardware-address\fR
+[\fB\-v\fR] [\fB\-q\fR] [\fB\-i\fR|\fB\-r\fR]
+[\fB\-t\fR \fImaxwait\fR]
+[\fB\-c\fR \fIclient-IP\-address\fR]
+[\fB\-s\fR \fIserver-IP\-address\fR]
+[\fB\-h\fR \fIclient-hardware-address\fR]
[\fB\-g\fR \fIgateway-IP\-address\fR]
+[\fIinterface\fR]
.SH "DESCRIPTION"
This command allows the system administrator to check if a remote
DHCP server is still functioning.
@@ -224,6 +225,8 @@
.Ip "\fB\-g\fR \fIgateway-\s-1IP\s0\-address\fR" 5
Use this \s-1IP\s0 address for the gateway \s-1IP\s0 address in the \s-1DHCP\s0 packet.
This option is currently broken.
+.Ip "\fIinterface\fR" 5
+Interface to use (e.g. "eth0")
.SH "RETURN VALUES"
If everything goes okay, it returns 0. If there went something
wrong, it returns 1.