forked from robertdavidgraham/masscan
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tcp service names in greppable output
- Loading branch information
1 parent
1107def
commit b869603
Showing
10 changed files
with
165 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#include "out-tcp-services.h" | ||
#include <string.h> | ||
#include <stdlib.h> | ||
|
||
#ifndef WIN32 | ||
#include <netdb.h> | ||
#else | ||
#include <WinSock2.h> | ||
#endif | ||
#include <ctype.h> | ||
|
||
#if _MSC_VER | ||
#define strdup _strdup | ||
#endif | ||
|
||
static char *tcp_services[65536]; | ||
static char *udp_services[65536]; | ||
|
||
|
||
|
||
const char * | ||
tcp_service_name(int port) | ||
{ | ||
if (tcp_services[port]) | ||
return tcp_services[port]; | ||
|
||
#ifdef __linux__ | ||
int r; | ||
struct servent result_buf; | ||
struct servent *result; | ||
char buf[2048]; | ||
|
||
r = getservbyport_r(htons(port), "tcp", &result_buf,buf, sizeof(buf), &result); | ||
|
||
/* ignore ERANGE - if the result can't fit in 2k, just return unknown */ | ||
if (r != 0 || result == NULL) | ||
return "unknown"; | ||
|
||
return tcp_services[port] = strdup(result_buf.s_name); | ||
#else | ||
struct servent *result; | ||
|
||
result = getservbyport(htons((unsigned short)port), "tcp"); | ||
|
||
if (result == 0) | ||
return "unknown"; | ||
|
||
return tcp_services[port] = strdup(result->s_name); | ||
#endif | ||
} | ||
|
||
const char * | ||
udp_service_name(int port) | ||
{ | ||
if (udp_services[port]) | ||
return udp_services[port]; | ||
#ifdef __linux__ | ||
int r; | ||
struct servent result_buf; | ||
struct servent *result; | ||
char buf[2048]; | ||
|
||
r = getservbyport_r(htons(port), "udp", &result_buf,buf, sizeof(buf), &result); | ||
|
||
/* ignore ERANGE - if the result can't fit in 2k, just return unknown */ | ||
if (r != 0 || result == NULL) | ||
return "unknown"; | ||
|
||
return udp_services[port] = strdup(result_buf.s_name); | ||
#else | ||
struct servent *result; | ||
|
||
result = getservbyport(htons((unsigned short)port), "udp"); | ||
|
||
if (result == 0) | ||
return "unknown"; | ||
|
||
return udp_services[port] = strdup(result->s_name); | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ifndef OUT_TCP_SERVICES_H | ||
#define OUT_TCP_SERVICES_H | ||
|
||
const char *tcp_service_name(int port); | ||
const char *udp_service_name(int port); | ||
|
||
#endif | ||
|
Oops, something went wrong.