aboutsummaryrefslogtreecommitdiffstats
path: root/interface.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>1996-12-29 09:49:44 +0000
committerEric S. Raymond <esr@thyrsus.com>1996-12-29 09:49:44 +0000
commitff4d046f39e3ed641bc5d9925f61d48010c56bfb (patch)
tree66a8dc42dcd814427ac00ae5c155b00c7ec0a6ae /interface.c
parenta81fbf21d9da4b643125eef4c2353529839331cb (diff)
downloadfetchmail-ff4d046f39e3ed641bc5d9925f61d48010c56bfb.tar.gz
fetchmail-ff4d046f39e3ed641bc5d9925f61d48010c56bfb.tar.bz2
fetchmail-ff4d046f39e3ed641bc5d9925f61d48010c56bfb.zip
After George Sipe's changes.
svn path=/trunk/; revision=704
Diffstat (limited to 'interface.c')
-rw-r--r--interface.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/interface.c b/interface.c
index 85ca85d8..dce5267e 100644
--- a/interface.c
+++ b/interface.c
@@ -14,13 +14,11 @@
#ifdef linux
#include <stdio.h>
-#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <linux/netdevice.h>
-#include <errno.h>
#include "fetchmail.h"
static struct in_addr interface_address;
@@ -47,9 +45,8 @@ static int _get_ifinfo_(int socket_fd, FILE *stats_file, const char *ifname,
/* see if the interface is up */
strcpy(request.ifr_name, ifname);
- errno = 0;
if (ioctl(socket_fd, SIOCGIFFLAGS, &request) < 0)
- error(PS_IOERR, errno, "interface status check failed");
+ return(FALSE);
if (!(request.ifr_flags & IFF_RUNNING))
return(FALSE);
@@ -106,7 +103,9 @@ static int get_ifinfo(const char *ifname, ifinfo_t *ifinfo)
void interface_parse(void)
{
+ int socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
char *cp1, *cp2;
+ struct ifreq request;
/* in the event we point to a null string, make pointer null */
if (interface && !*interface)
@@ -123,6 +122,13 @@ void interface_parse(void)
(void) error(PS_SYNTAX, 0, "missing IP interface address");
*cp1++ = '\000';
+ /* validate specified interface exists */
+ strcpy(request.ifr_name, interface);
+ if (ioctl(socket_fd, SIOCGIFFLAGS, &request) < 0)
+ (void) error(PS_SYNTAX, 0, "no such interface device '%s'",
+ interface);
+ close(socket_fd);
+
/* find and isolate just the netmask */
if (!(cp2 = strchr(cp1, '/')))
cp2 = "255.255.255.255";