File: getservice.cpp

package info (click to toggle)
fireflier 1.1.6-3etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 3,348 kB
  • ctags: 1,167
  • sloc: sh: 9,023; cpp: 8,370; makefile: 437; ansic: 300
file content (36 lines) | stat: -rw-r--r-- 748 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <netdb.h>
#include "getservice.h"
#include "fireflier.h"
std::string getService(const u_int16_t port, const char *protocol, bool withaliases)
{
	struct servent *se;
	u_int16_t temp;
	std::string servicename="Unknown";

    temp=port;
    netbswap(temp);
	se=getservbyport(temp, protocol);
	if (se)
	{
		servicename=se->s_name;
		if (withaliases)
		{
			for (int i=0;se->s_aliases[i]!=0;i++)
			{
				servicename+=", ";
                servicename+=se->s_aliases[i];
			}
		}
	}
    return servicename;
}

std::string getService(const u_int16_t port, const u_int16_t protocol, bool withaliases)
{
	struct protoent *pe;

	pe=getprotobynumber(protocol);
	if (!pe)
		return "Unknown";
    return (getService(port, pe->p_name, withaliases));
}