1
0
mirror of https://github.com/nmap/nmap.git synced 2026-01-27 16:49:01 +00:00

Define our own servent/protoent structs with const members.

This commit is contained in:
dmiller
2022-09-12 16:59:35 +00:00
parent d8864b6d5a
commit cc5cd5f2c6
6 changed files with 26 additions and 17 deletions

View File

@@ -504,7 +504,7 @@ void printportoutput(const Target *currenths, const PortList *plist) {
char serviceinfo[64];
int i;
int first = 1;
struct protoent *proto;
struct nprotoent *proto;
Port *current;
Port port;
char hostname[1200];
@@ -2282,7 +2282,7 @@ static void printtraceroute_normal(const Target *currenths) {
log_write(LOG_PLAIN, "TRACEROUTE (using port %d/%s)\n",
probe.pd.sctp.dport, proto2ascii_lowercase(probe.proto));
} else if (probe.type == PS_ICMP || probe.type == PS_ICMPV6 || probe.type == PS_PROTO) {
struct protoent *proto = nmap_getprotbynum(probe.proto);
struct nprotoent *proto = nmap_getprotbynum(probe.proto);
log_write(LOG_PLAIN, "TRACEROUTE (using proto %d/%s)\n",
probe.proto, proto ? proto->p_name : "unknown");
} else if (probe.type == PS_NONE) {
@@ -2389,7 +2389,7 @@ static void printtraceroute_xml(const Target *currenths) {
xml_attribute("port", "%d", probe.pd.sctp.dport);
xml_attribute("proto", "%s", proto2ascii_lowercase(probe.proto));
} else if (probe.type == PS_ICMP || probe.type == PS_PROTO) {
const struct protoent *proto = nmap_getprotbynum(probe.proto);
const struct nprotoent *proto = nmap_getprotbynum(probe.proto);
if (proto == NULL)
xml_attribute("proto", "%d", probe.proto);
else

View File

@@ -141,7 +141,7 @@ void Port::getNmapServiceName(char *namebuf, int buflen) const {
if (service != NULL && service->name != NULL) {
service_name = service->name;
} else {
const struct servent *service;
const struct nservent *service;
service = nmap_getservbyport(portno, IPPROTO2STR(proto));
if (service != NULL)
@@ -259,13 +259,13 @@ void PortList::getServiceDeductions(u16 portno, int protocol, struct serviceDedu
port = lookupPort(portno, protocol);
if (port == NULL || port->service == NULL) {
const struct servent *service;
const struct nservent *service;
/* Look up the service name. */
*sd = serviceDeductions();
service = nmap_getservbyport(portno, IPPROTO2STR(protocol));
if (service != NULL)
sd->name = service->s_name;
sd->name = strdup(service->s_name);
else
sd->name = NULL;
sd->name_confidence = 3;
@@ -329,7 +329,7 @@ void PortList::setServiceProbeResults(u16 portno, int protocol,
/* PROBESTATE_FINISHED_NOMATCH, PROBESTATE_EXCLUDED, PROBESTATE_INCOMPLETE.
Just look up the service name if none is provided. */
if (sname == NULL) {
const struct servent *service;
const struct nservent *service;
service = nmap_getservbyport(portno, IPPROTO2STR(protocol));
if (service != NULL)
sname = service->s_name;

View File

@@ -128,7 +128,7 @@ static int nmap_protocols_init() {
numipprots++;
current = (struct protocol_list *) cp_alloc(sizeof(struct protocol_list));
current->protoent = (struct protoent *) cp_alloc(sizeof(struct protoent));
current->protoent = (struct nprotoent *) cp_alloc(sizeof(struct nprotoent));
current->next = NULL;
if (previous == NULL) {
protocol_table[protno % PROTOCOL_TABLE_SIZE] = current;
@@ -137,7 +137,6 @@ static int nmap_protocols_init() {
}
current->protoent->p_name = cp_strdup(protocolname);
current->protoent->p_proto = protno;
current->protoent->p_aliases = NULL;
}
fclose(fp);
protocols_initialized = 1;
@@ -172,7 +171,7 @@ int addprotocolsfromservmask(char *mask, u8 *porttbl) {
}
struct protoent *nmap_getprotbynum(int num) {
struct nprotoent *nmap_getprotbynum(int num) {
struct protocol_list *current;
if (nmap_protocols_init() == -1)

View File

@@ -77,13 +77,18 @@
#define PROTOCOL_TABLE_SIZE 256
struct nprotoent {
const char *p_name;
short p_proto;
};
struct protocol_list {
struct protoent *protoent;
struct nprotoent *protoent;
struct protocol_list *next;
};
int addprotocolsfromservmask(char *mask, u8 *porttbl);
struct protoent *nmap_getprotbynum(int num);
struct nprotoent *nmap_getprotbynum(int num);
#define MAX_IPPROTOSTRLEN 4
#define IPPROTO2STR(p) \

View File

@@ -89,8 +89,8 @@ struct port_spec {
}
};
/* This is a servent augmented by a frequency ratio. */
struct service_node : public servent {
/* This is a nservent augmented by a frequency ratio. */
struct service_node : public nservent {
public:
double ratio;
};
@@ -228,7 +228,6 @@ static int nmap_services_init() {
sn.s_name = cp_strdup(servicename);
sn.s_port = portno;
sn.s_proto = cp_strdup(proto);
sn.s_aliases = NULL;
sn.ratio = ratio;
service_table[ps] = sn;
@@ -289,7 +288,7 @@ int addportsfromservmask(const char *mask, u8 *porttbl, int range_type) {
const struct servent *nmap_getservbyport(int port, const char *proto) {
const struct nservent *nmap_getservbyport(int port, const char *proto) {
std::map<port_spec, service_node>::const_iterator i;
port_spec ps;

View File

@@ -74,8 +74,14 @@
#define SERVICE_TABLE_SIZE 1024
struct nservent {
const char *s_name;
const char *s_proto;
short s_port;
};
int addportsfromservmask(const char *mask, u8 *porttbl, int range_type);
const struct servent *nmap_getservbyport(int port, const char *proto);
const struct nservent *nmap_getservbyport(int port, const char *proto);
void gettoppts(double level, const char *portlist, struct scan_lists * ports, const char *exclude_list = NULL);
void free_services();