When I call sendto() function under QNX6.20 it occurred a abnormal
situation:
it print some other character and the contents I want to send
out,actually I don’t print anything in the context codes.
my codes is very simple like this:
…
if( sock_wave=socket( AF_INET, SOCK_DGRAM, 0) < 0 )
{
perror( “Unable create socket” );
return 1;
}
r = sendto(sock_wave, wave_display,
sizeof(wave_display),
0,
(struct sockaddr *)&dest_wave,
sizeof(struct sockaddr) );
if( r <= 0 )
{ //never print this message
perror(“sendto I-value display PC occured.\n”);
}
}
…
and the results are:
A"Ã0/00TE
A"Ã0/00TE
A"Ã0/00TE
A"Ã0/00TE
…
I use “netstat -a” utility got the follow info:
udp:
9704 datagrams received //? I just send,not open port for receive
0 with incomplete header
0 with bad data length field
0 with bad checksum
1 dropped due to no socket
9700 broadcast/multicast datagrams dropped due to no socket //??
0 dropped due to full socket buffers
3 delivered
9703 PCB hash misses
14 datagrams output
Why got this result? may I wrong configure some files?
When I call sendto() function under QNX6.20 it occurred a abnormal
situation:
it print some other character and the contents I want to send
out,actually I don’t print anything in the context codes.
my codes is very simple like this:
…
if( sock_wave=socket( AF_INET, SOCK_DGRAM, 0) < 0 )
{
perror( “Unable create socket” );
return 1;
}
r = sendto(sock_wave, wave_display,
sizeof(wave_display),
0,
(struct sockaddr *)&dest_wave,
sizeof(struct sockaddr) );
if( r <= 0 )
{ //never print this message
perror(“sendto I-value display PC occured.\n”);
}
}
…
and the results are:
A"Ã0/00TE
A"Ã0/00TE
A"Ã0/00TE
A"Ã0/00TE
…
I use “netstat -a” utility got the follow info:
snip
udp:
9704 datagrams received //? I just send,not open port for receive
0 with incomplete header
0 with bad data length field
0 with bad checksum
1 dropped due to no socket
9700 broadcast/multicast datagrams dropped due to no socket //??
0 dropped due to full socket buffers
3 delivered
9703 PCB hash misses
14 datagrams output
/snip
Why got this result? may I wrong configure some files?
When I call sendto() function under QNX6.20 it occurred a abnormal
situation:
it print some other character and the contents I want to send
out,actually I don’t print anything in the context codes.
my codes is very simple like this:
…
if( sock_wave=socket( AF_INET, SOCK_DGRAM, 0) < 0 )
{
perror( “Unable create socket” );
return 1;
}
r = sendto(sock_wave, wave_display,
sizeof(wave_display),
0,
(struct sockaddr *)&dest_wave,
sizeof(struct sockaddr) );
if( r <= 0 )
{ //never print this message
perror(“sendto I-value display PC occured.\n”);
}
}
…
and the results are:
A"Ã0/00TE
A"Ã0/00TE
A"Ã0/00TE
A"Ã0/00TE
…
I use “netstat -a” utility got the follow info:
snip
udp:
9704 datagrams received //? I just send,not open port for
receive
0 with incomplete header
0 with bad data length field
0 with bad checksum
1 dropped due to no socket
9700 broadcast/multicast datagrams dropped due to no socket
//??
0 dropped due to full socket buffers
3 delivered
9703 PCB hash misses
14 datagrams output
/snip
Why got this result? may I wrong configure some files?
When I call sendto() function under QNX6.20 it occurred a abnormal
situation:
it print some other character and the contents I want to send
out,actually I don’t print anything in the context codes.
my codes is very simple like this:
…
if( sock_wave=socket( AF_INET, SOCK_DGRAM, 0) < 0 )
{
perror( “Unable create socket” );
return 1;
}
If for some reason sock_wave gets trashed to 1 or 2 it would endup on
stdout.
From your description I understand program display output on console while
it should not, right?
r = sendto(sock_wave, wave_display,
sizeof(wave_display),
0,
(struct sockaddr *)&dest_wave,
sizeof(struct sockaddr) );
if( r <= 0 )
{ //never print this message
perror(“sendto I-value display PC occured.\n”);
}
}
…
and the results are:
A"Ã0/00TE
A"Ã0/00TE
A"Ã0/00TE
A"Ã0/00TE
…
I use “netstat -a” utility got the follow info:
snip
udp:
9704 datagrams received //? I just send,not open port for receive
0 with incomplete header
0 with bad data length field
0 with bad checksum
1 dropped due to no socket
9700 broadcast/multicast datagrams dropped due to no socket //??
0 dropped due to full socket buffers
3 delivered
9703 PCB hash misses
14 datagrams output
/snip
Why got this result? may I wrong configure some files?
When I call sendto() function under QNX6.20 it occurred a abnormal
situation:
it print some other character and the contents I want to send
out,actually I don’t print anything in the context codes.
my codes is very simple like this:
…
if( sock_wave=socket( AF_INET, SOCK_DGRAM, 0) < 0 )
sock_wave = ( socket() < 0);
socket() returned > 0; so socket() < 0 was false → 0, so you
assigned sock_wave = 0;
Then, sendto(0, … ) became the equivalent of
write(0, …)
which is stdout.
-David
HC > Yes, David as you say the sock_wave==0 sometimes.
HC > I think the zero value of sock_wave is very surprising, why it can get
HC > zero??
HC > Thank you, David.
It should not be surprising. You just need an extra pair of
parenthesees (sp?). What was happening ws nothing like what you
intended to have happen. You wanted a file descriptor for the socket
and what you got was the truthfulness of socket() open failed or
not.
sock_wave = ( socket() < 0);
socket() returned > 0; so socket() < 0 was false → 0, so you
assigned sock_wave = 0;
Then, sendto(0, … ) became the equivalent of
write(0, …)
which is stdout.
-David
BC > HC > Yes, David as you say the sock_wave==0 sometimes.
BC > HC > I think the zero value of sock_wave is very surprising, why it can get
BC > HC > zero??
BC > HC > Thank you, David.
BC > It should not be surprising. You just need an extra pair of
BC > parenthesees (sp?). What was happening ws nothing like what you
BC > intended to have happen. You wanted a file descriptor for the socket
BC > and what you got was the truthfulness of socket() open failed or
BC > not.
Let me take this one step further and make a bold statement.
NEVER DO ASSIGNMENT INSIDE AN IF STATEMENT !
i.e. Don’t do:
if( ( this = that() ) != OK )
Instead do:
this = that();
if( this != OK )
It is easier to read but the really big advantage is that you can set
a break point in the debugger after the assignment and before the test.
sock_wave = ( socket() < 0);
socket() returned > 0; so socket() < 0 was false → 0, so you
assigned sock_wave = 0;
Then, sendto(0, … ) became the equivalent of
write(0, …)
which is stdout.
-David
Yes, David as you say the sock_wave==0 sometimes.
I think the zero value of sock_wave is very surprising, why it can get
zero??
Did you notice that when I repeated your line of code, I changed it
by adding an extra set of brackets?
You made a C order of operations mistake – the test was done before
the assignment. You wanted the assignment done first, you need more
brackets in your if statement to achieve this.
This behaviour is entirely unsurprising, and is also a common form
of error.