Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

factor out struct tcphdr #248

Merged
merged 2 commits into from Apr 11, 2013
Merged
Changes from all commits
Commits
File filter
Filter file types
Jump to
Jump to file
Failed to load files.

Always

Just for now

@@ -20,6 +20,8 @@
#define __FAVOR_BSD
#include <netinet/tcp.h>
#include <netinet/udp.h>
#include "tcphdr.h"

#include <arpa/inet.h>
#include <pcap.h>
#include "SIPdump.h"
@@ -494,7 +496,7 @@ static void sniff_logins(unsigned char *args,
{
const struct ip6_hdr *ip6;
const struct ip *ip_hdr;
const struct tcphdr *tcp_hdr;
const struct tcp_hdr *tcp_hdr;
const struct udphdr *udp_hdr;
unsigned char *payload;
int ip_protocol, ip_tot_len;
@@ -548,7 +550,7 @@ static void sniff_logins(unsigned char *args,
/* Check proto and get source and destination port */
switch (ip_protocol) {
case IPPROTO_TCP:
tcp_hdr = (struct tcphdr *) (packet + size_ip);
tcp_hdr = (struct tcp_hdr *) (packet + size_ip);
size_proto = tcp_hdr->th_off * 4;
if (size_proto < 20) {
debug(
@@ -0,0 +1,36 @@
#ifndef TCPHDR_H
#define TCPHDR_H

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>
#include <endian.h>

struct tcp_hdr {
uint16_t th_sport;
uint16_t th_dport;
uint32_t th_seq;
uint32_t th_ack;
#if __BYTE_ORDER == __LITTLE_ENDIAN
uint8_t th_x2:4;
uint8_t th_off:4;
#elif __BYTE_ORDER == __BIG_ENDIAN
uint8_t th_off:4;
uint8_t th_x2:4;
#else
#error invalid byte order
#endif
uint8_t th_flags;
uint16_t th_win;
uint16_t th_sum;
uint16_t th_urp;
};

#ifdef __cplusplus
}
#endif

#endif

@@ -40,6 +40,7 @@
#define __FAVOR_BSD
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include "tcphdr.h"
#include <pcap.h>

using namespace std;
@@ -117,12 +118,12 @@ bool Packet_Reader::kick()
continue; // bogus IP header

if (header.len <
sizeof(struct ether_header) + size_ip + sizeof(tcphdr))
sizeof(struct ether_header) + size_ip + sizeof(struct tcp_hdr))
continue;

const struct tcphdr *tcp =
const struct tcp_hdr *tcp =
reinterpret_cast <
const struct tcphdr *>(packet + sizeof(ether_header) +
const struct tcp_hdr *>(packet + sizeof(ether_header) +
size_ip);

size_t size_tcp = tcp->th_off * 4;
ProTip! Use n and p to navigate between commits in a pull request.