#ifndef TCP_HPP
#define TCP_HPP
#include <netinet/tcp.h>
#include <string>
#include <iostream>
#include "port_protocol.hpp"
void del_tcp(const u_char* ptr_packet, size_t used_len)
{
if (ptr_packet == NULL)
{
return ;
}
bool is_find;
const struct tcphdr* ptr_tcp = (struct tcphdr*)(ptr_packet+used_len);
std::string sp = get_protocol_by(ntohs(ptr_tcp->source), "tcp", is_find);
if (!is_find)//find not service by src_port, try dest_port
{
std::string dp = get_protocol_by(ntohs(ptr_tcp->dest), "tcp", is_find);
if (!is_find)//find not service by dest_port
{
std::cout<<_("tcp load undefined protocol")<<std::endl;
}
else
{
std::cout<<_("tcp load protocol is: ")<<dp<<std::endl;
}
}
else
{
std::cout<<_("tcp load protocol is: ")<<sp<<std::endl;
}
}
#endif
#define TCP_HPP
#include <netinet/tcp.h>
#include <string>
#include <iostream>
#include "port_protocol.hpp"
void del_tcp(const u_char* ptr_packet, size_t used_len)
{
if (ptr_packet == NULL)
{
return ;
}
bool is_find;
const struct tcphdr* ptr_tcp = (struct tcphdr*)(ptr_packet+used_len);
std::string sp = get_protocol_by(ntohs(ptr_tcp->source), "tcp", is_find);
if (!is_find)//find not service by src_port, try dest_port
{
std::string dp = get_protocol_by(ntohs(ptr_tcp->dest), "tcp", is_find);
if (!is_find)//find not service by dest_port
{
std::cout<<_("tcp load undefined protocol")<<std::endl;
}
else
{
std::cout<<_("tcp load protocol is: ")<<dp<<std::endl;
}
}
else
{
std::cout<<_("tcp load protocol is: ")<<sp<<std::endl;
}
}
#endif
本文深入探讨了TCP协议的解析过程,详细介绍了如何通过解析TCP头部信息来识别不同的服务和协议,包括源端口、目标端口以及协议类型。通过实例展示了在不同情况下如何根据端口信息判断TCP负载所承载的协议类型。
3万+

被折叠的 条评论
为什么被折叠?



