Hi,
trying to send data via rtnet without ip on raw socket I have a problem.
Using the native API it doesn't work at all, using the posix API it works
exactly once.
Since I tried everything I tried to rewrite the raw-ethernet example in my
project (my source code is attached). The first call of that program sends
the buffer as it should (checking via wireshark). All further calls do not
send anything. All functions return without any error, send function
returns with 36, the amount of bytes to be sent.
I have no more idea where my mistake is.
the raw-ethernet example works fine.
sorry for chatoical code, it changed a lot of time for testing purpose.
Greets, Nadym
#include "main.h"
char Eth_SendBuffer[MAXNETWORKFRAMESIZE];
int fd; //Filedescriptor for Network Device
int main (int argc, char* argv[])
{
SINT16 ReturnValue;
char test[20];
//Initialisation
ReturnValue = 0;
signal(SIGTERM, catch_signal);
signal(SIGINT, catch_signal);
signal(SIGHUP, catch_signal);
if ( -1 == mlockall (MCL_CURRENT | MCL_FUTURE) )
{
perror( "mlockall: " );
ReturnValue = -1;
}
struct ifreq ifr;
struct sockaddr_ll addr;
//creating socket ethernet device
fd = socket( PF_PACKET, SOCK_RAW, htons(ETH_TYPE_RTDATA));
if (0 > fd)
{
fprintf(stderr, "failed to open "NETWORK_DEVICE", error
code: %d\n", fd);
return -1;
}
strncpy(ifr.ifr_name, NETWORK_DEVICE, IFNAMSIZ);
if (ioctl(fd, SIOCGIFINDEX, &ifr) < 0)
{
perror("cannot get interface index");
close(fd);
return -1;
}
addr.sll_family = AF_PACKET;
addr.sll_protocol = htons(ETH_TYPE_RTDATA);
addr.sll_ifindex = ifr.ifr_ifindex;
if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
perror("cannot bind to local ip/port");
close(fd);
return -1;
}
memset( test, 0xee, 20 );
struct ether_header *eth = (struct ether_header
*)Eth_SendBuffer;
int i, j;
unsigned short Eth_PayloadSize;
eth->ether_dhost[0] = 0x06;
eth->ether_dhost[1] = 0x05;
eth->ether_dhost[2] = 0x04;
eth->ether_dhost[3] = 0x03;
eth->ether_dhost[4] = 0x02;
eth->ether_dhost[5] = 0x02;
eth->ether_shost[0] = 0x00;
eth->ether_shost[1] = 0x0e;
eth->ether_shost[2] = 0x0c;
eth->ether_shost[3] = 0xd7;
eth->ether_shost[4] = 0xfe;
eth->ether_shost[5] = 0xbf;
eth->ether_type = htons(ETH_PROTOCOL);
Eth_PayloadSize = htons(20);
memcpy(Eth_SendBuffer + 14, &Eth_PayloadSize, 2);
memcpy(Eth_SendBuffer + 16, test, 20);
for (j = 0; j < 20+16 ; j++ )
{
printf("Buffer:
0x%2x\n",(UINT8)Eth_SendBuffer[j]);
}
i = send( fd, Eth_SendBuffer, 20 + 16, 0);
printf("sent bytes: %d \n", i);
while ((close(fd) < 0) && (errno == EAGAIN)) {
printf("socket busy - waiting...\n");
sleep(1);
}
return ReturnValue;
}
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
RTnet-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rtnet-users