sendto() problem (linux) - help
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > sendto() problem (linux) - help




Pages (2): [1] 2 »   Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

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


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-23-04 10: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







[ Post a follow-up to this message ]



    Re: sendto() problem (linux) - help  
Nils O. examnotes


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-23-04 10: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




[ Post a follow-up to this message ]



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


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-23-04 10: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] sendto():[QUOTE] > Did you make sure everything is in network order ? > that is use htonl/htons.. > and it[QUOTE] > 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 >




[ Post a follow-up to this message ]



    Re: sendto() problem (linux) - help  
Casper H.S. Dik


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-23-04 10: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.




[ Post a follow-up to this message ]



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


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-23-04 10: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] sendto():[QUOTE] > Did you make sure everything is in network order ? > that is use htonl/htons.. > and it[QUOTE] > 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 >




[ Post a follow-up to this message ]



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


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-23-04 10: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 > >




[ Post a follow-up to this message ]



    Re: sendto() problem (linux) - help  
Nils O. examnotes


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-23-04 10: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...[/QUOT
E]
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






[ Post a follow-up to this message ]



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


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-23-04 10: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] that[QUOTE] 0.0.0.0...[QUOTE] > 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 >




[ Post a follow-up to this message ]



    Re: sendto() problem (linux) - help  
Joseph Dionne


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-23-04 10: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 > >




[ Post a follow-up to this message ]



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


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-23-04 10: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] sendto():[QUOTE] and it[QUOTE] >




[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 01:22 PM.      Post New Thread    Post A Reply      
Pages (2): [1] 2 »   Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register