Commit c9014df8 authored by Phil Blundell's avatar Phil Blundell

Take the netmask into account when printing routes (previously it

was hardwired as 255.255.255.0!)

Not very pretty I admit.
parent 86229c58
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* support functions for the net-tools. * support functions for the net-tools.
* (NET-3 base distribution). * (NET-3 base distribution).
* *
* Version: $Id: inet.c,v 1.8 1999/01/05 20:53:33 philip Exp $ * Version: $Id: inet.c,v 1.9 1999/03/02 21:09:14 philip Exp $
* *
* Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
* Copyright 1993 MicroWalt Corporation * Copyright 1993 MicroWalt Corporation
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
*960219 {1.25} Bernd Eckenfels : extern int h_errno *960219 {1.25} Bernd Eckenfels : extern int h_errno
*960329 {1.26} Bernd Eckenfels : resolve 255.255.255.255 *960329 {1.26} Bernd Eckenfels : resolve 255.255.255.255
*980101 {1.27} Bernd Eckenfels : resolve raw sockets in /etc/protocols *980101 {1.27} Bernd Eckenfels : resolve raw sockets in /etc/protocols
*990302 {1.28} Phil Blundell : add netmask to INET_rresolve
* *
* This program is free software; you can redistribute it * This program is free software; you can redistribute it
* and/or modify it under the terms of the GNU General * and/or modify it under the terms of the GNU General
...@@ -104,7 +105,8 @@ static int INET_resolve(char *name, struct sockaddr_in *sin) ...@@ -104,7 +105,8 @@ static int INET_resolve(char *name, struct sockaddr_in *sin)
} }
static int INET_rresolve(char *name, struct sockaddr_in *sin, int numeric) static int INET_rresolve(char *name, struct sockaddr_in *sin, int numeric,
unsigned int netmask)
{ {
struct hostent *ent; struct hostent *ent;
struct netent *np; struct netent *np;
...@@ -148,7 +150,7 @@ static int INET_rresolve(char *name, struct sockaddr_in *sin, int numeric) ...@@ -148,7 +150,7 @@ static int INET_rresolve(char *name, struct sockaddr_in *sin, int numeric)
host_ad = ntohl(ad); host_ad = ntohl(ad);
np = NULL; np = NULL;
ent = NULL; ent = NULL;
if ((host_ad & 0xFF) != 0) { if ((ad & (~ netmask)) != 0) {
ent = gethostbyaddr((char *) &ad, 4, AF_INET); ent = gethostbyaddr((char *) &ad, 4, AF_INET);
if (ent != NULL) if (ent != NULL)
strcpy(name, ent->h_name); strcpy(name, ent->h_name);
...@@ -192,7 +194,21 @@ static char *INET_sprint(struct sockaddr *sap, int numeric) ...@@ -192,7 +194,21 @@ static char *INET_sprint(struct sockaddr *sap, int numeric)
if (sap->sa_family == 0xFFFF || sap->sa_family == 0) if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
return safe_strncpy(buff, _("[NONE SET]"), sizeof(buff)); return safe_strncpy(buff, _("[NONE SET]"), sizeof(buff));
if (INET_rresolve(buff, (struct sockaddr_in *) sap, numeric) != 0) if (INET_rresolve(buff, (struct sockaddr_in *) sap, numeric,
0xffffff00) != 0)
return (NULL);
return (buff);
}
char *INET_sprintmask(struct sockaddr *sap, int numeric,
unsigned int netmask)
{
static char buff[128];
if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
return safe_strncpy(buff, _("[NONE SET]"), sizeof(buff));
if (INET_rresolve(buff, (struct sockaddr_in *) sap, numeric,
netmask) != 0)
return (NULL); return (NULL);
return (buff); return (buff);
} }
......
/* /*
$Id: inet_gr.c,v 1.10 1999/01/05 20:53:43 philip Exp $ $Id: inet_gr.c,v 1.11 1999/03/02 21:09:15 philip Exp $
Modifications: Modifications:
1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets 1998-07-01 - Arnaldo Carvalho de Melo - GNU gettext instead of catgets
...@@ -31,13 +31,14 @@ ...@@ -31,13 +31,14 @@
#include "proc.h" #include "proc.h"
extern struct aftype inet_aftype; extern struct aftype inet_aftype;
extern char *INET_sprintmask(struct sockaddr *sap, int numeric,
unsigned int netmask);
int rprint_fib(int ext, int numeric) int rprint_fib(int ext, int numeric)
{ {
char buff[1024], iface[16], flags[64]; char buff[1024], iface[16], flags[64];
char gate_addr[128], net_addr[128]; char gate_addr[128], net_addr[128];
char mask_addr[128]; char mask_addr[128];
struct sockaddr snet;
int num, iflags, metric, refcnt, use, mss, window, irtt; int num, iflags, metric, refcnt, use, mss, window, irtt;
FILE *fp = fopen(_PATH_PROCNET_ROUTE, "r"); FILE *fp = fopen(_PATH_PROCNET_ROUTE, "r");
char *fmt; char *fmt;
...@@ -83,6 +84,9 @@ int rprint_fib(int ext, int numeric) ...@@ -83,6 +84,9 @@ int rprint_fib(int ext, int numeric)
return 1; return 1;
while (fgets(buff, 1023, fp)) { while (fgets(buff, 1023, fp)) {
struct sockaddr snet_target, snet_gateway, snet_mask;
struct sockaddr_in *sin_netmask;
num = sscanf(buff, fmt, num = sscanf(buff, fmt,
iface, net_addr, gate_addr, iface, net_addr, gate_addr,
&iflags, &refcnt, &use, &metric, mask_addr, &iflags, &refcnt, &use, &metric, mask_addr,
...@@ -91,18 +95,24 @@ int rprint_fib(int ext, int numeric) ...@@ -91,18 +95,24 @@ int rprint_fib(int ext, int numeric)
continue; continue;
/* Fetch and resolve the target address. */ /* Fetch and resolve the target address. */
(void) inet_aftype.input(1, net_addr, &snet); (void) inet_aftype.input(1, net_addr, &snet_target);
strcpy(net_addr, inet_aftype.sprint(&snet, (numeric | 0x8000)));
net_addr[15] = '\0';
/* Fetch and resolve the gateway address. */ /* Fetch and resolve the gateway address. */
(void) inet_aftype.input(1, gate_addr, &snet); (void) inet_aftype.input(1, gate_addr, &snet_gateway);
strcpy(gate_addr, inet_aftype.sprint(&snet, numeric));
gate_addr[15] = '\0';
/* Fetch and resolve the genmask. */ /* Fetch and resolve the genmask. */
(void) inet_aftype.input(1, mask_addr, &snet); (void) inet_aftype.input(1, mask_addr, &snet_mask);
strcpy(mask_addr, inet_aftype.sprint(&snet, 1));
sin_netmask = (struct sockaddr_in *)&snet_mask;
strcpy(net_addr, INET_sprintmask(&snet_target,
(numeric | 0x8000),
sin_netmask->sin_addr.s_addr));
net_addr[15] = '\0';
strcpy(gate_addr, inet_aftype.sprint(&snet_gateway, numeric));
gate_addr[15] = '\0';
strcpy(mask_addr, inet_aftype.sprint(&snet_mask, 1));
mask_addr[15] = '\0'; mask_addr[15] = '\0';
/* Decode the flags. */ /* Decode the flags. */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment