C :: Program Not Printing Mac Address Correctly From Ethernet Header

Jun 2, 2013

I have a procedure that prints the fields of ethernet frames and ip headers. I have an issue with the src mac addr being printed incorrectly and incompletely. The part in red is the trouble code.

Code:
1#include "sniffer.h"
2
3void print_headers(struct ethhdr * ethhdr, struct ip * iphdr){
4
5 char ipstr_src[INET_ADDRSTRLEN];
6 char ipstr_dst[INET_ADDRSTRLEN];
7 char macstr_dst[ETH_ALEN], macstr_src[ETH_ALEN];

[Code] ....

View 2 Replies


ADVERTISEMENT

C/C++ :: Implementing Program That Sends And Receives Raw Ethernet Frames

Apr 15, 2013

I am fairly new to the topic of the ethernet and the data link layer and I am trying to write a C program which allows the sending and receiving of ethernet frames.

I am trying to have my program send the ethernet frame to myself, so the program will have the same source and destination mac addresses.

The program that I'm using is a modified version of the code from [URL] ....

I keep having trouble with the recvfrom() function, it seems to just be blocking and the program doesn't terminate. From the code, I am trying send the ethernet frame and have the recvfrom() function be able to retrieve the frame and store it in a buffer. But because recvfrom() function is just blocking, it seems to me that the sendto() function was not able to successfully send the frame.

Here is my code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>    /* Must precede if*.h */
#include <linux/if.h>
#include <linux/if_ether.h>

[Code] ....

This is on a linux machine ....

View 2 Replies View Related

C++ :: Board Not Printing Correctly

Jul 19, 2013

I'm writing a version of the classic Snake game. However, my board is not printing correctly. The right hand border is in the incorrect location. Also, when I randomly generate where the food ('X') is located, it only generates on the edges of the boundaries.

#include <iostream>
#include <cstdlib>
using namespace std;
const int ROWS = 21;
constint COLS = 61;

[code].....

View 5 Replies View Related

C/C++ :: Pushing Ethernet Data Packets To A Vector?

Jul 17, 2014

I am receiving packets of data from an ethernet cable. This is the line of code that is streaming in data from the ethernet cable:

size_t num_rx_samps = rx_stream->recv(&buff.front(), buff.size(), md, 3.0, enable_size_map);

and here is my attempt to push it onto a vector:

std::vector<size_t> processing_queue; //HERE IS WHERE I'M TRYING TO PUSH THE PACKETS ONTO A VECTOR
processing_queue.push_back(num_rx_samps);

I previously had my program saving to a .dat file (the commented out lines), but I'm trying to change it to pushing values onto a vector so I can stream the data packets from the ethernet cable to be processed. However, I'm having issues with pushing the data packets onto the vector?

The following is the code:

#include <uhd/types/tune_request.hpp>
#include <uhd/utils/thread_priority.hpp>
#include <uhd/utils/safe_main.hpp>

[Code].....

View 1 Replies View Related

C++ :: GPA - Program Not Averaging Correctly?

Feb 7, 2015

My program isnt averaging correctly.

#include <iostream>
#include <string>
#include <iomanip>
#include <cstdlib>
using namespace std;

struct nameGPA {

[Code] .....

View 4 Replies View Related

C++ :: Program Is Not Calculating Sums Correctly?

Jun 20, 2014

I am getting this weird error when calculating sums. Here is what my program does: it generates two random numbers and then randomly puts either an addition or subtraction sign between the two and then I am asked to enter what the correct answer for that question is. But on some of the subtraction questions when I give the answer it says I got it wrong after which the program shows the right answer. What's confusing is that the answer the computer calculates is the same that I entered. Anyways the complete program and a screenshot of the console window which shows the error are below. The function in question here is decAddSub at line 54. The error is shown in the first sum in the output window. It doesn't affect addition problems and only affects some of the subtraction problems.

#include<iostream>
#include<stdlib.h>
#include<time.h>
#include<random>

[Code].....

View 2 Replies View Related

C++ :: Program Is Not Reading In Values From DAT File Correctly

May 20, 2013

We are supposed to split this lab into 3 files a .h and 2 .cpp's. The code I'll be talking about is going to be directed at the main.cpp file. Basically we are supposed to be able to enter as many classes into the program and when you are done the program is supposed to save the contents into a .dat file. This lab is working off of an older lab so I already have a .dat file I am trying to test with this program by reading it into my program when I first run it I prompt if the user wants to load previously entered courses and if they reply with a 'Y' the program will load the contents of the .dat file. Problem is right now when I load from the .dat file only the first class is correct. Every other class after that is just giberish. I've tried everything but can't get the restore part working. I also cannot get the save to .dat portion of this lab working either.Here is my code:

#include "Course.h"
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
using std::ios;

[code]....

View 1 Replies View Related

C :: Program Won't Correctly Print Proper Totals On Screen

Oct 10, 2014

Why this program won't correctly print the proper totals on screen? See my code and the included screenshot.

Code:
#include <stdio.h>
int main(void) {
int total, first, second;
printf("Enter 2 numbers:

[Code] .....

View 4 Replies View Related

C/C++ :: Program To Emulate Shopping List - File Not Reading Correctly

Jan 28, 2015

I have written an program to emulate a shopping list. Everything works fine, until I try to read in from a file. Here is my read and write code (the write code looks like it is working ok, but I figured I would include it just in case), and an example of what happens to a list that has been written, then read back in.

I took this list, and wrote it to a file, then read that file back in. The .txt file looks like everything was written out properly, but when I try to read that exact same list back in, this is what I get:

View 10 Replies View Related

C++ :: Program That Will Display Name / Address And Age?

Jun 21, 2014

C++: write a c++ program that will display your name, address and age..

View 3 Replies View Related

C++ :: Address Book - Program Stops After Cin

Dec 6, 2013

the program is of an address book. the syntax is all fine, and the initial menu of options does show up. but once you punch in the cin, the program just stops.

View 9 Replies View Related

C :: Program Not Printing Exactly

Mar 9, 2013

I expected this program to print out:

Code: Enter your desired monthly salary: $2000___
Gee! $2000.00 a month is $24000.00 a year. Instead, it printed out:
Code: Enter your desired monthly salary: $2000___

Gee! $2000.00 a month is $24000.00 a year. I don't understand how it got the extra nextline in the middle.

Here is the code:

Code:

#include <stdio.h>
int main(void) {
float salary;
printf("aEnter your desired monthly salary:");

[Code].....

View 2 Replies View Related

C++ :: How To Use Two Header Files In Program

Sep 17, 2013

I want to use two header files in my program. Here is exactly what I want to do.

-In the first header I have a binary tree and a structure.
-In the second file I have another functions that need to use the structure in the first header.
-I also want to use a function from the second header in the first.
-And finally I want to do actions with both headers in a "main.cpp" file that contains only int main() function.

How to include the headers in each other and in the main.cpp to be able to do the actions above?

I try to include the first header in the second one and the second one in the first header. Then I include both headers in the main.cpp file. But the compiler shows me many errors.

View 5 Replies View Related

C++ :: Program For Printing All The Combinations Of A String

Feb 17, 2013

I am trying to write a program for printing all the combinations of a string. Why this program is giving the error message.

"First-chance exception at 0x761bc41f in word.exe: Microsoft C++ exception: std::out_of_range at memory location 0x0026f6b4..
Unhandled exception at 0x761bc41f in word.exe: Microsoft C++ exception: std::out_of_range at memory location 0x0026f6b4.." when i try to run this in MVS 2010

#include<iostream>
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include<conio.h>
void combination(std::string input,int length,std::string buffer,int allowedno)

[Code] .....

View 1 Replies View Related

C/C++ :: Program Printing Out Random Symbols?

Jan 19, 2014

I'm experimenting, making a little client/server but when it cout's the buffer, it prints out random symbols.

Server

#include <iostream>
#include <windows.h>
#include <WinSock2.h>
int main() {
char buffer[1024];
WSAData wsa;

[Code] ......

View 9 Replies View Related

C/C++ :: Create Welcome Text Header During Program Runs?

Apr 20, 2014

I want to create a welcome text header during the program runs. I wanna keep it at the top while the program is running (like asking for input@ showing output).

EG:
-----
WELCOME
----- //Stay until end of the program
// output/input. "WELCOME" stay at the top

View 2 Replies View Related

C++ :: Program Crashes While Printing Data From Vectors

Nov 23, 2013

I have a local student and international student class inherit from student class. read and print are virtual functions. After i have set all the member variables when i wan to print out all the student information, my program crashes.

Code: int main()
{
clsUniversityProgram objProgram[3];
for (int x = 0; x < 3; x++)

[Code] ....

View 4 Replies View Related

C :: Program Printing A Random Number Instead Of Variable

Mar 6, 2015

Program that has the user enter 5 digits then asks the user what they want to know about the 5 digits. My issue is when the program goes to print the value, its a totally ill related number

10 34 8 17 50

program prints out:

2 for smallest
79 for largest
119 for sum
23.80 for average

Code:

#include <stdio.h>#include <stdlib.h>
int main(void)
{
int smallNum, largNum, count=0, sum=0, value, choice;
double avgNum;
printf("Enter 5 integers
");
printf("
");

[Code]...

View 7 Replies View Related

C++ :: Rectangle Class Program - Header File Will Not Compile

Mar 7, 2014

I am currently learning OOP, and I can't figure out what the problem is with my header file. The rest of the program complies fine though. I am using g++ on UNIX.

myClass.h:9:23: error: Rectangle.h: No such file or directory
myClass.h: In function ‘int main()’:
myClass.h:13: error: ‘Rectangle’ was not declared in this scope
myClass.h:13: error: expected `;' before ‘rect’
myClass.h:14: error: ‘rect’ was not declared in this scope

Code:
myClass.h
/* This header file contains, The main function for my rectangle class program.*/

#include "Rectangle.h"
using namespace std;
int main(){
Rectangle rect;
rect.displayMaxRectangles();
rect.process();
rect.summary();

[Code] .....

View 1 Replies View Related

C++ :: Program Which Reads TIFF Files And Shows Header

Dec 13, 2013

I have program which reads tiff files, and shows header.

Code:

#include <iostream>
#include <fstream>
using namespace std;
#define II 1
#define MM 2
typedef struct {
short unsigned byte_order;

[Code] ....

but I have a problem, my program doesn't shows:

ImageWidth
ImageLength
XResolution
YResolution

I must do this, without using another library like libtiff...

View 1 Replies View Related

C/C++ :: Check Printing Program Breaks Halfway Through Running

Apr 3, 2015

For my c++ we're suppose to write a program that prints out a check. It's suppose to translate the numeric value of the dollars to worded strings.

Header File:

#ifndef CHECKWRITING_H
#define CHECKWRITING_H
#include <string>

[Code]....

View 1 Replies View Related

C++ :: Calling A Function From A Header To Another Header?

May 16, 2014

I'm doing a compiler, and I'm using writing everything in headerfiles.

at the moment I have lexer.h, token.h and for this case I need reservedWords.h

reservedWords.h is made up of enums showing the needed words

in token.h I have a function called reservedWords reservedLookup(string str) which returns a reservedWord (enum)

now in lexer.h I have a function called Token* getNextToken() in which I need to make use of the function reservedLookup found in token.h

note that all of them are classes apart from reservedwords as in

class Lexer
{
public: .....
}
class token
{
public .....
}

how I can call that function?

I tried declaring reservedWords reservedLookup (string str) BUT obviously it's directing me as Lexer::reservedLookup and not as Token::reservedLookup

When I tried using Token::reservedLookup it gave me

E:Universitycompilerslexer.h|65|error: cannot declare member function 'Token::reservedLookup' within 'Lexer'|

N.B I use namespace std, that's why I didnot write std::string str

View 1 Replies View Related

Visual C++ :: Should Precompiled Header Files Also Be Included In Source Header Files?

Sep 16, 2013

When including a header file in stdafx.h, should that file still be included in the source file where it is actually used?

If it is included in both places, is the one in the source file ignored?

View 5 Replies View Related

C :: How To Typecast Correctly

Feb 17, 2015

so i have this problem with my code ( not running)i want to read ( 2 double numbers x,y) and ( one integer z) then calculate reminder of x and y ( after they both converted to integer) and the formula : x^2 + y^2 + z^2and : x^z + y^z

here is what i came up with :

Code:
// compute.c

#include<stdio.h>
#include<math.h>
int main(void)
{

[Code]....

it also says in q : be sure to test the user input to make sure x,y,z are positive . any negative or zero should not be accepted and must print error msg ==> do i have to have an if statement here ? or the while loop is enough ?

View 9 Replies View Related

C :: How To Use Pow Function Correctly

Jan 23, 2015

I'm working on a school assignment that asks us to make code calculating the quadratic formula.

Code:

#include <stdio.h>
#include <math.h>
int main(void) {
double a = 0;
double b = 0;
double c = 0;
double discriminant = 0;
double solution = 0;
double solution2= 0;
}

[code]....

View 4 Replies View Related

C++ :: CPP File Not Opening Correctly?

Nov 2, 2014

When I try to open the cpp source in Visual Studio, it just opens a blank notepad window. The cpp file says its 4 kb and there was code in it.

View 5 Replies View Related







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