Hi,

I'm trying to send raw ethernet packages on Xenomai, I'm also working with the trunk version of RTnet. I looked at the example "raw-ethernet.c" and I'm wondering why the functions like socket_rt, send_rt ,.. aren't used. Is it still real-time? I tried to use the real-time functions like socket_rt,... but then I can't send or receive raw ethernet packages anymore: the function send_rt returns -1. I attached the program code. Running the program (I use rtlo as interface) results in the following output:

   Socket created: socket id: 0
   Got interface: index: 0
   Sending frames...
   Cannot send: Success
   Length: -1
   shutting down

My second problem is the reason why I only can use the loopback: I use a Realtek rtl8139 network card. Loading the modules works fine with insmod. With dmesg I see rteth0 has been initialized but when I want to activate it with "rtifconfig rteth0 up 192.168.1.100" my system freezes without any message and the only solution is a hard reboot. Does anyone also has this problem, or has any solution?

Tom

/***
 *
 *  examples/xenomai/posix/raw-ethernet.c
 *
 *  SOCK_RAW sender - sends out Ethernet frames via a SOCK_RAW packet socket
 *
 *  Copyright (C) 2006 Jan Kiszka <[EMAIL PROTECTED]>
 *
 *  RTnet - real-time networking example
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

#include <errno.h>
#include <signal.h>
#include <pthread.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netpacket/packet.h>
#include <net/ethernet.h>
#include <net/if.h>
#include <arpa/inet.h>

#include <rtnet.h>

char buffer[1514];
int sock;


void catch_signal(int sig)
{
    close_rt(sock);
}


int main(int argc, char *argv[])
{
    ssize_t len;
    struct sockaddr_ll addr;
    struct ifreq ifr;
    struct timespec delay = { 1, 0 };
    struct ether_header *eth = (struct ether_header *)buffer;


    signal(SIGTERM, catch_signal);
    signal(SIGINT, catch_signal);
    signal(SIGHUP, catch_signal);

    if (argc < 2) {
        printf("usage: %s <interface>\n", argv[0]);
        return 0;
    }

    if ((sock = socket_rt(PF_PACKET, SOCK_RAW, htons(0x1234))) < 0) {
        perror("socket cannot be created");
        return 1;
    }
        printf("Socket created: socket id: %d\n", sock);
    
    int index_ioctl = 0;
    strncpy(ifr.ifr_name, argv[1], IFNAMSIZ);
    if ((index_ioctl = ioctl_rt(sock, SIOCGIFINDEX, &ifr)) < 0) {
        perror("cannot get interface index");
        close_rt(sock);
        return 1;
    }
        printf("Got interface: index: %d\n", index_ioctl);      

    addr.sll_family   = AF_PACKET;
    addr.sll_protocol = htons(0x1234);
    addr.sll_ifindex  = ifr.ifr_ifindex;

    if (bind_rt(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
        perror("cannot bind to local ip/port");
        close_rt(sock);
        return 1;
    }

    memset(eth->ether_dhost, 0xFF, ETH_HLEN);
    eth->ether_type = htons(0x1234);
    
        printf("Sending data...\n");    
        int tel = 0;
    while (1) {
        len = send_rt(sock, buffer, sizeof(buffer), 0);
        if (len < 0) {
                perror("Cannot send");
                        printf("Length: %d\n", len);
                        break;
        }
            
                tel++;
        printf("Sent frame %d of %d bytes\n", tel, len);

        nanosleep(&delay, NULL);
    }

    /* This call also leaves primary mode, required for socket cleanup. */
    printf("shutting down\n");

    while ((close_rt(sock) < 0) && (errno == EAGAIN)) {
        printf("socket busy - waiting...\n");
        sleep(1);
    }

    return 0;
}
/***
 *
 *  examples/xenomai/posix/raw-ethernet.c
 *
 *  SOCK_RAW sender - sends out Ethernet frames via a SOCK_RAW packet socket
 *
 *  Copyright (C) 2006 Jan Kiszka <[EMAIL PROTECTED]>
 *
 *  RTnet - real-time networking example
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

#include <errno.h>
#include <signal.h>
#include <pthread.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netpacket/packet.h>
#include <net/ethernet.h>
#include <net/if.h>
#include <arpa/inet.h>

#include <rtnet.h>

char buffer[1514];
int sock;


void catch_signal(int sig)
{
    close_rt(sock);
}


int main(int argc, char *argv[])
{
    ssize_t len;
    struct sockaddr_ll addr;
    struct ifreq ifr;
    struct timespec delay = { 1, 0 };
    struct ether_header *eth = (struct ether_header *)buffer;


    signal(SIGTERM, catch_signal);
    signal(SIGINT, catch_signal);
    signal(SIGHUP, catch_signal);
    mlockall(MCL_CURRENT|MCL_FUTURE);
        
    if (argc < 2) {
        printf("usage: %s <interface>\n", argv[0]);
        return 0;
    }

    if ((sock = socket_rt(PF_PACKET, SOCK_RAW, htons(0x1234))) < 0) {
        perror("socket cannot be created");
        return 1;
    }
        
        printf("Socket created: socket id: %d\n", sock);
        
        int index_ioctl;
    strncpy(ifr.ifr_name, argv[1], IFNAMSIZ);
    if (ioctl_rt(sock, SIOCGIFINDEX, &ifr) < 0) {
        perror("cannot get interface index");
        close_rt(sock);
        return 1;
    }
        
        printf("Got interface: index: %d\n", index_ioctl);

    addr.sll_family   = AF_PACKET;
    addr.sll_protocol = htons(0x1234);
    addr.sll_ifindex  = ifr.ifr_ifindex;

    if (bind_rt(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
        perror("cannot bind to local ip/port");
        close_rt(sock);
        return 1;
    }

        printf("Receiving data...\n");
        int tel = 0;
    while (1) {
        len = recv_rt(sock, buffer, sizeof(buffer), 0);
        if (len < 0) {
                perror("Cannot Receive");
                        printf("Length: %d\n", len);
            break;
        }
                tel++;
        printf("Received frame %d of %d bytes\n", tel, len);

        //nanosleep(&delay, NULL);
    }

    /* This call also leaves primary mode, required for socket cleanup. */
    printf("shutting down\n");

    while ((close_rt(sock) < 0) && (errno == EAGAIN)) {
        printf("socket busy - waiting...\n");
        sleep(1);
    }

    return 0;
}
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
RTnet-users mailing list
RTnet-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rtnet-users

Reply via email to