My program is to send data using socket.. but I got the error message:
"sendto(msg) points to uninitialised byte(s) " This is my source code
1. key_list = emalloc(BUFSIZE - sizeof(Key) - sizeof(byte) -
sizeof(int));
bzero(key_list, sizeof(*key_list));
bp = key_list;
memmove(bp, key, ID_LEN);
bp += ID_LEN;
memmove(bp, &ip_num, sizeof(int));
bp += sizeof(int);
pack_addr = htonl(addr);
memmove(bp, &pack_addr, sizeof(ulong));
bp +=sizeof(ulong);
Ivn_send_key(srv, ttl, succ->addr, succ->port, bp, (bp -
key_list), addr, port);
2.
void Ivn_send_key(Vnode *srv, byte ttl, ulong to_addr, ushort
to_port, uchar *key_list, int list_len, ulong addr, ushort port)
{
byte buf[BUFSIZE];
Ivn_send_raw(srv, to_addr, to_port, Ivn_pack_key(buf, ttl, key_list,
list_len, addr, port), buf);
}
3.
int Ivn_pack_key(uchar *buf, byte ttl, uchar *key_list, int list_len,
ulong addr, ushort port)
{
//return Ivn_pack(buf, "ccxls", CHORD_KEY, ttl, key_list , port);
uchar *bp;
ushort sport;
bp = buf;
*bp++ = CHORD_KEY;
*bp++ = ttl;
sport = htons(port); //port number
memmove(bp, (char *)&sport, sizeof(ushort));
bp += sizeof(ushort);
memmove(bp, key_list, list_len);
bp += list_len;
free(key_list);
return bp -buf;
}
4.
void Ivn_send_raw(Vnode *srv, in_addr_t addr, in_port_t port, int n,
uchar *buf)
{
struct sockaddr_in dest;
memset(&dest, 0, sizeof(dest));
dest.sin_family = AF_INET;
dest.sin_port = htons(port);
dest.sin_addr.s_addr = htonl(addr);
//fprintf(stderr, " dst addr is %s\n", inet_ntoa(dest.sin_addr));
if (sendto(srv->out_sock, buf, n, 0, (struct sockaddr *) &dest,
sizeof(dest)) < 0)
warnm("sendto failed:"); /* ignore errors for now */
}
please help to correct the error? 4 2588
BlueJ wrote:
My program is to send data using socket.. but I got the error message:
"sendto(msg) points to uninitialised byte(s) " This is my source code
BlueJ,
I wanted to help you, but could not find a single instance of msg in
your code snippet, let alone sendto(msg).
1. key_list = emalloc(BUFSIZE - sizeof(Key) - sizeof(byte) -
sizeof(int));
bzero(key_list, sizeof(*key_list));
<snip>
What's emalloc and bzero? What's key_list, Key, byte? Your code snippet
is incomplete at best. If you want help, copy and paste a reduced source
that exhibits your problem but is still compilable, or at least contains
enough information for a human reader to understand.
Peter
On Thu, 18 Oct 2007 03:06:53 -0700, BlueJ <pe*****@gmail.comwrote in
comp.lang.c:
My program is to send data using socket.. but I got the error message:
"sendto(msg) points to uninitialised byte(s) " This is my source code
1. key_list = emalloc(BUFSIZE - sizeof(Key) - sizeof(byte) -
There is no emalloc() function in C.
sizeof(int));
bzero(key_list, sizeof(*key_list));
There is no bzero() function in C, and IIRC it's been deprecated in
*nix for a long time.
In any case, your question seems to be about non-standard, platform
specific network APIs, and they are off-topic here. I suggest you
post to a group for your platform.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
On Thu, 18 Oct 2007 03:06:53 -0700, BlueJ <pe*****@gmail.comwrote:
>My program is to send data using socket.. but I got the error message: "sendto(msg) points to uninitialised byte(s) " This is my source code
1. key_list = emalloc(BUFSIZE - sizeof(Key) - sizeof(byte) - sizeof(int)); bzero(key_list, sizeof(*key_list));
bp = key_list;
memmove(bp, key, ID_LEN); bp += ID_LEN;
memmove(bp, &ip_num, sizeof(int)); bp += sizeof(int);
pack_addr = htonl(addr); memmove(bp, &pack_addr, sizeof(ulong)); bp +=sizeof(ulong);
Ivn_send_key(srv, ttl, succ->addr, succ->port, bp, (bp - key_list), addr, port);
2. void Ivn_send_key(Vnode *srv, byte ttl, ulong to_addr, ushort to_port, uchar *key_list, int list_len, ulong addr, ushort port) {
byte buf[BUFSIZE];
Ivn_send_raw(srv, to_addr, to_port, Ivn_pack_key(buf, ttl, key_list, list_len, addr, port), buf); }
3. int Ivn_pack_key(uchar *buf, byte ttl, uchar *key_list, int list_len, ulong addr, ushort port) { //return Ivn_pack(buf, "ccxls", CHORD_KEY, ttl, key_list , port); uchar *bp; ushort sport;
bp = buf;
*bp++ = CHORD_KEY;
*bp++ = ttl;
sport = htons(port); //port number memmove(bp, (char *)&sport, sizeof(ushort)); bp += sizeof(ushort);
memmove(bp, key_list, list_len); bp += list_len; free(key_list);
return bp -buf; }
4. void Ivn_send_raw(Vnode *srv, in_addr_t addr, in_port_t port, int n, uchar *buf) {
struct sockaddr_in dest;
memset(&dest, 0, sizeof(dest));
dest.sin_family = AF_INET;
dest.sin_port = htons(port);
dest.sin_addr.s_addr = htonl(addr);
//fprintf(stderr, " dst addr is %s\n", inet_ntoa(dest.sin_addr));
if (sendto(srv->out_sock, buf, n, 0, (struct sockaddr *) &dest, sizeof(dest)) < 0)
warnm("sendto failed:"); /* ignore errors for now */ }
please help to correct the error?
Hi BlueJ,
Others have replied to you with what I feel and most likely you feel
are of little to no help to you at all. Within the context of what
they feel this newsgroup is about (discussing Standard C-related
issues), they are right (e.g., there are no Standard C functions such
as emalloc or bzero, and therefore the short-circuit rules apply and
you post is off-topic).
However, in a broader sense, which is programming in C (and the trials
and tribulations you will inevitable encounter, regardless of whether
you are programming in Standard C or not), those same people who
replied to your post are cheating you, and every reasonable person
like you who have committed such a serious error in C, of a more
reasonable response.
I'd bet each and every one of those posters who replied to your post
are aware of the non-standard function sendto() and its prototype, yet
they failed to use their knowledge of this to be of any real help to
you, even though the type of error you committed could as just as
easily be committed in Standard C code.
Based on my knowledge of the non-standard function sendto(), it's
prototype is (for one of my compilers):
int sendto(
SOCKET s,
const char FAR *buf,
int len,
int flags,
const struct sockaddr FAR *to,
int tolen
);
What is not important is what SOCKET or FAR are defined as. What is
important is the definition of what the buf parameter is. Whether you
are using Linux or Windows or MAC OS X or any other OS, if your
compiler provides the sendto() function, its definition of the buf
parameter will invariably be something like this:
buf
[in] Buffer containing the data to be transmitted.
Given this definition (which effectively translates into buf being
something whose contents are transmitted and therefore needs to be
initialized/set to something BY YOU), it's obvious that what you pass
as the buf parameter to sendto() as a result of the uninitialized
local variable buf in Ivn_send_key() is your problem, and therefore
deserves the compiler warning you received.
Best regards
--
jaysome
jaysome <ja*****@hotmail.comwrites:
On Thu, 18 Oct 2007 03:06:53 -0700, BlueJ <pe*****@gmail.comwrote:
>>My program is to send data using socket.. but I got the error message: "sendto(msg) points to uninitialised byte(s) " This is my source code
<snip>
>>void Ivn_send_key(Vnode *srv, byte ttl, ulong to_addr, ushort to_port, uchar *key_list, int list_len, ulong addr, ushort port) { byte buf[BUFSIZE];
Ivn_send_raw(srv, to_addr, to_port, Ivn_pack_key(buf, ttl, key_list, list_len, addr, port), buf); }
<snip>
>>int Ivn_pack_key(uchar *buf, byte ttl, uchar *key_list, int list_len, ulong addr, ushort port) {
<seems to put stuff in buf>
>>}
<snip>
>>void Ivn_send_raw(Vnode *srv, in_addr_t addr, in_port_t port, int n, uchar *buf) {
<calls sendto>
>>}
<snip>
it's obvious that what you pass
as the buf parameter to sendto() as a result of the uninitialized
local variable buf in Ivn_send_key() is your problem, and therefore
deserves the compiler warning you received.
Not obvious to me. I did not reply because I could not find the
error, and not because a non-standard function was used.. The buffer
seems to be filled by the call to Ivn_pack_key in the argument list of
the call to Ivn_send_raw.
Also, it seem unlikely to be a compiler warning, since the call to
sendto is a long way from the definition of the buffer (and if it is a
compiler warning it look bogus to me).
Unless I am missing something, we need more information. As usual, the
small compilable program that exhibits the problem would help (and,
equally usually, might help the OP find the problem on their own).
--
Ben. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: prabhu.pravin |
last post by:
I want to Transmit Data using Using Socket Programming in C. The only
Problem is that the data contains a lot of NULL characters in between
(it is an JPEG image data).so if I populate a Char array...
|
by: Just |
last post by:
Hi everybody
I was wondering if it is possible to use SendTo to send a whole IP package
including header to another IP than specified in the package. Say I have a
complete package and in it...
|
by: Chang |
last post by:
why Socket.ReceiveFrom(byte, ref EndPoint) and SendTo(byte, ref
EndPoint) uses ref ? I know what ref means but why it has to use ref is the
question.
Thanks a lot,
Chang
|
by: George T. |
last post by:
I need to access the serial port via python on a windows machine.
Reading on the web, there are three solutions: pyserial, siomodule and
USPP. pyserial seems to be the best option since the other...
|
by: rodmc |
last post by:
I recently wrote a program in IDLE and it runs perfectly. However when
the same application is executed within SPE I receive errors saying
that certain socket items are not callable, in particular...
| |
by: ataanis |
last post by:
I'm currently using the function:
sendto(sockfd, message, strlen(message), 0,&client_addr, addr_size)
to sending a message back to a client, and I was wondering if there was
a way of sending a...
|
by: Rene Sørensen |
last post by:
I'm using .NET 2.0 VS 2005
I'm creating a function that dos something similar to the.
SmoApplication.EnumAvailableSqlServers() function. But for som resone
I get an error or do i?. The problem...
|
by: Pedro Pinto |
last post by:
Hello there.
I've created a socket program so exchange some messages with a server.
The problem is the following:
it compiles well but when running it gives a segmentation error here:...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |