PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.c > sendto(msg) points to uninitialised byte(s)
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
sendto(msg) points to uninitialised byte(s)

Réponse
 
LinkBack Outils de la discussion
Vieux 18/10/2007, 11h06   #1 (permalink)
BlueJ
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut sendto(msg) points to uninitialised byte(s)

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 to correct the error?

  Réponse avec citation
Vieux 18/10/2007, 14h38   #2 (permalink)
CBFalconer
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sendto(msg) points to uninitialised byte(s)

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
>
> 1. key_list = emalloc(BUFSIZE - sizeof(Key) - sizeof(byte) -
> sizeof(int));
> bzero(key_list, sizeof(*key_list));


So far the entities 'key_list', 'emalloc', 'Key', 'byte', 'bzero'
are all undefined. Not to mention 'socket' and 'sendto()'.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>


--
Posted via a free Usenet account from http://www.teranews.com

  Réponse avec citation
Vieux 18/10/2007, 23h11   #3 (permalink)
Peter Pichler
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sendto(msg) points to uninitialised byte(s)

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 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 , 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
  Réponse avec citation
Vieux 19/10/2007, 02h55   #4 (permalink)
Jack Klein
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sendto(msg) points to uninitialised byte(s)

On Thu, 18 Oct 2007 03:06:53 -0700, BlueJ <pengbin@gmail.com> wrote 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
  Réponse avec citation
Vieux 19/10/2007, 06h47   #5 (permalink)
jaysome
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sendto(msg) points to uninitialised byte(s)

On Thu, 18 Oct 2007 03:06:53 -0700, BlueJ <pengbin@gmail.com> 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
>
> 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 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 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 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
  Réponse avec citation
Vieux 19/10/2007, 15h58   #6 (permalink)
Ben Bacarisse
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sendto(msg) points to uninitialised byte(s)

jaysome <jaysome@hotmail.com> writes:

> On Thu, 18 Oct 2007 03:06:53 -0700, BlueJ <pengbin@gmail.com> 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

<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 (and,
equally usually, might the OP find the problem on their own).

--
Ben.
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 11h26.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,27331 seconds with 14 queries