about UDP packet capture error

P

pmm

hi
I am a beginner in network programming I am trying out a UDP packet
transfer between a windows machine and a linux I created a structure on
both sides (ie on linux and on windows) and I sent using a UDP but the
packetI captured appeared to be with some extra-added data
I tried to clear the buffer before packet is ordered and sent and even
cleared the buff before capturing it on receiving side I am placing
both the print and structure I used
kindly suggest me what to modify

my structure
<code>
typedef struct
{
INT32S connId;
INT32S seqNo;
}addrData_t;

typedef struct
{
INT16S typeId;
INT16S length;
addrData_t addrData;

}addrItem_t;

typedef struct
{
INT16S typeId;
INT16S length;
INT8U data[1];
}dataItem_t;

typedef struct
{
INT16S itemCount;
addrItem_t addrItem;
dataItem_t dataItem;
} udpPacket_t;
</code>


print of windows from sending side
2 0 0 0 2 80 0 0 8 0 0 0 15 d6 99 b6 0 0 0 0 UDP PACKET SENT

typeid 8002
len 8
conn b69a263b
seq 0
dtype b1
dlen 1
data 12




print of linux from receiving side
2 0 0 0 2 ffffff80 0 0 8 0 0 0 15 ffffffd6 ffffff99
ffffffb6 0 0 0 0

Type Id 0
length 8002
ConnId 80000
Seq no d6150000
Data typeid b699
Data length 0
Item Count 2


kindly suggest what mistake I did both machines are same "ENDEIN"s

thanks regards
PMM
 
N

Nick Keighley

pmm said:
I am a beginner in network programming I am trying out a UDP packet
transfer between a windows machine and a linux I created a structure on
both sides (ie on linux and on windows) and I sent using a UDP but the
packetI captured appeared to be with some extra-added data
I tried to clear the buffer before packet is ordered and sent and even
cleared the buff before capturing it on receiving side I am placing
both the print and structure I used
kindly suggest me what to modify

this is generally a bad idea as padding may be added to the structures
and it
doesn't have to match on different implementations.
my structure
<code>
typedef struct
{
INT32S connId;
INT32S seqNo;
}addrData_t;

typedef struct
{
INT16S typeId;
INT16S length;
addrData_t addrData;

}addrItem_t;

typedef struct
{
INT16S typeId;
INT16S length;
INT8U data[1];
}dataItem_t;

typedef struct
{
INT16S itemCount;
addrItem_t addrItem;
dataItem_t dataItem;
} udpPacket_t;
</code>


print of windows from sending side
2 0 0 0 2 80 0 0 8 0 0 0 15 d6 99 b6 0 0 0 0 UDP PACKET SENT

typeid 8002
len 8
conn b69a263b
seq 0
dtype b1
dlen 1
data 12




print of linux from receiving side
2 0 0 0 2 ffffff80 0 0 8 0 0 0 15 ffffffd6 ffffff99
ffffffb6 0 0 0 0

note the sent received data appears to match the sent data (modulo some

sign extension problems) use unsigned chars to store octetes ("bytes")
transferred over a comms link.

To be certain you need to load your structures an element at a time

dataItem_t.typeId = get_word();
dataItem_t.length = get_word();
for (i = 0; i < dataItem_t.length; i++)
dataItem_t.data = get_byte();

code untested, uncompiled, unreviewed etc. etc. not suitable for safety
critical applications.
Type Id 0
length 8002
ConnId 80000
Seq no d6150000
Data typeid b699
Data length 0
Item Count 2

kindly suggest what mistake I did both machines are same "ENDEIN"s

yes, but are all machines in the universe the same endianess?
 
P

pmm

Nick said:
pmm said:
I am a beginner in network programming I am trying out a UDP packet
transfer between a windows machine and a linux I created a structure on
both sides (ie on linux and on windows) and I sent using a UDP but the
packetI captured appeared to be with some extra-added data
I tried to clear the buffer before packet is ordered and sent and even
cleared the buff before capturing it on receiving side I am placing
both the print and structure I used
kindly suggest me what to modify

this is generally a bad idea as padding may be added to the structures
and it
doesn't have to match on different implementations.
my structure
<code>
typedef struct
{
INT32S connId;
INT32S seqNo;
}addrData_t;

typedef struct
{
INT16S typeId;
INT16S length;
addrData_t addrData;

}addrItem_t;

typedef struct
{
INT16S typeId;
INT16S length;
INT8U data[1];
}dataItem_t;

typedef struct
{
INT16S itemCount;
addrItem_t addrItem;
dataItem_t dataItem;
} udpPacket_t;
</code>


print of windows from sending side
2 0 0 0 2 80 0 0 8 0 0 0 15 d6 99 b6 0 0 0 0 UDP PACKET SENT

typeid 8002
len 8
conn b69a263b
seq 0
dtype b1
dlen 1
data 12




print of linux from receiving side
2 0 0 0 2 ffffff80 0 0 8 0 0 0 15 ffffffd6 ffffff99
ffffffb6 0 0 0 0

note the sent received data appears to match the sent data (modulo some

sign extension problems) use unsigned chars to store octetes ("bytes")
transferred over a comms link.

To be certain you need to load your structures an element at a time

dataItem_t.typeId = get_word();
dataItem_t.length = get_word();
for (i = 0; i < dataItem_t.length; i++)
dataItem_t.data = get_byte();

code untested, uncompiled, unreviewed etc. etc. not suitable for safety
critical applications.
Type Id 0
length 8002
ConnId 80000
Seq no d6150000
Data typeid b699
Data length 0
Item Count 2

kindly suggest what mistake I did both machines are same "ENDEIN"s

yes, but are all machines in the universe the same endianess?


--
Nick Keighley

pictures and philosophy
www.nick-keighley.co.uk/john_powers



Dear Mr Nick
I did changed the signed to unsigned but still is same
I am placing the code which copies the data
plz do correct me if I am wrong
INT8U *buff=GetMemBuff(MAX_DATA_LEN);
<code>
udpPacket_t *udpPacket=(udpPacket_t*)buff ;
addrItem_t *ai=&udpPacket->addrItem;
dataItem_t *di=&udpPacket->dataItem;
addrData_t *ad=&ai->addrData;
static int sockFd; int len,thrdId; int siz; int kkk; extern int
udp_port_no;
extern int connId;
/*static hostent* h;*/
// sockHdl_t *sock = GetNewSockObj();
static sockAddr_t srv;
wVersionRequested = MAKEWORD( 2, 0 );
memset(buff,0,MAX_DATA_LEN);

udpPacket->itemCount=2;

ai->typeId=0x8002;
ai->length=8;
ad->connId=connId;
ad->seqNo=0;
di->typeId=0x00b1;
di->length=1;
di->data[0]=0x12;

siz=sizeof(udpPacket);
printf("\n udpacket size %d\n",siz);

printf("\n typeid %x",ai->typeId);
printf("\nlen %x",ai->length);
printf("\nconn %x",ad->connId);
printf("\nseq %x",ad->seqNo);
printf("\ndtype %x",di->typeId);
printf("\ndlen %x",di->length);
printf("\n data %x",di->data[0]);

srv.sin_family=AF_INET;

</code>
 
F

Flash Gordon

pmm said:
hi
I am a beginner in network programming I am trying out a UDP packet
transfer between a windows machine and a linux I created a structure on
both sides (ie on linux and on windows) and I sent using a UDP but the
packetI captured appeared to be with some extra-added data

The network side is off topic here, but I suspect you are tripping over
problems to do with standard C. In future you could well trip over other
problems which I am going to point out as well.
I tried to clear the buffer before packet is ordered and sent and even
cleared the buff before capturing it on receiving side I am placing
both the print and structure I used
kindly suggest me what to modify

my structure
<code>
typedef struct
{
INT32S connId;
INT32S seqNo;
}addrData_t;

typedef struct
{
INT16S typeId;
INT16S length;
addrData_t addrData;

}addrItem_t;

typedef struct
{
INT16S typeId;
INT16S length;
INT8U data[1];
}dataItem_t;

typedef struct
{
INT16S itemCount;
addrItem_t addrItem;
dataItem_t dataItem;
} udpPacket_t;

The compiler is allowed to insert padding between fields in a structure,
so there is no guarantee that the above will have the same layout on
both machines. Manually packing the bytes in to an array of unsigned
char would be more portable.
</code>


print of windows from sending side
2 0 0 0 2 80 0 0 8 0 0 0 15 d6 99 b6 0 0 0 0 UDP PACKET SENT

typeid 8002
len 8
conn b69a263b
seq 0
dtype b1
dlen 1
data 12




print of linux from receiving side
2 0 0 0 2 ffffff80 0 0 8 0 0 0 15 ffffffd6 ffffff99
ffffffb6 0 0 0 0

You haven't shown the code you are using to print this out. I'm guessing
that you are using a char pointer (or char array). On the linux system
char is obviously signed by default, but the windows system is
configured to have char unsigned. You should in general explicitly use
unsigned char when dealing with data as bytes.
Type Id 0
length 8002
ConnId 80000
Seq no d6150000
Data typeid b699
Data length 0
Item Count 2

kindly suggest what mistake I did both machines are same "ENDEIN"s

You have not shown the code, so all anyone can do is guess. I've made
guesses above, but the problem could be something completely unrelated
to what I have pointed out.

In future, any time you want help with code actually post the code (copy
and paste, don't retype) since not all of us have systems that implement
the mind reading over IP protocols. To make the code topical here you
could replace the network interfacing code with writing to/reading from
files using the standard C routines. Since I think your current problems
are not with the actual network code this would allow us to comment on
it here. If you have problems with the networking try asking on groups
dedicated to either networking your your systems of interest.
 
N

Nick Keighley

pmm said:
Nick said:
pmm wrote:
I am a beginner in network programming I am trying out a UDP packet
transfer between a windows machine and a linux I created a structure on
both sides (ie on linux and on windows) and I sent using a UDP but the
packetI captured appeared to be with some extra-added data
I tried to clear the buffer before packet is ordered and sent and even
cleared the buff before capturing it on receiving side I am placing
both the print and structure I used
kindly suggest me what to modify

this is generally a bad idea as padding may be added to the structures
and it doesn't have to match on different implementations.
my structure
<code>
typedef struct
{
INT32S connId;
INT32S seqNo;
}addrData_t;

typedef struct
{
INT16S typeId;
INT16S length;
addrData_t addrData;

}addrItem_t;

typedef struct
{
INT16S typeId;
INT16S length;
INT8U data[1];
}dataItem_t;

typedef struct
{
INT16S itemCount;
addrItem_t addrItem;
dataItem_t dataItem;
} udpPacket_t;
</code>


print of windows from sending side
2 0 0 0 2 80 0 0 8 0 0 0 15 d6 99 b6 0 0 0 0 UDP PACKET SENT

typeid 8002
len 8
conn b69a263b
seq 0
dtype b1
dlen 1
data 12

print of linux from receiving side
2 0 0 0 2 ffffff80 0 0 8 0 0 0 15 ffffffd6 ffffff99
ffffffb6 0 0 0 0

note the sent received data appears to match the sent data (modulo some

sign extension problems) use unsigned chars to store octetes ("bytes")
transferred over a comms link.

To be certain you need to load your structures an element at a time

dataItem_t.typeId = get_word();
dataItem_t.length = get_word();
for (i = 0; i < dataItem_t.length; i++)
dataItem_t.data = get_byte();

code untested, uncompiled, unreviewed etc. etc. not suitable for safety
critical applications.
Type Id 0
length 8002
ConnId 80000
Seq no d6150000
Data typeid b699
Data length 0
Item Count 2


Dear Mr Nick
:)


I did changed the signed to unsigned but still is same
I am placing the code which copies the data
plz do correct me if I am wrong

INT8U *buff=GetMemBuff(MAX_DATA_LEN);
<code>
udpPacket_t *udpPacket=(udpPacket_t*)buff ;
addrItem_t *ai=&udpPacket->addrItem;
dataItem_t *di=&udpPacket->dataItem;
addrData_t *ad=&ai->addrData;
static int sockFd; int len,thrdId; int siz; int kkk; extern int
udp_port_no;
extern int connId;
/*static hostent* h;*/
// sockHdl_t *sock = GetNewSockObj();
static sockAddr_t srv;
wVersionRequested = MAKEWORD( 2, 0 );
memset(buff,0,MAX_DATA_LEN);

udpPacket->itemCount=2;

ai->typeId=0x8002;
ai->length=8;
ad->connId=connId;
ad->seqNo=0;
di->typeId=0x00b1;
di->length=1;
di->data[0]=0x12;

siz=sizeof(udpPacket);
printf("\n udpacket size %d\n",siz);

printf("\n typeid %x",ai->typeId);
printf("\nlen %x",ai->length);
printf("\nconn %x",ad->connId);
printf("\nseq %x",ad->seqNo);
printf("\ndtype %x",di->typeId);
printf("\ndlen %x",di->length);
printf("\n data %x",di->data[0]);

srv.sin_family=AF_INET;

</code>

this is, presumably, the outgoing side. I was suggesting what to do on
the
*incoming* side. As other posters have commented we are left guessing a
bit...


--
Nick Keighley

Quantum Boggum Sort:
Q1. use a source of quantum noise (eg. radioactive decay) to
randomly permutate an array.
Q2. if the array is not ordered, destroy the universe (*)
Q3. if you reached this step your universe has sorted the array
in O(n) time.
(*) [100] this is left as an exercise
 
P

pmm

Nick said:
pmm said:
Nick said:
pmm wrote:
I am a beginner in network programming I am trying out a UDP packet
transfer between a windows machine and a linux I created a structure on
both sides (ie on linux and on windows) and I sent using a UDP but the
packetI captured appeared to be with some extra-added data
I tried to clear the buffer before packet is ordered and sent and even
cleared the buff before capturing it on receiving side I am placing
both the print and structure I used
kindly suggest me what to modify

this is generally a bad idea as padding may be added to the structures
and it doesn't have to match on different implementations.

my structure
<code>
typedef struct
{
INT32S connId;
INT32S seqNo;
}addrData_t;

typedef struct
{
INT16S typeId;
INT16S length;
addrData_t addrData;

}addrItem_t;

typedef struct
{
INT16S typeId;
INT16S length;
INT8U data[1];
}dataItem_t;

typedef struct
{
INT16S itemCount;
addrItem_t addrItem;
dataItem_t dataItem;
} udpPacket_t;
</code>


print of windows from sending side
2 0 0 0 2 80 0 0 8 0 0 0 15 d6 99 b6 0 0 0 0 UDP PACKET SENT

typeid 8002
len 8
conn b69a263b
seq 0
dtype b1
dlen 1
data 12

print of linux from receiving side
2 0 0 0 2 ffffff80 0 0 8 0 0 0 15 ffffffd6 ffffff99
ffffffb6 0 0 0 0

note the sent received data appears to match the sent data (modulo some

sign extension problems) use unsigned chars to store octetes ("bytes")
transferred over a comms link.

To be certain you need to load your structures an element at a time

dataItem_t.typeId = get_word();
dataItem_t.length = get_word();
for (i = 0; i < dataItem_t.length; i++)
dataItem_t.data = get_byte();

code untested, uncompiled, unreviewed etc. etc. not suitable for safety
critical applications.

