ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hai everybody,
I am trying to reconstruct a HTTP session.I am asked to compare SEQ and ACK numbers. I have checked for connection establishment.Then i have recognised the Request and Response packets.Now I need to check the SEQ and ACK numbers of response packet alone..I need help how to do this.
Here is my code:
Code:
#include <netinet/if_ether.h>
#include <stdlib.h>
#include <pcap.h>
#include <errno.h>
#include <stdio.h>
#include<netinet/ip.h>
#include<netinet/tcp.h>
#include<string.h>
#define MAXBYTES2CAPTURE 2048
pcap_dumper_t *dump;
void setfilter(pcap_t * capture, char filter_app[]);
void dump_offline(pcap_t * capture, char *filename);
void view_offline(char *filename);
int a[3] = { 0, 0, 0 };
int seq;
struct http_stat {
int connection;
int packets;
} httpstatus;
struct http_request {
char response;
int packets1;
} httprequest;
struct http_response
{
int packets;
int response_code;
}httpresponse;
void process_pkt(u_char * str, const struct pcap_pkthdr *pkthdr,
const u_char * packet)
{
int dst=8080;
int in, pos = 0, pos1 = 0;
static int cnt;
u_char *ptr;
struct ether_header *eptr;
struct ip *iphdr;
struct tcphdr *tcp;
static int count = 1, i;
httprequest.packets1 = 0;
printf("Call back:");
fprintf(stdout, "%d,\n", count);
count++;
//Here i have code for printing ethernet header and IP address
iphdr = (struct ip *) (packet + sizeof(struct ether_header));
if (iphdr->ip_p == IPPROTO_TCP) {
tcp =(struct tcphdr *) (packet + sizeof(struct ether_header) + sizeof(struct ip));
packet =(const char *) (packet + sizeof(struct ether_header) + sizeof(struct ip) + sizeof(struct tcphdr));
if (tcp->syn && tcp->ack)
a[1] = 1;
else if (tcp->syn)
a[0] = 1;
else if (tcp->ack)
a[2] = 1;
}
if (a[0] == 1 && a[1] == 1 && a[2] == 1) {
cnt++;
if (cnt == 1) {
httpstatus.connection = 1;
printf("connection established\n");
}
httpstatus.connection = 0;
}
if((tcp->source)==dst && !(tcp->psh)) // This is to find REsponse packet
{
seq=tcp->seq;
/* I want to compare previous packet's seq number and current packets ack num. How should i do this. With too many structures and variables i struggle to manipulate.. Please help!! */
if(seq==tcp->ack_seq)
printf("ACK is equals to SEQ");
}
for (i=0;i<pkthdr->len; i++)
printf("%c", packet[i]);
printf("\n");
}
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.