1.1 --- a/src/eth_resolv.h Sun Oct 18 11:19:15 2009 +0200
1.2 +++ b/src/eth_resolv.h Sun Oct 18 13:41:18 2009 +0200
1.3 @@ -31,9 +31,6 @@
1.4
1.5 /* Functions in resolv.c */
1.6
1.7 -/* get_tcp_port returns the TCP port name or "%d" if not found */
1.8 -extern char *get_tcp_port (u_int port);
1.9 -
1.10 /* get_ether_name returns the logical name if found in ethers files.
1.11 if only_ethers is false and the name is NOT in the file, it returns
1.12 "<vendor>_%02x:%02x:%02x" if the vendor code is known else
2.1 --- a/src/names.c Sun Oct 18 11:19:15 2009 +0200
2.2 +++ b/src/names.c Sun Oct 18 13:41:18 2009 +0200
2.3 @@ -24,6 +24,7 @@
2.4 #include "eth_resolv.h"
2.5 #include "names_netbios.h"
2.6 #include "protocols.h"
2.7 +#include "datastructs.h"
2.8 #include "util.h"
2.9
2.10 typedef struct
2.11 @@ -263,7 +264,10 @@
2.12 numeric = ether_to_str (nt->node_id.addr.eth);
2.13
2.14 /* solved is not NULL only if the address is in ethers file */
2.15 - solved = get_ether_name (nt->node_id.addr.eth, TRUE);
2.16 + if (pref.name_res)
2.17 + solved = get_ether_name (nt->node_id.addr.eth, TRUE);
2.18 + else
2.19 + solved = NULL;
2.20
2.21 add_name (numeric, solved, &nt->node_id, nt);
2.22
2.23 @@ -372,6 +376,7 @@
2.24 if (pref.mode == TCP)
2.25 {
2.26 gchar *numeric_name, *resolved_name;
2.27 +
2.28 if (nt->dir == OUTBOUND)
2.29 fill_node_id(&nt->node_id, TCP, nt, -8, 0);
2.30 else
2.31 @@ -381,12 +386,20 @@
2.32 ip_to_str(nt->node_id.addr.tcp4.host),
2.33 nt->node_id.addr.tcp4.port);
2.34
2.35 - resolved_name = g_strdup_printf("%s:%s",
2.36 - dns_lookup (
2.37 - pntohl (nt->node_id.addr.tcp4.host),
2.38 - TRUE),
2.39 - get_tcp_port(nt->node_id.addr.tcp4.port)
2.40 - );
2.41 + if (pref.name_res)
2.42 + {
2.43 + const gchar *dnsname;
2.44 + const port_service_t *port;
2.45 + dnsname = dns_lookup (pntohl (nt->node_id.addr.tcp4.host), TRUE);
2.46 + port = services_tcp_find(nt->node_id.addr.tcp4.port);
2.47 + if (port)
2.48 + resolved_name = g_strdup_printf("%s:%s", dnsname, port->name);
2.49 + else
2.50 + resolved_name = g_strdup_printf("%s:%d", dnsname,
2.51 + nt->node_id.addr.tcp4.port);
2.52 + }
2.53 + else
2.54 + resolved_name = NULL;
2.55
2.56 add_name (numeric_name, resolved_name, &nt->node_id, nt);
2.57
3.1 --- a/src/resolv.c Sun Oct 18 11:19:15 2009 +0200
3.2 +++ b/src/resolv.c Sun Oct 18 13:41:18 2009 +0200
3.3 @@ -2,12 +2,6 @@
3.4 * Routines for network object lookup
3.5 * $Id$
3.6 *
3.7 - * Originally written by Laurent Deniel <deniel@worldnet.fr>
3.8 - * Adapted to etherape by Juan Toledo <toledo@users.sourceforge.net>
3.9 - *
3.10 - * Each of my changes (Juan) is marked by JTC. This is so
3.11 - * because as I need more features, I will be needing more of the file.
3.12 - *
3.13 * This program is free software; you can redistribute it and/or
3.14 * modify it under the terms of the GNU General Public License
3.15 * as published by the Free Software Foundation; either version 2
3.16 @@ -23,6 +17,12 @@
3.17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3.18 */
3.19
3.20 +/*
3.21 + * Originally written by Laurent Deniel <deniel@worldnet.fr>
3.22 + * Adapted to etherape by Juan Toledo <toledo@users.sourceforge.net>
3.23 + * Further changes by Riccardo Ghetta <bchiara@users.sourceforge.net>
3.24 + */
3.25 +
3.26 #ifdef HAVE_CONFIG_H
3.27 #include "config.h"
3.28 #endif
3.29 @@ -57,19 +57,13 @@
3.30 #include <sys/socket.h>
3.31 #endif
3.32
3.33 -#ifdef AVOID_DNS_TIMEOUT
3.34 -#include <setjmp.h>
3.35 -#endif
3.36 -
3.37 #ifdef NEED_INET_V6DEFS_H
3.38 #include "inet_v6defs.h"
3.39 #endif
3.40
3.41 #include <glib.h>
3.42 #include "globals.h"
3.43 -#include "eth_resolv.h" /* JTC name space conflict */
3.44 #include "util.h"
3.45 -#include "dns.h"
3.46
3.47 #define EPATH_ETHERS "/etc/ethers"
3.48 #define EPATH_MANUF DATAFILE_DIR "/manuf"
3.49 @@ -85,17 +79,6 @@
3.50 #define HASHMANUFSIZE 256
3.51 #define HASHPORTSIZE 256
3.52
3.53 -/* hash table used for host and port lookup */
3.54 -
3.55 -typedef struct hashname
3.56 -{
3.57 - u_int addr;
3.58 - char name[MAXNAMELEN];
3.59 - struct hashname *next;
3.60 -}
3.61 -hashname_t;
3.62 -
3.63 -
3.64 /* hash tables used for ethernet and manufacturer lookup */
3.65
3.66 typedef struct hashmanuf
3.67 @@ -124,7 +107,6 @@
3.68 }
3.69 ether_t;
3.70
3.71 -static hashname_t *tcp_port_table[HASHPORTSIZE];
3.72 static hashmanuf_t *manuf_table[HASHMANUFSIZE];
3.73 static hashether_t *eth_table[HASHETHSIZE];
3.74
3.75 @@ -140,80 +122,6 @@
3.76 /* first resolving call */
3.77
3.78 /*
3.79 - * Local function definitions
3.80 - */
3.81 -
3.82 -
3.83 -static char *
3.84 -serv_name_lookup (u_int port, u_int proto)
3.85 -{
3.86 -
3.87 - hashname_t *tp;
3.88 - hashname_t **table;
3.89 - char *serv_proto = NULL;
3.90 - struct servent *servp;
3.91 - int i;
3.92 -
3.93 - switch (proto)
3.94 - {
3.95 - case IPPROTO_TCP:
3.96 - table = tcp_port_table;
3.97 - serv_proto = "tcp";
3.98 - break;
3.99 - default:
3.100 - /* not yet implemented */
3.101 - return NULL;
3.102 - /*NOTREACHED */
3.103 - break;
3.104 - } /* proto */
3.105 -
3.106 - i = port & (HASHPORTSIZE - 1);
3.107 - tp = table[i & (HASHPORTSIZE - 1)];
3.108 -
3.109 - if (tp == NULL)
3.110 - {
3.111 - tp = table[i & (HASHPORTSIZE - 1)] =
3.112 - (hashname_t *) g_malloc (sizeof (hashname_t));
3.113 - g_assert(tp);
3.114 - }
3.115 - else
3.116 - {
3.117 - while (1)
3.118 - {
3.119 - if (tp->addr == port)
3.120 - {
3.121 - return tp->name;
3.122 - }
3.123 - if (tp->next == NULL)
3.124 - {
3.125 - tp->next = (hashname_t *) g_malloc (sizeof (hashname_t));
3.126 - g_assert(tp->next);
3.127 - tp = tp->next;
3.128 - break;
3.129 - }
3.130 - tp = tp->next;
3.131 - }
3.132 - }
3.133 -
3.134 - /* fill in a new entry */
3.135 - tp->addr = port;
3.136 - tp->next = NULL;
3.137 -
3.138 - if ((servp = getservbyport (htons (port), serv_proto)) == NULL)
3.139 - {
3.140 - /* unknown port */
3.141 - snprintf (tp->name, MAXNAMELEN, "%d", port);
3.142 - }
3.143 - else
3.144 - safe_strncpy (tp->name, servp->s_name, MAXNAMELEN);
3.145 -
3.146 - return (tp->name);
3.147 -
3.148 -} /* serv_name_lookup */
3.149 -
3.150 -
3.151 -
3.152 -/*
3.153 * Miscellaneous functions
3.154 */
3.155
3.156 @@ -587,13 +495,6 @@
3.157
3.158 } /* eth_name_lookup */
3.159
3.160 -extern char *
3.161 -get_tcp_port (u_int port)
3.162 -{
3.163 - return serv_name_lookup (port, IPPROTO_TCP);
3.164 -} /* get_tcp_port */
3.165 -
3.166 -
3.167 extern const char *
3.168 get_ether_name (const u_char * addr, gboolean only_ethers)
3.169 {
4.1 --- a/src/util.c Sun Oct 18 11:19:15 2009 +0200
4.2 +++ b/src/util.c Sun Oct 18 13:41:18 2009 +0200
4.3 @@ -185,7 +185,6 @@
4.4 * by Gerald Combs */
4.5
4.6 /* Output has to be copied elsewhere */
4.7 -/* TODO should I dump this funtion now that I have dns_lookup? */
4.8 const gchar *
4.9 ip_to_str (const guint8 * ad)
4.10 {
4.11 @@ -241,7 +240,7 @@
4.12 * the resulting string is 5 bytes shorter)
4.13 */
4.14
4.15 -const gchar *
4.16 +static const gchar *
4.17 ether_to_str_punct (const guint8 * ad, char punct)
4.18 {
4.19 static gchar str[3][18];
5.1 --- a/src/util.h Sun Oct 18 11:19:15 2009 +0200
5.2 +++ b/src/util.h Sun Oct 18 13:41:18 2009 +0200
5.3 @@ -49,7 +49,6 @@
5.4 /* utility functions */
5.5 const gchar *ip_to_str (const guint8 * ad);
5.6 const gchar *ether_to_str (const guint8 * ad);
5.7 - const gchar *ether_to_str_punct (const guint8 * ad, char punct);
5.8
5.9 #ifdef __cplusplus
5.10 }