Type Id 0
length 8002
ConnId 80000
Seq no d6150000
Data typeid b699
Data length 0
Item Count 2


Dear Mr Nick
:)


I did changed the signed to unsigned but still is same
I am placing the code which copies the data
plz do correct me if I am wrong

INT8U *buff=GetMemBuff(MAX_DATA_LEN);
<code>
udpPacket_t *udpPacket=(udpPacket_t*)buff ;
addrItem_t *ai=&udpPacket->addrItem;
dataItem_t *di=&udpPacket->dataItem;
addrData_t *ad=&ai->addrData;
static int sockFd; int len,thrdId; int siz; int kkk; extern int
udp_port_no;
extern int connId;
/*static hostent* h;*/
// sockHdl_t *sock = GetNewSockObj();
static sockAddr_t srv;
wVersionRequested = MAKEWORD( 2, 0 );
memset(buff,0,MAX_DATA_LEN);

udpPacket->itemCount=2;

ai->typeId=0x8002;
ai->length=8;
ad->connId=connId;
ad->seqNo=0;
di->typeId=0x00b1;
di->length=1;
di->data[0]=0x12;

siz=sizeof(udpPacket);
printf("\n udpacket size %d\n",siz);

printf("\n typeid %x",ai->typeId);
printf("\nlen %x",ai->length);
printf("\nconn %x",ad->connId);
printf("\nseq %x",ad->seqNo);
printf("\ndtype %x",di->typeId);
printf("\ndlen %x",di->length);
printf("\n data %x",di->data[0]);

srv.sin_family=AF_INET;

</code>

this is, presumably, the outgoing side. I was suggesting what to do on
the
*incoming* side. As other posters have commented we are left guessing a
bit...


--
Nick Keighley

Quantum Boggum Sort:
Q1. use a source of quantum noise (eg. radioactive decay) to
randomly permutate an array.
Q2. if the array is not ordered, destroy the universe (*)
Q3. if you reached this step your universe has sorted the array
in O(n) time.
(*) [100] this is left as an exercise



Dr Mr Nick
Here I am posting the recving code lines
kindly do correct me

typedef struct
{
UDINT connId;
UDINT seqNo;
}addrData_t;

typedef struct
{
UINT typeId;
UINT length;
addrData_t addrData;

}addrItem_t;

typedef struct
{
UINT typeId;
UINT length;
USINT data[1];
}dataItem_t;

typedef struct
{
UINT itemCount;
addrItem_t addrItem;
dataItem_t dataItem;
} udpPacket_t;








void* IODataRecv(void* sfd)
{
int nsfd=*((int *)sfd);
int len ,i;
char *buff=GetMemBuff(128);

struct in_addr adr;

struct sockaddr_in dst;
socklen_t adrLen;
memset(buff,0,128);
int count = 0;
sleep(2);
inet_aton("192.168.16.25",&adr);
dst.sin_addr=adr;
dst.sin_port=htons(CONNECTED_UDP_PORT);
dst.sin_family= AF_INET;
while(1)
{
printf("\nIO data function\n ");
/*len= recvfrom(nsfd,buff,1024,0,(struct sockaddr*)
&dst,sizeof(dst)); */
len= recv(nsfd,buff,1024,0);
printf("\n data function\n ");
if (len>0)
{
for (i=0;i<len;i++)
{
printf(" %x ",buff);
}
udpPacket_t *udppkt= (udpPacket_t *)buff;
addrItem_t ai=udppkt->addrItem;
dataItem_t di=udppkt->dataItem;
addrData_t ad=ai.addrData;

printf("Type Id %x \n",ai.typeId);
printf("length %x\n",ai.length);
printf("ConnId %x \n",ad.connId);
printf("Seq no %x \n",ad.seqNo);
printf("Data typeid %x\n",di.typeId);
printf("Data length %x\n",di.length);
printf("Item Count %x\n",udppkt->itemCount);

}
}


thanks and regards
PMM
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top