Unix Programming - sendto() problem (linux) - help

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > January 2004 > sendto() problem (linux) - help





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author sendto() problem (linux) - help
B.r.K.o.N.j.A.

2004-01-23, 5:18 pm

I've been having trouble with sendto function (I open a socket, bind it to
eth0, recvfrom works fine but when I execute following line I get sendto():
invalid argument)

if(sendto(sokit, buf, sizeof(buf), 0, (struct sockaddr *)&drugaadr,
sizeof(drugaadr))==-1){
perror("sendto()")
exit(-1)
}

sokit is int variable with socket handler (value 3)
buf is declared char[60]
drugaadr is struct sockaddr_in

drugaadr.sin_family=AF_INET;
drugaadr.sin_port=0;
drugaadr.sin_addr.s_addr=inet_addr("192.168.0.1");
and the drugaadr.sin_zero is filled with 8 zeros.

Please help (I'm trying to send an ARP packet, but that's within buf, and it
shouldn't have anything to do with sendto failure), I've searched the
internet but came empty-handed.

Thanks,

Vedran


Nils O. =?iso-8859-1?Q?Sel=E5sdal?=

2004-01-23, 5:18 pm

In article <brbtht$61p$1@sunce.iskon.hr>, B.r.K.o.N.j.A. wrote:
quote:

> I've been having trouble with sendto function (I open a socket, bind it to
> eth0, recvfrom works fine but when I execute following line I get sendto():
> invalid argument)
>
> if(sendto(sokit, buf, sizeof(buf), 0, (struct sockaddr *)&drugaadr,
> sizeof(drugaadr))==-1){
> perror("sendto()")
> exit(-1)
> }
>
> sokit is int variable with socket handler (value 3)
> buf is declared char[60]
> drugaadr is struct sockaddr_in
>
> drugaadr.sin_family=AF_INET;
> drugaadr.sin_port=0;
> drugaadr.sin_addr.s_addr=inet_addr("192.168.0.1");
> and the drugaadr.sin_zero is filled with 8 zeros.


Did you make sure everything is in network order ?
that is use htonl/htons..
quote:

> Please help (I'm trying to send an ARP packet, but that's within buf, and it
> shouldn't have anything to do with sendto failure), I've searched the
> internet but came empty-handed.


If you want to send a raw ARP packet, you'll need to use a packet socket.
(man 7 packet)
--
Vennlig hilsen/Best Regards
Nils Olav Selåsdal <NOS at Utel.no>
System Engineer
UtelSystems a/s

B.r.K.o.N.j.A.

2004-01-23, 5:18 pm

I've changed to

drugaadr.sin_family=htons(AF_INET);
drugaadr.sin_port=0;

and both
drugaadr.sin_addr.s_addr=htonl(inet_addr("192.168.0.1"));
and
drugaadr.sin_addr.s_addr=inet_addr("192.168.0.1");

But nothing changed, Help!

Which parameter could be causing trouble? I've got some data in char
buf[60], can it affect the sendto?

Thanks,

Vedran

"Nils O. Selåsdal" <noselasd@frisurf.no> wrote in message
news:slrnbtj036.507.noselasd@utelsystems.dyndns.org...
quote:

> In article <brbtht$61p$1@sunce.iskon.hr>, B.r.K.o.N.j.A. wrote:
to[QUOTE][color=darkred]
sendto():[QUOTE][color=darkred]
> Did you make sure everything is in network order ?
> that is use htonl/htons..
>
and it[QUOTE][color=darkred]
> If you want to send a raw ARP packet, you'll need to use a packet socket.
> (man 7 packet)
> --
> Vennlig hilsen/Best Regards
> Nils Olav Selåsdal <NOS at Utel.no>
> System Engineer
> UtelSystems a/s
>




Casper H.S. Dik

2004-01-23, 5:18 pm

"B.r.K.o.N.j.A." <thebrkonja@inet.hr> writes:
quote:

>drugaadr.sin_port=0;



Not a legal port number.

Casper
--
Expressed in this posting are my opinions. They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.
B.r.K.o.N.j.A.

2004-01-23, 5:18 pm

I've changed drugaadr from sockaddr_in to sockaddr_ll, and filled the
elements of the structure, all of them except sll_addr which is 6 byte
address, and all I have is IP address (4 bytes), how can put it in sll_addr
(I think that this will make things work) - I'm not trying to comm with
internet but through local network.

Thanks,

Vedran

"Nils O. Selåsdal" <noselasd@frisurf.no> wrote in message
news:slrnbtj036.507.noselasd@utelsystems.dyndns.org...
quote:

> In article <brbtht$61p$1@sunce.iskon.hr>, B.r.K.o.N.j.A. wrote:
to[QUOTE][color=darkred]
sendto():[QUOTE][color=darkred]
> Did you make sure everything is in network order ?
> that is use htonl/htons..
>
and it[QUOTE][color=darkred]
> If you want to send a raw ARP packet, you'll need to use a packet socket.
> (man 7 packet)
> --
> Vennlig hilsen/Best Regards
> Nils Olav Selåsdal <NOS at Utel.no>
> System Engineer
> UtelSystems a/s
>




B.r.K.o.N.j.A.

2004-01-23, 5:18 pm

I've made it work (somewhat), I've used struct sockaddr_ll instead of
sockaddr_in, and filled all the fields except sll_addr (6 bytes ethernet
addres), now it sends data, and other mashine (with tcpdump running) gets
data but I should set the destination address for the packet (I think that
now, I'm just broadcasting) since tcpdump gives me source address 0.0.0.0...

Please help,

Best regards,

Vedran

"B.r.K.o.N.j.A." <thebrkonja@inet.hr> wrote in message
news:brbtht$61p$1@sunce.iskon.hr...
quote:

> I've been having trouble with sendto function (I open a socket, bind it to
> eth0, recvfrom works fine but when I execute following line I get


sendto():
quote:

> invalid argument)
>
> if(sendto(sokit, buf, sizeof(buf), 0, (struct sockaddr *)&drugaadr,
> sizeof(drugaadr))==-1){
> perror("sendto()")
> exit(-1)
> }
>
> sokit is int variable with socket handler (value 3)
> buf is declared char[60]
> drugaadr is struct sockaddr_in
>
> drugaadr.sin_family=AF_INET;
> drugaadr.sin_port=0;
> drugaadr.sin_addr.s_addr=inet_addr("192.168.0.1");
> and the drugaadr.sin_zero is filled with 8 zeros.
>
> Please help (I'm trying to send an ARP packet, but that's within buf, and


it
quote:

> shouldn't have anything to do with sendto failure), I've searched the
> internet but came empty-handed.
>
> Thanks,
>
> Vedran
>
>




Nils O. =?iso-8859-1?Q?Sel=E5sdal?=

2004-01-23, 5:18 pm

In article <brc7ih$eel$1@sunce.iskon.hr>, B.r.K.o.N.j.A. wrote:
quote:

> I've made it work (somewhat), I've used struct sockaddr_ll instead of
> sockaddr_in, and filled all the fields except sll_addr (6 bytes ethernet
> addres), now it sends data, and other mashine (with tcpdump running) gets
> data but I should set the destination address for the packet (I think that
> now, I'm just broadcasting) since tcpdump gives me source address 0.0.0.0...


Just a thougt, but if you are sending arp packets, you could take a look at
the sourcecode for arping , part of the iputils package.

--
Vennlig hilsen/Best Regards
Nils Olav Selåsdal <NOS at Utel.no>
System Engineer
UtelSystems a/s

B.r.K.o.N.j.A.

2004-01-23, 5:18 pm

I've solved it. (I think , now it sends arp packets, and tcpdump on the
other side sees those packages as arp packages, so I guess it's O.K. now.

Thanks for all the help

Vedran

"Nils O. Selåsdal" <noselasd@frisurf.no> wrote in message
news:slrnbtj9t1.5o8.noselasd@utelsystems.dyndns.org...
quote:

> In article <brc7ih$eel$1@sunce.iskon.hr>, B.r.K.o.N.j.A. wrote:
gets[QUOTE][color=darkred]
that[QUOTE][color=darkred]
0.0.0.0...[QUOTE][color=darkred]
> Just a thougt, but if you are sending arp packets, you could take a look


at
quote:

> the sourcecode for arping , part of the iputils package.
>
> --
> Vennlig hilsen/Best Regards
> Nils Olav Selåsdal <NOS at Utel.no>
> System Engineer
> UtelSystems a/s
>




Joseph Dionne

2004-01-23, 5:18 pm

Please provide more of the code use to setup sokit.

B.r.K.o.N.j.A. wrote:
quote:

> I've been having trouble with sendto function (I open a socket, bind it to
> eth0, recvfrom works fine but when I execute following line I get sendto():
> invalid argument)
>
> if(sendto(sokit, buf, sizeof(buf), 0, (struct sockaddr *)&drugaadr,
> sizeof(drugaadr))==-1){
> perror("sendto()")
> exit(-1)
> }
>
> sokit is int variable with socket handler (value 3)
> buf is declared char[60]
> drugaadr is struct sockaddr_in
>
> drugaadr.sin_family=AF_INET;
> drugaadr.sin_port=0;
> drugaadr.sin_addr.s_addr=inet_addr("192.168.0.1");
> and the drugaadr.sin_zero is filled with 8 zeros.
>
> Please help (I'm trying to send an ARP packet, but that's within buf, and it
> shouldn't have anything to do with sendto failure), I've searched the
> internet but came empty-handed.
>
> Thanks,
>
> Vedran
>
>



B.r.K.o.N.j.A.

2004-01-23, 5:18 pm

I've solved it, thanks.


"Joseph Dionne" <jdionne@hotmail.com> wrote in message
news:XRkCb.66328$%h4.52460@twister.tampabay.rr.com...
quote:

> Please provide more of the code use to setup sokit.
>
> B.r.K.o.N.j.A. wrote:
to[QUOTE][color=darkred]
sendto():[QUOTE][color=darkred]
and it[QUOTE][color=darkred]
>




David Schwartz

2004-01-23, 5:18 pm


"B.r.K.o.N.j.A." <thebrkonja@inet.hr> wrote in message
news:brbtht$61p$1@sunce.iskon.hr...
quote:

> I've been having trouble with sendto function (I open a socket, bind it to
> eth0, recvfrom works fine but when I execute following line I get


sendto():
quote:

> invalid argument)
>
> if(sendto(sokit, buf, sizeof(buf), 0, (struct sockaddr *)&drugaadr,
> sizeof(drugaadr))==-1){
> perror("sendto()")
> exit(-1)
> }
>
> sokit is int variable with socket handler (value 3)



What type of socket is this? UDP?
quote:

> drugaadr.sin_family=AF_INET;
> drugaadr.sin_port=0;
> drugaadr.sin_addr.s_addr=inet_addr("192.168.0.1");
> and the drugaadr.sin_zero is filled with 8 zeros.



I don't think zero is a legal port number to send to. What parameters
did you pass to 'socket' when you opened the socket?

DS


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com