From: Krzysztof Halasa <khc@pm.waw.pl>
To: "Miguel Ángel Álvarez" <gotzoncabanes@gmail.com>
Cc: "Francois Romieu" <romieu@fr.zoreil.com>, netdev@vger.kernel.org
Subject: Re: How to use ixp4xx_hss (or generic-hdlc?)
Date: Sat, 22 Nov 2008 00:28:16 +0100 [thread overview]
Message-ID: <m37i6wslpr.fsf@maximus.localdomain> (raw)
In-Reply-To: <b0438a630811210018j38518462ve975dfd3a7220b00@mail.gmail.com> ("Miguel Ángel Álvarez"'s message of "Fri\, 21 Nov 2008 09\:18\:43 +0100")
"Miguel Ángel Álvarez" <gotzoncabanes@gmail.com> writes:
> I have also taken a look to the code of sethdlc to see how the socket
> to the interface was set. He made "sock = socket(PF_INET, SOCK_DGRAM,
> IPPROTO_IP);" which I suppose does not care a lot because sethdlc only
> uses the socket to send ioctls, and not any data transfers.
This is a bit different matter, though you may need it to get ifr_index.
> However, in my case, I need to send data in a non-IP world using the
> interface. So... Is this the way I should open the socket? Would this
> encapsulate my data in hdlc before sending it to the interface?
>
> if I open the socket using sock = socket(PF_PACKET, SOCK_RAW,
> htons(ETH_P_ALL)); I can send data into the interface, but it is just
> sent as raw data (which is logic).
It should be bit-stuffed and encapsulated in HDLC frames (flags etc),
assuming a real HDLC device.
You may need to prepend some headers, though.
The basic idea is:
int sock;
struct ifreq ifr;
struct sockaddr_ll addr;
strcpy(ifr.ifr_name, "hdlc0");
if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP)) < 0)
error();
if (ioctl(sock, SIOCGIFINDEX, &ifr))
error();
close(sock);
if ((sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL))) < 0)
error();
memset(&addr, 0, sizeof(addr));
addr.sll_family = AF_PACKET;
addr.sll_protocol = htons(ETH_P_ALL);
addr.sll_ifindex = ifr.ifr_ifindex;
then:
sendto(sock, packet_data, packet_size, 0, &addr, sizeof(addr)) < 0)
for RX:
if (bind(sock, &addr, sizeof(addr)) < 0)
error();
then:
recvfrom(sock, buffer, max_packet_size, 0, &addr, &addr_len)
--
Krzysztof Halasa
next prev parent reply other threads:[~2008-11-21 23:28 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-20 17:42 How to use ixp4xx_hss (or generic-hdlc?) Miguel Ángel Álvarez
2008-11-20 22:24 ` Francois Romieu
2008-11-21 8:18 ` Miguel Ángel Álvarez
2008-11-21 23:28 ` Krzysztof Halasa [this message]
2008-11-24 9:56 ` Miguel Ángel Álvarez
2008-11-24 16:33 ` Krzysztof Halasa
2008-11-25 7:24 ` Miguel Ángel Álvarez
2008-11-21 23:09 ` Krzysztof Halasa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m37i6wslpr.fsf@maximus.localdomain \
--to=khc@pm.waw.pl \
--cc=gotzoncabanes@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=romieu@fr.zoreil.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox