mirror of
https://github.com/nmap/nmap.git
synced 2026-05-13 08:46:45 +00:00
Avoid static buffer for protocol hdrinfo functions
This commit is contained in:
parent
4ba5b9c335
commit
2d46c6b86c
3 changed files with 297 additions and 308 deletions
|
|
@ -441,15 +441,20 @@ char *format_ip_options(const u8* ipopt, int ipoptlen);
|
||||||
#define MEDIUM_DETAIL 2
|
#define MEDIUM_DETAIL 2
|
||||||
#define HIGH_DETAIL 3
|
#define HIGH_DETAIL 3
|
||||||
const char *ippackethdrinfo(const u8 *packet, u32 len, int detail);
|
const char *ippackethdrinfo(const u8 *packet, u32 len, int detail);
|
||||||
const char *tcphdrinfo (const u8 *data, unsigned int datalen, int detail,
|
int tcppackethdrinfo (const u8 *data, unsigned int datalen,
|
||||||
|
char *outbuf, int outlen, int detail,
|
||||||
int frag_off, const char *srchost, const char *dsthost);
|
int frag_off, const char *srchost, const char *dsthost);
|
||||||
const char *udphdrinfo (const u8 *data, unsigned int datalen, int detail,
|
int udppackethdrinfo (const u8 *data, unsigned int datalen,
|
||||||
|
char *outbuf, int outlen, int detail,
|
||||||
int frag_off, const char *srchost, const char *dsthost);
|
int frag_off, const char *srchost, const char *dsthost);
|
||||||
const char *sctphdrinfo (const u8 *data, unsigned int datalen, int detail,
|
int sctppackethdrinfo (const u8 *data, unsigned int datalen,
|
||||||
|
char *outbuf, int outlen, int detail,
|
||||||
int frag_off, const char *srchost, const char *dsthost);
|
int frag_off, const char *srchost, const char *dsthost);
|
||||||
const char *icmphdrinfo (const u8 *data, unsigned int datalen, int detail,
|
int icmppackethdrinfo (const u8 *data, unsigned int datalen,
|
||||||
|
char *outbuf, int outlen, int detail,
|
||||||
int frag_off, const char *srchost, const char *dsthost);
|
int frag_off, const char *srchost, const char *dsthost);
|
||||||
const char *icmp6hdrinfo (const u8 *data, unsigned int datalen, int detail,
|
int icmp6packethdrinfo (const u8 *data, unsigned int datalen,
|
||||||
|
char *outbuf, int outlen, int detail,
|
||||||
int frag_off, const char *srchost, const char *dsthost);
|
int frag_off, const char *srchost, const char *dsthost);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -608,34 +608,32 @@ const char *ippackethdrinfo(const u8 *packet, u32 len, int detail) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *p = protoinfo;
|
||||||
|
int remains = sizeof(protoinfo);
|
||||||
|
int used = 0;
|
||||||
if (hdr.proto == IPPROTO_TCP) {
|
if (hdr.proto == IPPROTO_TCP) {
|
||||||
Snprintf(protoinfo, sizeof(protoinfo), "%s IP [%s]", tcphdrinfo(data, datalen, detail, frag_off, srchost, dsthost), ipinfo);
|
used = tcppackethdrinfo(data, datalen, p, remains, detail, frag_off, srchost, dsthost);
|
||||||
}
|
}
|
||||||
else if (hdr.proto == IPPROTO_UDP) {
|
else if (hdr.proto == IPPROTO_UDP) {
|
||||||
Snprintf(protoinfo, sizeof(protoinfo), "%s IP [%s]", udphdrinfo(data, datalen, detail, frag_off, srchost, dsthost), ipinfo);
|
used = udppackethdrinfo(data, datalen, p, remains, detail, frag_off, srchost, dsthost);
|
||||||
}
|
}
|
||||||
else if (hdr.proto == IPPROTO_SCTP) {
|
else if (hdr.proto == IPPROTO_SCTP) {
|
||||||
Snprintf(protoinfo, sizeof(protoinfo), "%s IP [%s]", sctphdrinfo(data, datalen, detail, frag_off, srchost, dsthost), ipinfo);
|
used = sctppackethdrinfo(data, datalen, p, remains, detail, frag_off, srchost, dsthost);
|
||||||
}
|
}
|
||||||
else if (hdr.proto == IPPROTO_ICMP) {
|
else if (hdr.proto == IPPROTO_ICMP) {
|
||||||
Snprintf(protoinfo, sizeof(protoinfo), "%s IP [%s]", icmphdrinfo(data, datalen, detail, frag_off, srchost, dsthost), ipinfo);
|
used = icmppackethdrinfo(data, datalen, p, remains, detail, frag_off, srchost, dsthost);
|
||||||
}
|
}
|
||||||
else if (hdr.proto == IPPROTO_ICMPV6) {
|
else if (hdr.proto == IPPROTO_ICMPV6) {
|
||||||
Snprintf(protoinfo, sizeof(protoinfo), "%s IP [%s]", icmp6hdrinfo(data, datalen, detail, frag_off, srchost, dsthost), ipinfo);
|
used = icmp6packethdrinfo(data, datalen, p, remains, detail, frag_off, srchost, dsthost);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* UNKNOWN PROTOCOL **********************************************************/
|
/* UNKNOWN PROTOCOL **********************************************************/
|
||||||
const char *hdrstr;
|
used = Snprintf(p, remains, "%s (%d) %s > %s",
|
||||||
|
nexthdrtoa(hdr.proto, 1), hdr.proto, srchost, dsthost);
|
||||||
hdrstr = nexthdrtoa(hdr.proto, 1);
|
|
||||||
if (hdrstr == NULL || *hdrstr == '\0') {
|
|
||||||
Snprintf(protoinfo, sizeof(protoinfo), "Unknown protocol (%d) %s > %s: %s",
|
|
||||||
hdr.proto, srchost, dsthost, ipinfo);
|
|
||||||
} else {
|
|
||||||
Snprintf(protoinfo, sizeof(protoinfo), "%s (%d) %s > %s: %s",
|
|
||||||
hdrstr, hdr.proto, srchost, dsthost, ipinfo);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
p += used;
|
||||||
|
remains -= used;
|
||||||
|
Snprintf(p, remains, " IP [%s]", ipinfo);
|
||||||
|
|
||||||
return protoinfo;
|
return protoinfo;
|
||||||
}
|
}
|
||||||
|
|
@ -657,7 +655,8 @@ static const char *get_addrstr(const char *host, char strbuf[INFO_ADDRSTRLEN])
|
||||||
return host;
|
return host;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *tcphdrinfo (const u8 *data, unsigned int datalen, int detail,
|
int tcppackethdrinfo (const u8 *data, unsigned int datalen,
|
||||||
|
char *outbuf, int outlen, int detail,
|
||||||
int frag_off, const char *srchost, const char *dsthost)
|
int frag_off, const char *srchost, const char *dsthost)
|
||||||
{
|
{
|
||||||
char srcstr[INFO_ADDRSTRLEN] = "";
|
char srcstr[INFO_ADDRSTRLEN] = "";
|
||||||
|
|
@ -666,7 +665,6 @@ const char *tcphdrinfo (const u8 *data, unsigned int datalen, int detail,
|
||||||
dsthost = get_addrstr(dsthost, dststr);
|
dsthost = get_addrstr(dsthost, dststr);
|
||||||
|
|
||||||
/* TCP INFORMATION ***********************************************************/
|
/* TCP INFORMATION ***********************************************************/
|
||||||
static char protoinfo[512] = "";
|
|
||||||
char tcpoptinfo[256] = "";
|
char tcpoptinfo[256] = "";
|
||||||
struct tcp_hdr tcp;
|
struct tcp_hdr tcp;
|
||||||
|
|
||||||
|
|
@ -683,18 +681,17 @@ const char *tcphdrinfo (const u8 *data, unsigned int datalen, int detail,
|
||||||
* less than 8 bytes. This also includes empty IP packets that say they
|
* less than 8 bytes. This also includes empty IP packets that say they
|
||||||
* contain a TCP packet. */
|
* contain a TCP packet. */
|
||||||
if (frag_off > 8 || datalen < 8 || (frag_off % 8 != 0)) {
|
if (frag_off > 8 || datalen < 8 || (frag_off % 8 != 0)) {
|
||||||
Snprintf(protoinfo, sizeof(protoinfo), "TCP %s:?? > %s:?? ?? (incomplete)",
|
return Snprintf(outbuf, outlen, "TCP %s:?? > %s:?? ?? (incomplete)",
|
||||||
srchost, dsthost);
|
srchost, dsthost);
|
||||||
}
|
}
|
||||||
/* For all cases after this, datalen is necessarily >= 8 and frag_off is <= 8 */
|
/* For all cases after this, datalen is necessarily >= 8 and frag_off is <= 8 */
|
||||||
else {
|
|
||||||
memcpy((u8 *)&tcp + frag_off, data, MIN(datalen, sizeof(tcp) - frag_off));
|
memcpy((u8 *)&tcp + frag_off, data, MIN(datalen, sizeof(tcp) - frag_off));
|
||||||
/* how much of the original packet do we have? */
|
/* how much of the original packet do we have? */
|
||||||
int lastbyte = datalen + frag_off;
|
int lastbyte = datalen + frag_off;
|
||||||
bool have_seq=false, have_flags_win=false, have_sum_urp=false;
|
bool have_seq=false, have_flags_win=false, have_sum_urp=false;
|
||||||
|
|
||||||
char *p = protoinfo;
|
char *p = outbuf;
|
||||||
int remains = sizeof(protoinfo) - 1;
|
int remains = outlen;
|
||||||
int used = 0;
|
int used = 0;
|
||||||
u32 tcpdataoffset = 0;
|
u32 tcpdataoffset = 0;
|
||||||
|
|
||||||
|
|
@ -783,11 +780,11 @@ tcpdone:
|
||||||
remains -= used;
|
remains -= used;
|
||||||
}
|
}
|
||||||
assert(remains > 0);
|
assert(remains > 0);
|
||||||
}
|
return outlen - remains;
|
||||||
return protoinfo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *udphdrinfo (const u8 *data, unsigned int datalen, int detail,
|
int udppackethdrinfo (const u8 *data, unsigned int datalen,
|
||||||
|
char *outbuf, int outlen, int detail,
|
||||||
int frag_off, const char *srchost, const char *dsthost)
|
int frag_off, const char *srchost, const char *dsthost)
|
||||||
{
|
{
|
||||||
char srcstr[INFO_ADDRSTRLEN] = "";
|
char srcstr[INFO_ADDRSTRLEN] = "";
|
||||||
|
|
@ -795,31 +792,30 @@ const char *udphdrinfo (const u8 *data, unsigned int datalen, int detail,
|
||||||
srchost = get_addrstr(srchost, srcstr);
|
srchost = get_addrstr(srchost, srcstr);
|
||||||
dsthost = get_addrstr(dsthost, dststr);
|
dsthost = get_addrstr(dsthost, dststr);
|
||||||
|
|
||||||
static char protoinfo[512] = "";
|
/* UDP INFORMATION ***********************************************************/
|
||||||
/* UDP INFORMATION ***********************************************************/
|
if((frag_off || datalen < sizeof(struct udp_hdr))) {
|
||||||
if((frag_off || datalen < sizeof(struct udp_hdr))) {
|
return Snprintf(outbuf, outlen, "UDP %s:?? > %s:?? fragment (incomplete)",
|
||||||
Snprintf(protoinfo, sizeof(protoinfo), "UDP %s:?? > %s:?? fragment (incomplete)",
|
srchost, dsthost);
|
||||||
srchost, dsthost);
|
}
|
||||||
} else {
|
|
||||||
struct udp_hdr udp;
|
struct udp_hdr udp;
|
||||||
memcpy(&udp, data, sizeof(udp));
|
memcpy(&udp, data, sizeof(udp));
|
||||||
|
|
||||||
if (detail == LOW_DETAIL) {
|
if (detail == LOW_DETAIL) {
|
||||||
Snprintf(protoinfo, sizeof(protoinfo), "UDP %s:%hu > %s:%hu",
|
return Snprintf(outbuf, outlen, "UDP %s:%hu > %s:%hu",
|
||||||
srchost, (unsigned short) ntohs(udp.uh_sport), dsthost, (unsigned short) ntohs(udp.uh_dport));
|
srchost, (unsigned short) ntohs(udp.uh_sport), dsthost, (unsigned short) ntohs(udp.uh_dport));
|
||||||
} else if (detail == MEDIUM_DETAIL) {
|
} else if (detail == MEDIUM_DETAIL) {
|
||||||
Snprintf(protoinfo, sizeof(protoinfo), "UDP [%s:%hu > %s:%hu csum=0x%04X]",
|
return Snprintf(outbuf, outlen, "UDP [%s:%hu > %s:%hu csum=0x%04X]",
|
||||||
srchost, (unsigned short) ntohs(udp.uh_sport), dsthost, (unsigned short) ntohs(udp.uh_dport), ntohs(udp.uh_sum));
|
srchost, (unsigned short) ntohs(udp.uh_sport), dsthost, (unsigned short) ntohs(udp.uh_dport), ntohs(udp.uh_sum));
|
||||||
} else if (detail == HIGH_DETAIL) {
|
} else if (detail == HIGH_DETAIL) {
|
||||||
Snprintf(protoinfo, sizeof(protoinfo), "UDP [%s:%hu > %s:%hu len=%hu csum=0x%04X]",
|
return Snprintf(outbuf, outlen, "UDP [%s:%hu > %s:%hu len=%hu csum=0x%04X]",
|
||||||
srchost, (unsigned short) ntohs(udp.uh_sport), dsthost, (unsigned short) ntohs(udp.uh_dport),
|
srchost, (unsigned short) ntohs(udp.uh_sport), dsthost, (unsigned short) ntohs(udp.uh_dport),
|
||||||
(unsigned short) ntohs(udp.uh_ulen), ntohs(udp.uh_sum));
|
(unsigned short) ntohs(udp.uh_ulen), ntohs(udp.uh_sum));
|
||||||
}
|
}
|
||||||
}
|
return 0;
|
||||||
return protoinfo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *sctphdrinfo (const u8 *data, unsigned int datalen, int detail,
|
int sctppackethdrinfo (const u8 *data, unsigned int datalen,
|
||||||
|
char *outbuf, int outlen, int detail,
|
||||||
int frag_off, const char *srchost, const char *dsthost)
|
int frag_off, const char *srchost, const char *dsthost)
|
||||||
{
|
{
|
||||||
char srcstr[INFO_ADDRSTRLEN] = "";
|
char srcstr[INFO_ADDRSTRLEN] = "";
|
||||||
|
|
@ -827,358 +823,356 @@ const char *sctphdrinfo (const u8 *data, unsigned int datalen, int detail,
|
||||||
srchost = get_addrstr(srchost, srcstr);
|
srchost = get_addrstr(srchost, srcstr);
|
||||||
dsthost = get_addrstr(dsthost, dststr);
|
dsthost = get_addrstr(dsthost, dststr);
|
||||||
|
|
||||||
static char protoinfo[512] = "";
|
/* SCTP INFORMATION **********************************************************/
|
||||||
/* SCTP INFORMATION **********************************************************/
|
if ((frag_off || datalen < sizeof(struct sctp_hdr))) {
|
||||||
if ((frag_off || datalen < sizeof(struct sctp_hdr))) {
|
return Snprintf(outbuf, outlen, "SCTP %s:?? > %s:?? fragment (incomplete)",
|
||||||
Snprintf(protoinfo, sizeof(protoinfo), "SCTP %s:?? > %s:?? fragment (incomplete)",
|
srchost, dsthost);
|
||||||
srchost, dsthost);
|
}
|
||||||
} else {
|
|
||||||
struct sctp_hdr sctp;
|
struct sctp_hdr sctp;
|
||||||
memcpy(&sctp, data, sizeof(sctp));
|
memcpy(&sctp, data, sizeof(sctp));
|
||||||
|
|
||||||
if (detail == LOW_DETAIL) {
|
if (detail == LOW_DETAIL) {
|
||||||
Snprintf(protoinfo, sizeof(protoinfo), "SCTP %s:%hu > %s:%hu",
|
return Snprintf(outbuf, outlen, "SCTP %s:%hu > %s:%hu",
|
||||||
srchost, (unsigned short) ntohs(sctp.sh_sport), dsthost, (unsigned short) ntohs(sctp.sh_dport));
|
srchost, (unsigned short) ntohs(sctp.sh_sport), dsthost, (unsigned short) ntohs(sctp.sh_dport));
|
||||||
} else if (detail == MEDIUM_DETAIL) {
|
} else if (detail == MEDIUM_DETAIL) {
|
||||||
Snprintf(protoinfo, sizeof(protoinfo), "SCTP [%s:%hu > %s:%hu csum=0x%08x]",
|
return Snprintf(outbuf, outlen, "SCTP [%s:%hu > %s:%hu csum=0x%08x]",
|
||||||
srchost, (unsigned short) ntohs(sctp.sh_sport), dsthost, (unsigned short) ntohs(sctp.sh_dport), ntohl(sctp.sh_sum));
|
srchost, (unsigned short) ntohs(sctp.sh_sport), dsthost, (unsigned short) ntohs(sctp.sh_dport), ntohl(sctp.sh_sum));
|
||||||
} else if (detail == HIGH_DETAIL) {
|
} else if (detail == HIGH_DETAIL) {
|
||||||
Snprintf(protoinfo, sizeof(protoinfo), "SCTP [%s:%hu > %s:%hu vtag=%lu csum=0x%08x]",
|
return Snprintf(outbuf, outlen, "SCTP [%s:%hu > %s:%hu vtag=%lu csum=0x%08x]",
|
||||||
srchost, (unsigned short) ntohs(sctp.sh_sport), dsthost, (unsigned short) ntohs(sctp.sh_dport),
|
srchost, (unsigned short) ntohs(sctp.sh_sport), dsthost, (unsigned short) ntohs(sctp.sh_dport),
|
||||||
(unsigned long) ntohl(sctp.sh_vtag), ntohl(sctp.sh_sum));
|
(unsigned long) ntohl(sctp.sh_vtag), ntohl(sctp.sh_sum));
|
||||||
}
|
}
|
||||||
}
|
return 0;
|
||||||
return protoinfo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *icmphdrinfo (const u8 *data, unsigned int datalen, int detail,
|
int icmppackethdrinfo (const u8 *data, unsigned int datalen,
|
||||||
|
char *outbuf, int outlen, int detail,
|
||||||
int frag_off, const char *srchost, const char *dsthost)
|
int frag_off, const char *srchost, const char *dsthost)
|
||||||
{
|
{
|
||||||
if (srchost == NULL)
|
if (srchost == NULL)
|
||||||
srchost = "??";
|
srchost = "??";
|
||||||
if (dsthost == NULL)
|
if (dsthost == NULL)
|
||||||
dsthost = "??";
|
dsthost = "??";
|
||||||
static char protoinfo[512] = "";
|
|
||||||
char icmptype[128] = ""; /* Temp info about ICMP type & code */
|
char icmptype[128] = ""; /* Temp info about ICMP type & code */
|
||||||
char icmpfields[256] = ""; /* Temp info for various ICMP fields */
|
char icmpfields[256] = ""; /* Temp info for various ICMP fields */
|
||||||
/* ICMP INFORMATION **********************************************************/
|
/* ICMP INFORMATION **********************************************************/
|
||||||
if((frag_off || datalen < sizeof(struct icmp_hdr))) {
|
if((frag_off || datalen < sizeof(struct icmp_hdr))) {
|
||||||
Snprintf(protoinfo, sizeof(protoinfo), "ICMP %s > %s fragment (incomplete)",
|
return Snprintf(outbuf, outlen, "ICMP %s > %s fragment (incomplete)",
|
||||||
srchost, dsthost);
|
srchost, dsthost);
|
||||||
} else {
|
}
|
||||||
struct ip_hdr ip2; /* Points to the IP datagram carried by some ICMP messages */
|
|
||||||
char *ip2dst; /* Dest IP in caried IP datagram */
|
|
||||||
char auxbuff[128]; /* Aux buffer */
|
|
||||||
struct icmp_hdr icmp;
|
|
||||||
unsigned pktlen = sizeof(icmp);
|
|
||||||
|
|
||||||
/* We need the ICMP packet to be at least 8 bytes long */
|
struct ip_hdr ip2; /* Points to the IP datagram carried by some ICMP messages */
|
||||||
if (ICMP_LEN_MIN > datalen)
|
char *ip2dst; /* Dest IP in caried IP datagram */
|
||||||
goto icmpbad;
|
char auxbuff[128]; /* Aux buffer */
|
||||||
|
struct icmp_hdr icmp;
|
||||||
|
unsigned pktlen = sizeof(icmp);
|
||||||
|
|
||||||
memcpy(&icmp, data, sizeof(icmp));
|
/* We need the ICMP packet to be at least 8 bytes long */
|
||||||
|
if (ICMP_LEN_MIN > datalen)
|
||||||
|
goto icmpbad;
|
||||||
|
|
||||||
union icmp_msg msg;
|
memcpy(&icmp, data, sizeof(icmp));
|
||||||
memcpy(&msg, data + pktlen, MIN(datalen - pktlen, sizeof(msg)));
|
|
||||||
|
|
||||||
switch(icmp.icmp_type) {
|
union icmp_msg msg;
|
||||||
/* Echo Reply **************************/
|
memcpy(&msg, data + pktlen, MIN(datalen - pktlen, sizeof(msg)));
|
||||||
case 0:
|
|
||||||
strcpy(icmptype, "Echo reply");
|
|
||||||
Snprintf(icmpfields, sizeof(icmpfields), "id=%hu seq=%hu", (unsigned short) ntohs(msg.echo.icmp_id), (unsigned short) ntohs(msg.echo.icmp_seq));
|
|
||||||
break;
|
|
||||||
|
|
||||||
/* Destination Unreachable *************/
|
switch(icmp.icmp_type) {
|
||||||
case 3:
|
/* Echo Reply **************************/
|
||||||
/* Point to the start of the original datagram */
|
case 0:
|
||||||
pktlen += offsetof(struct icmp_msg_quote, icmp_ip);
|
strcpy(icmptype, "Echo reply");
|
||||||
if (datalen >= pktlen + sizeof(ip2)) {
|
Snprintf(icmpfields, sizeof(icmpfields), "id=%hu seq=%hu", (unsigned short) ntohs(msg.echo.icmp_id), (unsigned short) ntohs(msg.echo.icmp_seq));
|
||||||
memcpy(&ip2, data + pktlen, sizeof(ip2));
|
break;
|
||||||
pktlen += ip2.ip_hl * 4;
|
|
||||||
} else {
|
|
||||||
pktlen += sizeof(ip2);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check we have a full IP datagram included in the ICMP message */
|
/* Destination Unreachable *************/
|
||||||
if (pktlen > datalen) {
|
case 3:
|
||||||
if (datalen == 8) {
|
/* Point to the start of the original datagram */
|
||||||
Snprintf(icmptype, sizeof icmptype, "Destination unreachable%s",
|
pktlen += offsetof(struct icmp_msg_quote, icmp_ip);
|
||||||
|
if (datalen >= pktlen + sizeof(ip2)) {
|
||||||
|
memcpy(&ip2, data + pktlen, sizeof(ip2));
|
||||||
|
pktlen += ip2.ip_hl * 4;
|
||||||
|
} else {
|
||||||
|
pktlen += sizeof(ip2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check we have a full IP datagram included in the ICMP message */
|
||||||
|
if (pktlen > datalen) {
|
||||||
|
if (datalen == 8) {
|
||||||
|
Snprintf(icmptype, sizeof icmptype, "Destination unreachable%s",
|
||||||
(detail!=LOW_DETAIL)? " (original datagram missing)" : "");
|
(detail!=LOW_DETAIL)? " (original datagram missing)" : "");
|
||||||
} else {
|
} else {
|
||||||
Snprintf(icmptype, sizeof icmptype, "Destination unreachable%s",
|
Snprintf(icmptype, sizeof icmptype, "Destination unreachable%s",
|
||||||
(detail!=LOW_DETAIL)? " (part of original datagram missing)" : "");
|
(detail!=LOW_DETAIL)? " (part of original datagram missing)" : "");
|
||||||
}
|
|
||||||
goto icmpbad;
|
|
||||||
}
|
}
|
||||||
|
goto icmpbad;
|
||||||
|
}
|
||||||
|
|
||||||
/* Basic check to ensure we have an IPv4 datagram attached */
|
/* Basic check to ensure we have an IPv4 datagram attached */
|
||||||
/* TODO: We should actually check the datagram checksum to
|
/* TODO: We should actually check the datagram checksum to
|
||||||
* see if it validates because just checking the version number
|
* see if it validates because just checking the version number
|
||||||
* is not enough. On average, if we get random data 1 out of
|
* is not enough. On average, if we get random data 1 out of
|
||||||
* 16 (2^4bits) times we will have value 4. */
|
* 16 (2^4bits) times we will have value 4. */
|
||||||
if ((ip2.ip_v != 4) || ((ip2.ip_hl * 4) < 20) || ((ip2.ip_hl * 4) > 60)) {
|
if ((ip2.ip_v != 4) || ((ip2.ip_hl * 4) < 20) || ((ip2.ip_hl * 4) > 60)) {
|
||||||
Snprintf(icmptype, sizeof icmptype, "Destination unreachable (bogus original datagram)");
|
Snprintf(icmptype, sizeof icmptype, "Destination unreachable (bogus original datagram)");
|
||||||
goto icmpbad;
|
goto icmpbad;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Determine the IP the original datagram was sent to */
|
/* Determine the IP the original datagram was sent to */
|
||||||
ip2dst = ip_ntoa(&ip2.ip_dst);
|
ip2dst = ip_ntoa(&ip2.ip_dst);
|
||||||
|
|
||||||
/* Determine type of Destination unreachable from the code value */
|
/* Determine type of Destination unreachable from the code value */
|
||||||
switch (icmp.icmp_code) {
|
switch (icmp.icmp_code) {
|
||||||
case 0:
|
case 0:
|
||||||
Snprintf(icmptype, sizeof icmptype, "Network %s unreachable", ip2dst);
|
Snprintf(icmptype, sizeof icmptype, "Network %s unreachable", ip2dst);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
Snprintf(icmptype, sizeof icmptype, "Host %s unreachable", ip2dst);
|
Snprintf(icmptype, sizeof icmptype, "Host %s unreachable", ip2dst);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
Snprintf(icmptype, sizeof icmptype, "Protocol %u unreachable", ip2.ip_p);
|
Snprintf(icmptype, sizeof icmptype, "Protocol %u unreachable", ip2.ip_p);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
if (pktlen + 8 < datalen) {
|
if (pktlen + 8 < datalen) {
|
||||||
/* We have the original datagram + the first 8 bytes of the
|
/* We have the original datagram + the first 8 bytes of the
|
||||||
* transport layer header */
|
* transport layer header */
|
||||||
const u8 *pp = data + pktlen;
|
const u8 *pp = data + pktlen;
|
||||||
int offset = -1;
|
int offset = -1;
|
||||||
if (ip2.ip_p == IPPROTO_UDP)
|
if (ip2.ip_p == IPPROTO_UDP)
|
||||||
offset = offsetof(struct udp_hdr, uh_dport);
|
offset = offsetof(struct udp_hdr, uh_dport);
|
||||||
else if (ip2.ip_p == IPPROTO_TCP)
|
else if (ip2.ip_p == IPPROTO_TCP)
|
||||||
offset = offsetof(struct tcp_hdr, th_dport);
|
offset = offsetof(struct tcp_hdr, th_dport);
|
||||||
else if (ip2.ip_p == IPPROTO_SCTP)
|
else if (ip2.ip_p == IPPROTO_SCTP)
|
||||||
offset = offsetof(struct sctp_hdr, sh_dport);
|
offset = offsetof(struct sctp_hdr, sh_dport);
|
||||||
|
|
||||||
if (offset >= 0) {
|
if (offset >= 0) {
|
||||||
pp += offset;
|
pp += offset;
|
||||||
Snprintf(icmptype, sizeof icmptype, "Port %hu unreachable", (u16)((pp[0] << 8) + pp[1]));
|
Snprintf(icmptype, sizeof icmptype, "Port %hu unreachable", (u16)((pp[0] << 8) + pp[1]));
|
||||||
}
|
|
||||||
else
|
|
||||||
Snprintf(icmptype, sizeof icmptype, "Port unreachable (unknown protocol %u)", ip2.ip_p);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
strcpy(icmptype, "Port unreachable");
|
Snprintf(icmptype, sizeof icmptype, "Port unreachable (unknown protocol %u)", ip2.ip_p);
|
||||||
break;
|
}
|
||||||
|
else
|
||||||
|
strcpy(icmptype, "Port unreachable");
|
||||||
|
break;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
strcpy(icmptype, "Fragmentation required");
|
strcpy(icmptype, "Fragmentation required");
|
||||||
Snprintf(icmpfields, sizeof(icmpfields), "Next-Hop-MTU=%d", ntohs(msg.needfrag.icmp_mtu));
|
Snprintf(icmpfields, sizeof(icmpfields), "Next-Hop-MTU=%d", ntohs(msg.needfrag.icmp_mtu));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 5:
|
case 5:
|
||||||
strcpy(icmptype, "Source route failed");
|
strcpy(icmptype, "Source route failed");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 6:
|
case 6:
|
||||||
Snprintf(icmptype, sizeof icmptype, "Destination network %s unknown", ip2dst);
|
Snprintf(icmptype, sizeof icmptype, "Destination network %s unknown", ip2dst);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 7:
|
case 7:
|
||||||
Snprintf(icmptype, sizeof icmptype, "Destination host %s unknown", ip2dst);
|
Snprintf(icmptype, sizeof icmptype, "Destination host %s unknown", ip2dst);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 8:
|
case 8:
|
||||||
strcpy(icmptype, "Source host isolated");
|
strcpy(icmptype, "Source host isolated");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 9:
|
case 9:
|
||||||
Snprintf(icmptype, sizeof icmptype, "Destination network %s administratively prohibited", ip2dst);
|
Snprintf(icmptype, sizeof icmptype, "Destination network %s administratively prohibited", ip2dst);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 10:
|
case 10:
|
||||||
Snprintf(icmptype, sizeof icmptype, "Destination host %s administratively prohibited", ip2dst);
|
Snprintf(icmptype, sizeof icmptype, "Destination host %s administratively prohibited", ip2dst);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 11:
|
case 11:
|
||||||
Snprintf(icmptype, sizeof icmptype, "Network %s unreachable for TOS", ip2dst);
|
Snprintf(icmptype, sizeof icmptype, "Network %s unreachable for TOS", ip2dst);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 12:
|
case 12:
|
||||||
Snprintf(icmptype, sizeof icmptype, "Host %s unreachable for TOS", ip2dst);
|
Snprintf(icmptype, sizeof icmptype, "Host %s unreachable for TOS", ip2dst);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 13:
|
case 13:
|
||||||
strcpy(icmptype, "Communication administratively prohibited by filtering");
|
strcpy(icmptype, "Communication administratively prohibited by filtering");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 14:
|
case 14:
|
||||||
strcpy(icmptype, "Host precedence violation");
|
strcpy(icmptype, "Host precedence violation");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 15:
|
case 15:
|
||||||
strcpy(icmptype, "Precedence cutoff in effect");
|
strcpy(icmptype, "Precedence cutoff in effect");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
strcpy(icmptype, "Destination unreachable (unknown code)");
|
strcpy(icmptype, "Destination unreachable (unknown code)");
|
||||||
break;
|
break;
|
||||||
} /* End of ICMP Code switch */
|
} /* End of ICMP Code switch */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
/* Source Quench ***********************/
|
/* Source Quench ***********************/
|
||||||
case 4:
|
case 4:
|
||||||
strcpy(icmptype, "Source quench");
|
strcpy(icmptype, "Source quench");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* Redirect ****************************/
|
/* Redirect ****************************/
|
||||||
case 5:
|
case 5:
|
||||||
if (icmp.icmp_code == 0)
|
if (icmp.icmp_code == 0)
|
||||||
strcpy(icmptype, "Network redirect");
|
strcpy(icmptype, "Network redirect");
|
||||||
else if (icmp.icmp_code == 1)
|
else if (icmp.icmp_code == 1)
|
||||||
strcpy(icmptype, "Host redirect");
|
strcpy(icmptype, "Host redirect");
|
||||||
else
|
else
|
||||||
strcpy(icmptype, "Redirect (unknown code)");
|
strcpy(icmptype, "Redirect (unknown code)");
|
||||||
inet_ntop(AF_INET, &msg.redirect.icmp_void, auxbuff, sizeof(auxbuff));
|
inet_ntop(AF_INET, &msg.redirect.icmp_void, auxbuff, sizeof(auxbuff));
|
||||||
Snprintf(icmpfields, sizeof(icmpfields), "addr=%s", auxbuff);
|
Snprintf(icmpfields, sizeof(icmpfields), "addr=%s", auxbuff);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* Echo Request ************************/
|
/* Echo Request ************************/
|
||||||
case 8:
|
case 8:
|
||||||
strcpy(icmptype, "Echo request");
|
strcpy(icmptype, "Echo request");
|
||||||
Snprintf(icmpfields, sizeof(icmpfields), "id=%hu seq=%hu", (unsigned short) ntohs(msg.echo.icmp_id), (unsigned short) ntohs(msg.echo.icmp_seq));
|
Snprintf(icmpfields, sizeof(icmpfields), "id=%hu seq=%hu", (unsigned short) ntohs(msg.echo.icmp_id), (unsigned short) ntohs(msg.echo.icmp_seq));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* Router Advertisement ****************/
|
/* Router Advertisement ****************/
|
||||||
case 9:
|
case 9:
|
||||||
if (icmp.icmp_code == 16)
|
if (icmp.icmp_code == 16)
|
||||||
strcpy(icmptype, "Router advertisement (Mobile Agent Only)");
|
strcpy(icmptype, "Router advertisement (Mobile Agent Only)");
|
||||||
else
|
else
|
||||||
strcpy(icmptype, "Router advertisement");
|
strcpy(icmptype, "Router advertisement");
|
||||||
Snprintf(icmpfields, sizeof(icmpfields), "addrs=%u addrlen=%u lifetime=%hu",
|
Snprintf(icmpfields, sizeof(icmpfields), "addrs=%u addrlen=%u lifetime=%hu",
|
||||||
msg.rtradvert.icmp_num_addrs,
|
msg.rtradvert.icmp_num_addrs,
|
||||||
msg.rtradvert.icmp_wpa,
|
msg.rtradvert.icmp_wpa,
|
||||||
(unsigned short) ntohs(msg.rtradvert.icmp_lifetime));
|
(unsigned short) ntohs(msg.rtradvert.icmp_lifetime));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* Router Solicitation *****************/
|
/* Router Solicitation *****************/
|
||||||
case 10:
|
case 10:
|
||||||
strcpy(icmptype, "Router solicitation");
|
strcpy(icmptype, "Router solicitation");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* Time Exceeded ***********************/
|
/* Time Exceeded ***********************/
|
||||||
case 11:
|
case 11:
|
||||||
if (icmp.icmp_code == 0)
|
if (icmp.icmp_code == 0)
|
||||||
strcpy(icmptype, "TTL=0 during transit");
|
strcpy(icmptype, "TTL=0 during transit");
|
||||||
else if (icmp.icmp_code == 1)
|
else if (icmp.icmp_code == 1)
|
||||||
strcpy(icmptype, "TTL=0 during reassembly");
|
strcpy(icmptype, "TTL=0 during reassembly");
|
||||||
else
|
else
|
||||||
strcpy(icmptype, "TTL exceeded (unknown code)");
|
strcpy(icmptype, "TTL exceeded (unknown code)");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* Parameter Problem *******************/
|
/* Parameter Problem *******************/
|
||||||
case 12:
|
case 12:
|
||||||
if (icmp.icmp_code == 0)
|
if (icmp.icmp_code == 0)
|
||||||
strcpy(icmptype, "Parameter problem (pointer indicates error)");
|
strcpy(icmptype, "Parameter problem (pointer indicates error)");
|
||||||
else if (icmp.icmp_code == 1)
|
else if (icmp.icmp_code == 1)
|
||||||
strcpy(icmptype, "Parameter problem (option missing)");
|
strcpy(icmptype, "Parameter problem (option missing)");
|
||||||
else if (icmp.icmp_code == 2)
|
else if (icmp.icmp_code == 2)
|
||||||
strcpy(icmptype, "Parameter problem (bad length)");
|
strcpy(icmptype, "Parameter problem (bad length)");
|
||||||
else
|
else
|
||||||
strcpy(icmptype, "Parameter problem (unknown code)");
|
strcpy(icmptype, "Parameter problem (unknown code)");
|
||||||
Snprintf(icmpfields, sizeof(icmpfields), "pointer=%hhu", *((u8 *)(&msg.paramprob.icmp_void)));
|
Snprintf(icmpfields, sizeof(icmpfields), "pointer=%hhu", *((u8 *)(&msg.paramprob.icmp_void)));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* Timestamp Request/Reply *************/
|
/* Timestamp Request/Reply *************/
|
||||||
case 13:
|
case 13:
|
||||||
case 14:
|
case 14:
|
||||||
Snprintf(icmptype, sizeof(icmptype), "Timestamp %s", (icmp.icmp_type == 13)? "request" : "reply");
|
Snprintf(icmptype, sizeof(icmptype), "Timestamp %s", (icmp.icmp_type == 13)? "request" : "reply");
|
||||||
Snprintf(icmpfields, sizeof(icmpfields), "id=%hu seq=%hu orig=%lu recv=%lu trans=%lu",
|
Snprintf(icmpfields, sizeof(icmpfields), "id=%hu seq=%hu orig=%lu recv=%lu trans=%lu",
|
||||||
(unsigned short) ntohs(msg.tstamp.icmp_id), (unsigned short) ntohs(msg.tstamp.icmp_seq),
|
(unsigned short) ntohs(msg.tstamp.icmp_id), (unsigned short) ntohs(msg.tstamp.icmp_seq),
|
||||||
(unsigned long) ntohl(msg.tstamp.icmp_ts_orig),
|
(unsigned long) ntohl(msg.tstamp.icmp_ts_orig),
|
||||||
(unsigned long) ntohl(msg.tstamp.icmp_ts_rx),
|
(unsigned long) ntohl(msg.tstamp.icmp_ts_rx),
|
||||||
(unsigned long) ntohl(msg.tstamp.icmp_ts_tx));
|
(unsigned long) ntohl(msg.tstamp.icmp_ts_tx));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* Information Request *****************/
|
/* Information Request *****************/
|
||||||
case 15:
|
case 15:
|
||||||
strcpy(icmptype, "Information request");
|
strcpy(icmptype, "Information request");
|
||||||
Snprintf(icmpfields, sizeof(icmpfields), "id=%hu seq=%hu", (unsigned short) ntohs(msg.info.icmp_id), (unsigned short) ntohs(msg.info.icmp_seq));
|
Snprintf(icmpfields, sizeof(icmpfields), "id=%hu seq=%hu", (unsigned short) ntohs(msg.info.icmp_id), (unsigned short) ntohs(msg.info.icmp_seq));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* Information Reply *******************/
|
/* Information Reply *******************/
|
||||||
case 16:
|
case 16:
|
||||||
strcpy(icmptype, "Information reply");
|
strcpy(icmptype, "Information reply");
|
||||||
Snprintf(icmpfields, sizeof(icmpfields), "id=%hu seq=%hu", (unsigned short) ntohs(msg.info.icmp_id), (unsigned short) ntohs(msg.info.icmp_seq));
|
Snprintf(icmpfields, sizeof(icmpfields), "id=%hu seq=%hu", (unsigned short) ntohs(msg.info.icmp_id), (unsigned short) ntohs(msg.info.icmp_seq));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* Netmask Request/Reply ***************/
|
/* Netmask Request/Reply ***************/
|
||||||
case 17:
|
case 17:
|
||||||
case 18:
|
case 18:
|
||||||
Snprintf(icmptype, sizeof(icmptype), "Address mask %s", (icmp.icmp_type == 17)? "request" : "reply");
|
Snprintf(icmptype, sizeof(icmptype), "Address mask %s", (icmp.icmp_type == 17)? "request" : "reply");
|
||||||
inet_ntop(AF_INET, &msg.mask.icmp_mask, auxbuff, sizeof(auxbuff));
|
inet_ntop(AF_INET, &msg.mask.icmp_mask, auxbuff, sizeof(auxbuff));
|
||||||
Snprintf(icmpfields, sizeof(icmpfields), "id=%u seq=%u mask=%s",
|
Snprintf(icmpfields, sizeof(icmpfields), "id=%u seq=%u mask=%s",
|
||||||
(unsigned short) ntohs(msg.mask.icmp_id), (unsigned short) ntohs(msg.mask.icmp_seq), auxbuff);
|
(unsigned short) ntohs(msg.mask.icmp_id), (unsigned short) ntohs(msg.mask.icmp_seq), auxbuff);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* Traceroute **************************/
|
/* Traceroute **************************/
|
||||||
case 30:
|
case 30:
|
||||||
strcpy(icmptype, "Traceroute");
|
strcpy(icmptype, "Traceroute");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* Domain Name Request *****************/
|
/* Domain Name Request *****************/
|
||||||
case 37:
|
case 37:
|
||||||
strcpy(icmptype, "Domain name request");
|
strcpy(icmptype, "Domain name request");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* Domain Name Reply *******************/
|
/* Domain Name Reply *******************/
|
||||||
case 38:
|
case 38:
|
||||||
strcpy(icmptype, "Domain name reply");
|
strcpy(icmptype, "Domain name reply");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* Security ****************************/
|
/* Security ****************************/
|
||||||
case 40:
|
case 40:
|
||||||
strcpy(icmptype, "Security failures"); /* rfc 2521 */
|
strcpy(icmptype, "Security failures"); /* rfc 2521 */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
strcpy(icmptype, "Unknown type"); break;
|
strcpy(icmptype, "Unknown type"); break;
|
||||||
break;
|
break;
|
||||||
} /* End of ICMP Type switch */
|
} /* End of ICMP Type switch */
|
||||||
|
|
||||||
if (pktlen > datalen) {
|
if (pktlen > datalen) {
|
||||||
icmpbad:
|
icmpbad:
|
||||||
if (icmptype[0] != '\0') {
|
if (icmptype[0] != '\0') {
|
||||||
/* We still have this information */
|
/* We still have this information */
|
||||||
Snprintf(protoinfo, sizeof(protoinfo), "ICMP %s > %s %s (type=%d/code=%d)",
|
return Snprintf(outbuf, outlen, "ICMP %s > %s %s (type=%d/code=%d)",
|
||||||
srchost, dsthost, icmptype, icmp.icmp_type, icmp.icmp_code);
|
srchost, dsthost, icmptype, icmp.icmp_type, icmp.icmp_code);
|
||||||
} else {
|
|
||||||
Snprintf(protoinfo, sizeof(protoinfo), "ICMP %s > %s [??]",
|
|
||||||
srchost, dsthost);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
char icmpinfo[512] = ""; /* Temp info about ICMP. */
|
return Snprintf(outbuf, outlen, "ICMP %s > %s [??]",
|
||||||
sprintf(icmpinfo,"type=%d/code=%d", icmp.icmp_type, icmp.icmp_code);
|
srchost, dsthost);
|
||||||
|
|
||||||
Snprintf(protoinfo, sizeof(protoinfo), "ICMP [%s > %s %s (%s) %s]",
|
|
||||||
srchost, dsthost, icmptype, icmpinfo, icmpfields);
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
char icmpinfo[512] = ""; /* Temp info about ICMP. */
|
||||||
|
sprintf(icmpinfo,"type=%d/code=%d", icmp.icmp_type, icmp.icmp_code);
|
||||||
|
|
||||||
|
return Snprintf(outbuf, outlen, "ICMP [%s > %s %s (%s) %s]",
|
||||||
|
srchost, dsthost, icmptype, icmpinfo, icmpfields);
|
||||||
}
|
}
|
||||||
return protoinfo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *icmp6hdrinfo (const u8 *data, unsigned int datalen, int detail,
|
int icmp6packethdrinfo (const u8 *data, unsigned int datalen,
|
||||||
|
char *outbuf, int outlen, int detail,
|
||||||
int frag_off, const char *srchost, const char *dsthost)
|
int frag_off, const char *srchost, const char *dsthost)
|
||||||
{
|
{
|
||||||
if (srchost == NULL)
|
if (srchost == NULL)
|
||||||
srchost = "??";
|
srchost = "??";
|
||||||
if (dsthost == NULL)
|
if (dsthost == NULL)
|
||||||
dsthost = "??";
|
dsthost = "??";
|
||||||
static char protoinfo[512] = "";
|
|
||||||
if (frag_off || datalen < sizeof(struct icmpv6_hdr)) {
|
if (frag_off || datalen < sizeof(struct icmpv6_hdr)) {
|
||||||
Snprintf(protoinfo, sizeof(protoinfo), "ICMPv6 %s > %s (type=?/code=?)",
|
return Snprintf(outbuf, outlen, "ICMPv6 %s > %s (type=?/code=?)",
|
||||||
srchost, dsthost);
|
srchost, dsthost);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const struct icmpv6_hdr *icmpv6;
|
const struct icmpv6_hdr *icmpv6;
|
||||||
|
|
||||||
icmpv6 = (struct icmpv6_hdr *) data;
|
icmpv6 = (struct icmpv6_hdr *) data;
|
||||||
Snprintf(protoinfo, sizeof(protoinfo), "ICMPv6 %s > %s (type=%d/code=%d)",
|
return Snprintf(outbuf, outlen, "ICMPv6 %s > %s (type=%d/code=%d)",
|
||||||
srchost, dsthost,
|
srchost, dsthost,
|
||||||
icmpv6->icmpv6_type, icmpv6->icmpv6_code);
|
icmpv6->icmpv6_type, icmpv6->icmpv6_code);
|
||||||
}
|
}
|
||||||
return protoinfo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -904,37 +904,27 @@ int arppackethdrinfo(const u8 *packet, u32 len, u8 *dstbuff, u32 dstlen){
|
||||||
} /* End of arppackethdrinfo() */
|
} /* End of arppackethdrinfo() */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int tcppackethdrinfo(const u8 *packet, size_t len, u8 *dstbuff, size_t dstlen,
|
int tcppackethdrinfo(const u8 *packet, size_t len, u8 *dstbuff, size_t dstlen,
|
||||||
int detail, const char *src, const char *dst){
|
int detail, const char *src, const char *dst){
|
||||||
assert(packet);
|
assert(packet);
|
||||||
assert(dstbuff);
|
assert(dstbuff);
|
||||||
|
|
||||||
const char *protoinfo = tcphdrinfo(packet, len, detail, 0, src, dst);
|
return (tcppackethdrinfo(packet, len, (char *)dstbuff, dstlen,
|
||||||
Strncpy((char*)dstbuff, protoinfo, dstlen);
|
detail, 0, src, dst) > 0 ? OP_SUCCESS : OP_FAILURE);
|
||||||
|
|
||||||
return OP_SUCCESS;
|
|
||||||
|
|
||||||
} /* End of tcppackethdrinfo() */
|
} /* End of tcppackethdrinfo() */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int udppackethdrinfo(const u8 *packet, size_t len, u8 *dstbuff, size_t dstlen,
|
int udppackethdrinfo(const u8 *packet, size_t len, u8 *dstbuff, size_t dstlen,
|
||||||
int detail, const char *src, const char *dst){
|
int detail, const char *src, const char *dst){
|
||||||
|
|
||||||
assert(packet);
|
assert(packet);
|
||||||
assert(dstbuff);
|
assert(dstbuff);
|
||||||
|
|
||||||
const char *protoinfo = udphdrinfo(packet, len, detail, 0, src, dst);
|
return (udppackethdrinfo(packet, len, (char *)dstbuff, dstlen,
|
||||||
strncpy((char*)dstbuff, protoinfo, dstlen);
|
detail, 0, src, dst) > 0 ? OP_SUCCESS : OP_FAILURE);
|
||||||
|
|
||||||
return OP_SUCCESS;
|
|
||||||
|
|
||||||
} /* End of udppackethdrinfo() */
|
} /* End of udppackethdrinfo() */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** Returns a random (null-terminated) ASCII string with no special
|
/** Returns a random (null-terminated) ASCII string with no special
|
||||||
* meaning. Returned string may be between 1 and 512 bytes and contain
|
* meaning. Returned string may be between 1 and 512 bytes and contain
|
||||||
* random letters and some whitespace.
|
* random letters and some whitespace.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue