I try to solve this but again some errors came out!!
Can anyone help me?
CODE
#include<stdio.h>
#include<netinet/in.h>
#define MACLENGTH 6
int main(void)
{
typedef struct {
unsigned int ihl:4;
unsigned int ver:4;
unsigned char tos;
unsigned int length;
unsigned int identification;
unsigned int flag_offset;
unsigned char ttl;
unsigned char protocol;
unsigned int checksum;
unsigned long int ucSource[MACLENGTH];
unsigned long int ucDestination[MACLENGTH];
}packet;
unsigned char ucSingle;
int iLoop,iVal;
char *ptr;
packet frame;
printf("Creating destination MAC address\n");
for(iLoop=0;iLoop<MACLENGTH;iLoop++)
{
printf("\nOctet%d=",iLoop);
scanf("%d", &iVal);
frame.ucDestination[iLoop] = (unsigned char)iVal;
}
printf("Enter the the type of length field value \n");
scanf("%d",&frame.length);
{
packet.ver = 4;
packet.ihl = 5;
packet.tos = 0;
packet.length = htons(0x4321);
packet.identification = htons(0x9876);
packet.flag_offset = 0;
packet.ttl = 64;
packet.protocol = 6;
packet.checksum = htons(0x1111);
packet.source = htonl(0xc0a8fa03);
packet.destination = htonl(0xc0a8faa8);
}
ptr = (char*) &frame;
printf("frame complete\n");
for(iLoop=0;iLoop<14;iLoop++)
{
ucSingle = (unsigned char)ptr[iLoop];
printf("[%d]",(int)ucSingle);
}
ptr = (char*)&packet;
printf("packet complete\n");
for(iLoop=0;iLoop<20;iLoop++)
{
ucSingle = (unsigned char)ptr[iLoop];
printf("[%d]",(int)ucSingle);
}
return 0;
}
-------------------------------------------------------
What are the errors?
-------------------------------------------------------
Sorry that i didn't post the errors!!!
cc: Error: program3.c, line 41: Invalid declarator. (declarator)
packet.ver = 4;
------^
cc: Error: program3.c, line 42: Invalid declarator. (declarator)
packet.ihl = 5;
------^
cc: Error: program3.c, line 43: Invalid declarator. (declarator)
packet.tos = 0;
------^
cc: Error: program3.c, line 44: Invalid declarator. (declarator)
packet.length = htons(0x4321);
------^
cc: Error: program3.c, line 45: Invalid declarator. (declarator)
packet.identification = htons(0x9876);
------^
cc: Error: program3.c, line 46: Invalid declarator. (declarator)
packet.flag_offset = 0;
------^
cc: Error: program3.c, line 47: Invalid declarator. (declarator)
packet.ttl = 64;
------^
cc: Error: program3.c, line 48: Invalid declarator. (declarator)
packet.protocol = 6;
------^
cc: Error: program3.c, line 49: Invalid declarator. (declarator)
packet.checksum = htons(0x1111);
------^
cc: Error: program3.c, line 50: Invalid declarator. (declarator)
packet.source = htonl(0xc0a8fa03);
------^
cc: Error: program3.c, line 51: Invalid declarator. (declarator)
packet.destination = htonl(0xc0a8faa8);
------^
cc: Error: program3.c, line 60: In this statement, "packet" is declared as a typedef, and so cannot occur as an expression. (typeexpr)
ptr = (char*)&packet;
--------------^
CODE
packet frame;
The variable that you have declared is of type packet and the name is frame. Not the opposite.
Simply change the variable name where is indicated from packet.* to frame.*
Hope this help you
-----------------------------------------------------------------------------------------
Hi..Thanks for the reply but I'm afraid that didn't solve the errors....
Can you or someone else give me specific information about that?
Thankss