Move make_ip_str to probe_modules/packet.c

This is a utility function, mostly useful for probe modules
This commit is contained in:
Eric 2013-09-02 17:57:32 -04:00
parent e458982892
commit ee9593938b
3 changed files with 18 additions and 11 deletions

View File

@ -20,6 +20,7 @@
#include <net/if.h>
#include <arpa/inet.h>
#include <assert.h>
#include "state.h"
@ -121,3 +122,16 @@ void make_udp_header(struct udphdr *udp_header, port_h_t dest_port,
udp_header->check = 0;
}
// Note: caller must free return value
char *make_ip_str(uint32_t ip)
{
struct in_addr t;
t.s_addr = ip;
const char *temp = inet_ntoa(t);
char *retv = malloc(strlen(temp)+1);
assert (retv);
strcpy(retv, temp);
return retv;
}

View File

@ -102,4 +102,7 @@ static __attribute__((unused)) inline uint16_t get_src_port(int num_ports,
return zconf.source_port_first + ((validation[1] + probe_num) % num_ports);
}
// Note: caller must free return value
char *make_ip_str(uint32_t ip);
#endif

View File

@ -21,6 +21,7 @@
#include "../../lib/logger.h"
#include "../fieldset.h"
#include "probe_modules.h"
#include "packet.h"
extern probe_module_t module_tcp_synscan;
extern probe_module_t module_icmp_echo;
@ -53,17 +54,6 @@ void print_probe_modules(void)
}
}
char *make_ip_str(uint32_t ip)
{
struct in_addr t;
t.s_addr = ip;
const char *temp = inet_ntoa(t);
char *retv = malloc(strlen(temp)+1);
assert (retv);
strcpy(retv, temp);
return retv;
}
void fs_add_ip_fields(fieldset_t *fs, struct iphdr *ip)
{
fs_add_string(fs, "saddr", make_ip_str(ip->saddr), 1);