1
0
mirror of https://github.com/nmap/nmap.git synced 2026-01-23 14:49:02 +00:00

Use const. New function nmap_getprotbyname()

This commit is contained in:
dmiller
2022-09-16 01:10:18 +00:00
parent 721912c113
commit 6c6d4e33b5
3 changed files with 17 additions and 4 deletions

View File

@@ -504,7 +504,7 @@ void printportoutput(const Target *currenths, const PortList *plist) {
char serviceinfo[64];
int i;
int first = 1;
struct nprotoent *proto;
const 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 nprotoent *proto = nmap_getprotbynum(probe.proto);
const 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) {

View File

@@ -181,7 +181,7 @@ int addprotocolsfromservmask(char *mask, u8 *porttbl) {
}
struct nprotoent *nmap_getprotbynum(int num) {
const struct nprotoent *nmap_getprotbynum(int num) {
if (nmap_protocols_init() == -1)
return NULL;
@@ -189,3 +189,15 @@ struct nprotoent *nmap_getprotbynum(int num) {
assert(num >= 0 && num < UCHAR_MAX);
return protocol_table[num];
}
const struct nprotoent *nmap_getprotbyname(const char *name) {
if (nmap_protocols_init() == -1)
return NULL;
ProtoMap::const_iterator it = proto_map.find(name);
if (it != proto_map.end()) {
return &it->second;
}
return NULL;
}

View File

@@ -77,7 +77,8 @@ struct nprotoent {
};
int addprotocolsfromservmask(char *mask, u8 *porttbl);
struct nprotoent *nmap_getprotbynum(int num);
const struct nprotoent *nmap_getprotbynum(int num);
const struct nprotoent *nmap_getprotbyname(const char *name);
#define MAX_IPPROTOSTRLEN 4
#define IPPROTO2STR(p) \