LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-28-2003, 05:25 PM   #1
kiba
LQ Newbie
 
Registered: Oct 2003
Posts: 4

Rep: Reputation: 0
how to sendto() on packet sockets in linux?


anyone has any idea on how to fill the sendto() when sending data trough a packet socket in linux? i can recvfrom() though.

---------------(soc)
char pkt[]="...blah..."; // my packet w/ 802.3 header and w/ LLC header
struct sockaddr_ll remote_host;

sd=socket(AF_PACKET,SOCK_RAW,htons(ETH_P_ALL));

bzero(&remote_host, sizeof(struct sockaddr_ll));
remote_host.sll_family = AF_PACKET;
remote_host.sll_ifindex = 2; // eth0
remote_host.sll_halen = ETH_ALEN; // 6 bytes
strcpy(remote_host.sll_addr,"\x00\x50\x56\xc0\x00\x01"); // destination host's mac
// "man packet" says filling only this 4 fields is enough for sending

sendto(sd, pkt, sizeof(pkt), 0, (struct sockaddr*)&remote_host, sizeof(struct sockaddr));
// returns -1 errno = Invalid argument
-------------(eoc)

pkt[] is a stp(spanning tree protocol) packet captured w/ ethereal(copy'ed/paste'd) so
it must be valid. but anyway, does sendto() refuse to send if pkt is ivalid?

i also tryed SOCK_DGRAM and still no luck

thank you in advance.
 
Old 10-29-2003, 02:05 AM   #2
repe
Member
 
Registered: Aug 2003
Location: Finland
Distribution: Slackware 9.0 & 9.1. FreeBSD 4.8 & 5.1
Posts: 30

Rep: Reputation: 15
Take a look at Beej's Guide to Network Programming. http://www.ecst.csuchico.edu/~beej/guide/net/
 
Old 10-29-2003, 04:45 AM   #3
kiba
LQ Newbie
 
Registered: Oct 2003
Posts: 4

Original Poster
Rep: Reputation: 0
i could not find any information on this on the net. all there is are some basic tutorials (including beej's guide), not the real stuff anyway. this kind of information(sending on packet sockets) is not present even in Richard Stevens' "UNIX Network Programming Vol 1, 2nd Ed"
 
Old 10-29-2003, 11:46 AM   #4
infamous41md
Member
 
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
this is the kinda stuff u learn from late nights hanging out in /usr/include/net*/*
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Sockets and Packet Stream Question Chryzmo Programming 2 11-12-2005 08:54 PM
sendto error (socket) payal_shah Linux - Networking 0 02-23-2005 12:18 PM
int to string+sendto pantera Programming 3 08-19-2004 07:19 PM
nmap raw packet sendto error in Mandrake 9.2 conn-fused Linux - Networking 0 06-30-2004 02:11 PM
help: sockets & sendto Lugh Programming 4 09-13-2003 04:13 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration