I write a code for send message
but the sendto retourn the error EINVAL and I don't understand why...
tanks
Nicol@
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/net.h>
#include <linux/socket.h>
#include <linux/if_ether.h>
#include <linux/if_packet.h>
/* RTAI */
#include <rtai.h>
#include <rtai_sched.h>
#include <rtai_shm.h>
#include <rtai_sem.h>
#include <rtai_nam2num.h>
#include <rtai_fifos.h>
/* RTnet */
#include <rtnet.h>
#include <rtdm.h>
#include "packet_if.h"
MODULE_LICENSE("GPL");
static RT_TASK task_start;
RTIME start, period;
int OpenTxSocket(const char *name, unsigned short protocol,
int *ifindex, struct sockaddr *hwaddr)
{
int st;
int s;
/* Open a PF_PACKET/SOCK_DGRAM socket */
if((s = socket_rt(PF_PACKET, SOCK_DGRAM, htons(0x0000))) < 0)
{
printk("Error: socket_rt() = %d\n", s);
return -1;
}
*ifindex = 1;
/* Get interface index and hw address from name */
hwaddr->sa_family = AF_PACKET;
rt_eth_aton(hwaddr->sa_data, mac_eth0);
/* If an error occurred (st < 0), close the socket and return the error
* code, else return the socket id.
*/
if(st < 0) close_rt(s);
else
{
printk("Tx socket %d bound to ", s);
DumpIfInfo(name, *ifindex, hwaddr);
st = s;
}
return st;
}
void
PrepareToAddr(const struct sockaddr *hwaddr, unsigned short protocol,
int ifindex, struct sockaddr_ll *addr)
{
int i;
addr->sll_family = AF_PACKET;
addr->sll_protocol = htons(0x0000);
addr->sll_ifindex = ifindex;
addr->sll_hatype = 0; /* SBZ per packet(7) */
addr->sll_pkttype = 0; /* SBZ per packet(7) */
addr->sll_halen = 6;
for(i=0; i<6; i++)
addr->sll_addr[i] = hwaddr->sa_data[i];
}
int
My_Sendto(int s, const unsigned char buf[2048], size_t len,
const struct sockaddr_ll *to_addr)
{
int st;
st = sendto_rt(s, &buf, len, MSG_DONTROUTE,
(struct sockaddr *)to_addr, sizeof(struct sockaddr_ll));
if(st < 0) printk("Error: AttemptTx/sendto: %d\n", st);
return st;
}
int tx_s;
struct sockaddr_ll to_addr;
void
start(int thread)
{
int i;
for(i = 0; i < 20; i++)
{
tx_b[2048];
My_Sendto(tx_s, tx_b, 1024, to_addr);
}
}
int
init_module(void)
{
printk("\nStart Packet_if\n\n");
/* Open sockets and gather interface info (index and physical
address) */
tx_s = OpenTxSocket(ETH0_NAME, MY_PROTOCOL, &tx_index, &tx_addr);
if (tx_s < 0)
{
printk("Error: OpenTxSocket() = %d\n", tx_s);
return -1;
}
rt_set_periodic_mode();
period = start_rt_timer(nano2count(TICK_TIME));
start = rt_get_time() + 100*period;
rt_task_init(&task_start, start, 0, 5000, 20, 0, 0);
return rt_task_make_periodic(&task_start, start, nano2count(1230000));
}
-------------------------------------------------------
This SF.Net email is sponsored by Yahoo.
Introducing Yahoo! Search Developer Network - Create apps using Yahoo!
Search APIs Find out how you can build Yahoo! directly into your own
Applications - visit http://developer.yahoo.net/?fr=offad-ysdn-ostg-q22005
_______________________________________________
RTnet-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rtnet-users