sendto: Invalid Argument
Posted
by Sylvain
on Stack Overflow
See other posts from Stack Overflow
or by Sylvain
Published on 2010-04-23T08:07:58Z
Indexed on
2010/04/23
8:13 UTC
Read the original article
Hit count: 461
c++
|socket-programming
Hi,
I have a list<struct sockaddr_in> _peers
I'd like to use for sendto()
the list is filled this way
struct hostent *hp;
hp = gethostbyname(hostname);
sockaddr_in sin;
bzero(&sin, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_port = htons(port);
sin.sin_addr.s_addr = *(in_addr_t *)hp->h_addr;
_peers.push_front(sin);
and here's how I try to send:
for (list<struct sockaddr_in>::iterator it = _peers.begin(); it != _peers.end(); ++it) {
if (sendto(_s, "PING", 5, 0, (struct sockaddr *)&(*it), sizeof(struct sockaddr_in)) < 0)
perror("sendto");
}
outputs:
sendto: Invalid argument
If I create the struct sockaddr_in
right before sendto()
, everything works fine, so I guess I fail at using the list properly ... I also tested using &_peers.front()
directly and still get the same error ...
what am I doing wrong?
Thanks in advance,
© Stack Overflow or respective owner