Visual C++ :: Getting Port Number Of A Packet In Pcap File

Jan 19, 2014

I am programming in c++ with 'winpcap' . I read a .pcap file and after I want to get the source and destination of packets in that file. Here is a piece of my code:

Code:
////I define the sructures here
#pragma pack(1)
struct sniff_ethernet {
u_char ether_dhost[ETHER_ADDR_LEN]; /* Destination host address */
u_char ether_shost[ETHER_ADDR_LEN]; /* Source host address */
u_short ether_type; /* IP? ARP? RARP? etc */

[Code] ....

but the result is incorrect? where is the problem?

View 5 Replies


ADVERTISEMENT

Visual C++ :: Sending Packet Of Type Byte To Serial Port

Feb 26, 2013

I need to send a packet of type byte:

0x00, 0x01, 0x02, 0x11, 0x00, 0x00

to a device via the serial port and then I receive and store data coming from device like this:

0x01, 0x01, 0x01 , 0x00, 0x00, 0x00, 0x01, 0x00, 0x04, 0x01, 0x00.

Writing lines of code through which:

1) I create the array
2) the sending the array to serial port
3) I'll see what I'm sending
4) I get the data

I'm using Visual Studio 2010 and C + + or VC++ language.

View 14 Replies View Related

Visual C++ :: COM Port Communication

Nov 30, 2012

How to communicate my COM PORT to my visual c++ ... Means i want to read data from my port and want to show in visual c++ so what to do ...

View 1 Replies View Related

C :: Compare IPv6 Source And Destination Address From Pcap?

Feb 24, 2015

I want to examine every packet of a pcap trace file and if packet n+1 source address == packet n destination address && packet n+1 destination address == packet n source address i want to get the time between those 2 packages.

Problem: I can't compare the ipv6 adresses of src and destination.

comparing src and src is no problem. dst with dst as well

Code: ....

handle = pcap_open_offline(argv[fnum], errbuf);
while (packet = pcap_next(handle,&header))
{
...
struct ip6_hdr *ip_hdr = (struct ip6_hdr *)packet;
if (memcmp(&(ip_hdr->ip6_dst),ipv6_src,sizeof(ip_hdr->ip6_dst)))
{
.....

[code]....

if i try to compare these adresses i will never get a match. But i use a trace file with much matches. Do i need a offset in pkt_ptr? I saw some examples which deals with it.

Code:

uint32_t* test = (uint32_t*)ipv6_dst;
for (uint32_t j=0;j<sizeof(ip_hdr->ip6_dst);j++)
{
printf ("%x", *(test+j));
}
printf ("

[Code] ......

with given addresses:

Source: 2001:6f8:1c2c:2000:54c2:b056:f097:2830
Destination: 2a01:238:43f5:d900:2bf:784a:e3f8:9cd7

View 1 Replies View Related

Visual C++ :: Using The Same Port For 2 UDP Multicast Groups?

Jun 20, 2014

I habe a program, that can send and receive UDP Multicast telegrams. When I open the socket then I bind my multicast group address and the local port to a specified networkcard (our PC has 2 network cards). Now I have a special constellation:

Our PC has 2 network cards. Multicast group 1 shall use card 1 and group shall use card 2. As long as both groups use different local ports it works fine. But when both group want to use the same port number then I can receive and send telegrams only through the first group that was created. For the second one I don't even get a FD_READ event at all.

Code:
SrvAddr.sin_family = AF_INET;
SrvAddr.sin_port = htons( (WORD) nLocalPort );
SrvAddr.sin_addr.s_addr = inet_addr(strOwnIpAddress); // bind multicast group socket to a specified networkcard
// If bind socket to port failed
if( bind( hSocket,

[Code] .....

View 2 Replies View Related

Visual C++ :: How To Read And Write On Serial Port With MFC

Feb 17, 2013

I want to read and write value on serail port to Microcontroller with MFC. The MFC have no serial port tool like in VB Professionnal edition. I try to find MFC connect serial port example but I not found. If you have good example for read and write on serial port with MFC

View 2 Replies View Related

Visual C++ :: Data Stuck When Debugging With Serial Port

May 10, 2014

I am making a MFC application with VC++2012 with receiving data from Serial Port and the data is stored in a Listbox, then after processing (convert into numbers) and get these data to draw a sine wave on the chart. (I intend to make a virtual oscilloscope).

Everything works ok at the beginning, but after receiving about 300 items or above (in the Listbox) the value seem stucking (or lagging) and work very slowly.

I receive data by the SerialPort_DataReceived() method, and process of converting and drawing chart also in this method, I think this makes the system overload!!

View 1 Replies View Related

C :: How To Read And Write A File Using Serial Port

Dec 29, 2013

Explain me a working code to read and write a file using serial communication.and i need to store that file.I know normal file handling in C, but how it is through serial port i am not getting.

View 1 Replies View Related

C :: Sending A Packet Over Sockets

Oct 30, 2013

I have a socket connection already set up, my thing is what would be the best way to send a packet through sockets? My teacher wants us to convert the packet to bits first before we send it. I think he wants something like this:

Code:
struct packet{

int header
int message
int flag

}clientpacket; m

My question is how do we covert this to bits, before sending it. One of my friends said we can create a char[] array the size of the struct as a buffer. will memcpy() change the struct to bits if I copy it to the buffer?

this is how is suppose to look in bits for the header field/column.

Field : header
Field size(bits): 8
data format: Unsigned int
value example: 1
Value in bits: 0000 0001

I am confused, I think I send a structure over the socket but I did not convert it to bits before I sent it .

View 13 Replies View Related

C :: How To Create Packet Data

Jan 8, 2014

How can header info 'foo' be combined with data in buffer 'buff' to pass to sendto function

Code:

/* Send a single RTP packet, converting the RTP header to network byte order. */
int sendrtp(int fd, struct sockaddr_in ........ockAddr, struct rtpheader *foo, void *data, int len)
{
char *buff = alloca(len+sizeof(struct rtpheader));
foo->b.sequence = htons(foo->b.sequence);
foo->timestamp = htonl(foo->timestamp);
foo->ssrc = htonl(foo->ssrc);
}

[code]....

View 2 Replies View Related

C :: Send Data Packet

Mar 6, 2015

how to send datapackets. When we send a data packet from device to another, say I have a "string". How Do I send it? Are data sent as a hex or binary number?If so do i first convert the "string" into hex or binary and then send it over the communication medium(say UART)??

I have two hex numbers to be sent using the UART, do i wrap it in some specific form and send it and retrieve it on the other side?Say if I have a data structure, in that case how do i send it? Sending data packets is very cruicial in an embedded system.

View 3 Replies View Related

C :: UDP Application Simulate Packet Loss

Aug 12, 2014

have udp server-client application written in C. On the client side packet loss is detected using recvfrom function and sequence numbers of packets. How can I now simulate dropped packet's on the client side, for example if server is sending 1000 packet I want to drop 20% of them? I want to do this in the code, not for example using ip tables or WANEM or something like that. And one more thing, I have few clients and I want that they can dropped different packets, not the same one.

Code:
while(1){
nbytes = recvfrom(socket, buffer, MAX_SIZE, 0, (struct sockaddr *) &srv_addr, &addrlen);
if (nbytes != -1) {
// packet is received

}else{
//packet is not received
}
}

View 2 Replies View Related

C :: More Packet Received Than Threaded Sender Sent

Dec 15, 2014

Questions : I am running a client Server Program whose Sender and Receiver loop is given below .I have multi threaded Sender using OMP .As per My logic Receive should receive same amount of data send by Sender ,But its receiving more packet than Sender sent .I am not able to identify the Bug !!

Code:
/*
Running As Follow :
gcc UTGen.c -o Sender
gcc UTGen.c -o Receiver

./Receiver -m 0 -p 5000 -z 256 -P t

export OMP_NUM_THREADS=4
./Sender -m 1 -s localhost -p 5000 -z 256 -T 10 -P t
*/

[Code] .....

View 3 Replies View Related

C++ :: Building Multicast Packet - Memcpy Casting

Aug 19, 2014

I am just getting back in to C++ after 10 years not doing any, contributing to an open source project. I'm adding in some functionality and am hitting a road block.

I need to send a multicast packet out on the network that is structured in a certain way. I have the definition, and know what data is going in each byte. I can successfully send a message using multicast, I now just need to send the right message.

I have used a char array to hold the message, as each char represents 1 byte, and I can transmit the array.

I am having trouble putting all of the data in the right place though. If my source data is a string, then I seem to be able to convert it, but if it is a short or int, then I keep getting errors when compiling. Similarly, two of the lines, (version and type) i initially tried using char arrays with a length of one.

Should I be using memcpy or a different function, or even be doing this in a totally different way altogether? This is the code that I am using, along with the packet structure:

//Construct a Zone Query packet
// 4 bytes - Signature "Ohz " = 0x6f, 0x68, 0x7a, 0x20
// 1 bytes - Version = 1
// 1 bytes - Type (0 = Zone Query, 1 = Zone Uri)
// 2 bytes - Entire message length = 12 + zone length
// 4 bytes - Length in bytes of the zone ID
// n bytes - Zone ID to query

[Code] ....

The errors that I get are:

error: invalid conversion from ‘short int’ to ‘const void*’ [-fpermissive]
memcpy(buffer + 6, packetLength, sizeof(packetLength));
^
[Code] ....

View 9 Replies View Related

C/C++ :: Winsock Sending Packet Header With Data

Apr 16, 2015

This question is kind of a continuation of Winsock Sending X264 Nal Unit. I was finally able to solve that problem, turns out in the end I was missing a memcpy(). Now my current issue is, when I try to decode the received packets, I am shown a bunch of errors. I have attached a picture with my decoding errors. So since I am using a reliable multicast socket, which doesn't guarantee order of delivery. My initial thought is that I am getting packets out of order.

So my question is, how would I attach a packet header to my current data? Could I get away with sending the header separately? Similar to what I am doing with the nal length. If I do attach my header to the packet data, what is a good way to delimit the two?

Server:

#include <WinSock2.h>
#include <WS2tcpip.h>
#include "wsrm.h"
#include <Windows.h>
#include <stdio.h>
#include <stdint.h>
#include <iostream>
#include "x264Encoder.h"

[Code] ....

My client is just reading packets into a vector, because decoding it right away was too slow. So I thought that might have been an issue, so I decided to read in 200 packets just for testing purposes.

Attached image(s)

View 6 Replies View Related

C :: How To Calculate Total Sum Of Delay Of Receiving Side Packet

Dec 17, 2014

I want to calculate the total some of delay pf receiving Side Packet . Code is as Follow ..

What is weird that even if i invoke a sleep of 2 sec ,than its show delay always zero. Delay will be in microsec ..Is there any problem with logic or anything else..

Code:

do
{#pragma omp parallel private(nthreads, tid) {
/* Obtain thread number */
tid = omp_get_thread_num();
if (tid == 0) {
nthreads = omp_get_num_threads();

[Code]...

View 2 Replies View Related

C :: HTTP Packet Generation And Send / Receive Via Socket

Dec 26, 2014

I have Build code for sending/receiving TCP Traffic over c Socket . Now I want t add HTTP Protocol to it .

After searching out on google ,one method I found which is by GET method to send a query to a server like google.com and request a page .

But ,Suppose I saved a HTML page in my directory how can I send HTTP packet via client/server in socket using this HTML page .

View 4 Replies View Related

C/C++ :: HTTP Packet Generation And Send / Receive Via Socket

Dec 27, 2014

I have code for sending/receiving TCP traffic over C socket. Now I want to add HTTP protocol to it. After searching the web, one method I found which is by GET method to send a query to a server like google.com and request a page.

But, suppose I saved a HTML page in my directory how can I send HTTP packet via client/server in socket using this HTML page.

Server side code:

sockfd = socket(AF_INET, SOCK_STREAM, 0);
bind(sockfd, (struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0)
listen(sockfd,5);
newsockfd = accept(sockfd, (struct sockaddr *)&cli_addr,&clilen);
while (1)

[Code] .....

View 1 Replies View Related

C :: Port Mixer From OSS To ALSA

Jan 27, 2013

I'm new in c programming and my requirement is as follows. I make a code for oss mixer and now when new systems, throwing the OSS, and there is no /dev/mixer I want to port my code to alsa but my skills are minimal.

Code:
static int mixer_fd = -1, mixer_src = -1;
static char *devices[] = SOUND_DEVICE_NAMES;
int mixer_init(char *mixer_device, char *mixer_source) {
int i;

mixer_src = -1;
for (i=0;i<SOUND_MIXER_NRDEVICES;i++)
if (strcmp(mixer_source, devices[i]) == 0)

[Code] ....

Coexistance with OSS would be nice, so both could be used depending on users choice. Perhaps: if this first
part of the mixer name is a valid device file, try OSS, otherwise try ALSA?

View 1 Replies View Related

C# :: How To Multithread Port Scanning App

Jan 24, 2012

I'm creating a small port scanning app which use a port range defined by user.My problem with the code is that I find it not efficient enough meaning that it ping very slow, especially when ports are not responding meaning that I must wait for the timeout before continuing to next port.

I want to make this small app threaded. The problem here is that I'm kind of blank of how to implement threading in my program. This is my code which is a method which does the actual checking, the other part of the code is a simple button with for loop for advancing my port number.

Code:

private void ScanPort(IPAddress address, int port) {
using (TcpClient client = new TcpClient() {
IAsyncResult result = client.BeginConnect(address, port, null, null);

if (result.AsyncWaitHandle.WaitOne((int)nudTimeout.Value, false)) txtDisplay.AppendText("Port: " + port + " is open." + Environment.NewLine);
else txtDisplay.AppendText("Port: " + port + " is closed." + Environment.NewLine);
} }

I have read some basic threading tutorial but I just don't know how to implement this piece of code so I can check ports much faster.

View 3 Replies View Related

C :: Parallel Port Programming - On / Off LED

Sep 9, 2014

I try to ON and OFF the LED's via parallel port. I connect the cathode of LED's with pin number 18 that is ground and anode of each LED is connected through a 1K resistor to pin 2 to 8. I write the following programe

Code:
#include <dos.h>
#include <stdio.h>
#include <conio.h>
#define PORTID 0x378
void main(){
outportb(PORTID,0x00);
getch()
}

But when i connect the LEDS to the parallel port all the LEDS are LIT while i also change the 0x00 to 0xff and so on. But no effect on the LED's.

View 8 Replies View Related

C :: Parallel Port Where To Start

Jan 1, 2014

I started writing in c because I want to control relays with the parallel port, or anything else. Doesn't really matter what I use I just need to know where to start. Trying to send and receive data from the outside world with c programming on a GNU/Linux os? If so any good some what up to date resources online?

View 5 Replies View Related

C++ :: Output Voltage On USB Port

Oct 26, 2013

I am on a project. I have a laptop and It doesn't have a COM port. So what I would like to do is to get a usb to RS232 cable and write a code so to output voltages on usb and measure it on the RS-232 end. Can I vary the output voltage to my needs?

View 2 Replies View Related

C++ :: Port A Pc Game To Android

Jul 10, 2013

How do I port a pc game to android? Do I just include libraries or do I have to rewrite all my code?

View 5 Replies View Related

C/C++ :: How To Write To The Parallel Port

Apr 16, 2007

How To write to the parallel port under windows xp using Visual C++ ->MS Studio studio 2005

View 4 Replies View Related

C++ :: Inserting Hex Value And Sending It At Serial Port

Dec 17, 2013

I am trying to convert decimal value 1 to 32 to hex value and insert it at 4th pos of char array and send it as hex value at the serial port .

My issue is it is converting to decimal to hex value but when it sends, it treat the converted hex value as char and sends it equivalent hex value.

For example

if decimal =1 then its hex = 1.
so , writebuffer[3] =1

But when we send whole writebuffer through send function, it treat this 1 as char and sends its hex value as 31. how to send its hex value.

unsigned int i=0;
char hex[3];
unsigned char hexunsigned[3];
unsigned int dec;
do {
unsigned char writebuffer[8] ={0x01, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

[Code] ....

The send function is

void serial::send(unsigned char data[], DWORD noOfByte) {
DWORD dwBytesWrite;
WriteFile(serialHandle, data, noOfByte, &dwBytesWrite, NULL);
}

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved