Dear,

I tried that file just now, but when I compile it, there are too many error so 
it can't be tested. Do you know why is this keep error? I think it is from the 
included files or the way I include the libraries and included files. It keep 
get error from the undeclared something or error from the .h's files.

Thanks

===
the command:
gcc -lnative -lrtdk -I /usr/xenomai/include/ -I /usr/local/rtnet/include/ -I 
/usr/xenomai/include/native/ -I /usr/src/rtnet-0.9.12/stack/include/ -I 
/usr/xenomai/include/nucleus/ -D _GNU_SOURCE -D_REENTRANT -Wall -pipe -D 
__XENO__ -L /usr/xenomai/lib/ -lxenomai -lpthread -lnative -lrtdk 
/home/mon/Desktop/raw-packets.c -o /home/mon/Desktop/raw-packets


===
the errors is something like this:
/home/mon/Desktop/raw-packets.c:25:26: error: linux/module.h: No such file or 
directory
/home/mon/Desktop/raw-packets.c:38:41: error: missing binary operator before 
token "("
/home/mon/Desktop/raw-packets.c:41: error: expected ‘)’ before string constant
/home/mon/Desktop/raw-packets.c:43: error: expected ‘)’ before ‘int’
/home/mon/Desktop/raw-packets.c:44: error: expected ‘)’ before string constant
/home/mon/Desktop/raw-packets.c:45: error: expected ‘)’ before string constant
/home/mon/Desktop/raw-packets.c:47: error: expected declaration specifiers or 
‘...’ before string constant
/home/mon/Desktop/raw-packets.c:47: warning: data definition has no type or 
storage class
/home/mon/Desktop/raw-packets.c:47: warning: type defaults to ‘int’ in 
declaration of ‘MODULE_LICENSE’
/home/mon/Desktop/raw-packets.c: In function ‘send_msg’:
/home/mon/Desktop/raw-packets.c:81: warning: implicit declaration of function 
‘printk’
/home/mon/Desktop/raw-packets.c: In function ‘init_module’:
/home/mon/Desktop/raw-packets.c:139: warning: implicit declaration of function 
‘htons’
/home/mon/Desktop/raw-packets.c:143: warning: implicit declaration of function 
‘rt_eth_aton’
/home/mon/Desktop/raw-packets.c: In function ‘cleanup_module’:
/home/mon/Desktop/raw-packets.c:233: warning: implicit declaration of function 
‘set_current_state’
/home/mon/Desktop/raw-packets.c:233: error: ‘TASK_UNINTERRUPTIBLE’ undeclared 
(first use in this function)
/home/mon/Desktop/raw-packets.c:233: error: (Each undeclared identifier is 
reported only once
/home/mon/Desktop/raw-packets.c:233: error: for each function it appears in.)
/home/mon/Desktop/raw-packets.c:234: warning: implicit declaration of function 
‘schedule_timeout’
===
I am confused with these error:
/home/mon/Desktop/raw-packets.c:25:26: error: linux/module.h: No such file or 
directory
/home/mon/Desktop/raw-packets.c:38:41: error: missing binary operator before 
token "("
/home/mon/Desktop/raw-packets.c:41: error: expected ‘)’ before string constant
/home/mon/Desktop/raw-packets.c:43: error: expected ‘)’ before ‘int’
/home/mon/Desktop/raw-packets.c:44: error: expected ‘)’ before string constant
/home/mon/Desktop/raw-packets.c:45: error: expected ‘)’ before string constant
/home/mon/Desktop/raw-packets.c:47: error: expected declaration specifiers or 
‘...’ before string constant
==>for the first line error, while I locate the linux/module.h  that is told in 
the error "no such 
file or directory" and add the located file (maybe 
usr/src/linux-2.6.32.11/include/) to the gcc command, it get more (a lot
 of) errors.
===>I am confused with the others line of error

and the one those looks like

/home/mon/Desktop/raw-packets.c:233: error: ‘TASK_UNINTERRUPTIBLE’ 
undeclared (first use in this function)
==> is there something I miss with the included file/library?


--- On Tue, 2/22/11, Andreas Kasper <a.kas...@kabsi.at> wrote:

From: Andreas Kasper <a.kas...@kabsi.at>
Subject: Re: [RTnet-users] [ask] how to send and receive packet with real time 
network in rtnet
To: "Ramon Rusli" <mon_...@yahoo.com>
Cc: "rtnet" <rtnet-users@lists.sourceforge.net>
Date: Tuesday, February 22, 2011, 7:49 PM

Hi,
  I'm also new to rtnet (and RTAI). Therefore I don't know what you have to 
change to use this code on xenomai. But there are examples in the rtnet 
archive. Download the newest archive and look in the following 
directory:/rtnet-0.9.12/examples/xenomai/native/kernel/

There is a file called raw-packets.c. I think this will help you.

Andreas Kasper

  Zitat Ramon Rusli <mon_...@yahoo.com>:
  
    
      
        
          Dear,

Thanks a lot Mr Kasper. From your code, which sections are needed to be changed 
if I use Xenomai, not RTAI? Because I am using xenomai, not RTAI.

I am sorry if this answer is too be beginner, I am very new with this. Thank 
you so much.

--- On Tue, 2/22/11, Andreas Kasper <a.kas...@kabsi.at> wrote:

            
From: Andreas Kasper <a.kas...@kabsi.at>
Subject: Re: [RTnet-users] [ask] how to send and receive packet with real time 
network in rtnet
To: "Ramon Rusli" <mon_...@yahoo.com>
Cc: "rtnet" <rtnet-users@lists.sourceforge.net>
Date: Tuesday, February 22, 2011, 7:28 AM


              
                Hello, 
                I think you are looking for the following code: 
                
 
                

#include <stdio.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <string.h>

#include <rtai_lxrt.h>
#include <rtnet.h>

#define LXRTTASKID 4444

static struct sockaddr_in net_client;
static struct sockaddr_in net_canrouter;

int main( int argc, char **argv )
{
    RT_TASK *lxrttask;
    int sock;

    RTIME start;
    RTIME end;

    char welcomemessage[] = "Welcome";

    /* init network strutures */
    memset( &net_client, 0, sizeof( struct sockaddr_in ) );
    memset( &net_canrouter, 0, sizeof( struct sockaddr_in ) );


    /* disable paging for the current process */
    if ( -1 == mlockall( MCL_CURRENT | MCL_FUTURE )
 )
    {
        printf("Error: mlockall failed\n");

        exit( EXIT_FAILURE );
    }

    /* local network interface configuration */
    net_client.sin_family = AF_INET;
    net_client.sin_addr.s_addr = INADDR_ANY;
    net_client.sin_port = htons( 333 ); /* local udp port */

    /* udp destinaton configuration */
    net_canrouter.sin_family = AF_INET;
    net_canrouter.sin_addr.s_addr = inet_addr( "192.168.22.1" );
    //printf("INET_ATON: %d\n", inet_aton( "192.168.22.1", 
&net_canrouter.sin_addr) );
    net_canrouter.sin_port= htons( 333 ); /* remode udp port */

    /* create udp socket */
    if ( ( sock = rt_dev_socket( AF_INET,
 SOCK_DGRAM, 0 ) ) < 0 )
    {
        printf("Error: rt_dev_socket\n");

        exit( EXIT_FAILURE );
    }

    /* init realtime task */
    if ( ( lxrttask = rt_task_init( LXRTTASKID, 1, 0, 0 ) ) == NULL )
    {
        rt_dev_close( sock );
 
        printf("Error: rt_task_init\n");

        exit( EXIT_FAILURE );
    }

    printf("switching to hard real time mode\n");


    /* switch to hard real time mode */
    rt_make_hard_real_time( );


    /* bind local rt socket */
    if ( 0 != rt_dev_bind( sock, (struct sockaddr *) &net_client, sizeof( struct
 sockaddr_in ) ) )
    {
        rt_make_soft_real_time( );

        rt_dev_close( sock );

        rt_task_delete( lxrttask );

        printf("Error: rt_dev_bind\n");

        exit( EXIT_FAILURE );
    }

    /* connect can router */
    if ( 0 != rt_dev_connect( sock, (struct sockaddr *) &net_canrouter, sizeof( 
struct sockaddr_in ) ) )
    {
        rt_make_soft_real_time( );

        rt_dev_close( sock );

        rt_task_delete( lxrttask );

        printf("Error: rt_dev_connect\n");

        exit(
 EXIT_FAILURE );
    }

    /* rt & network initialization completed */

    printf("send\n");


    /* send welcome message to the can router */
    rt_dev_send( sock, welcomemessage, sizeof( welcomemessage ), 0 );


    printf("=> soft realtime\n");

    rt_make_soft_real_time( );

    printf("=> close\n");

    rt_dev_close( sock );

    printf("=> task_delete\n");

    rt_task_delete( lxrttask );

    printf("=> exit\n");

    printf("start: %g\nende: %g\n", start, end );

    exit( EXIT_SUCCESS );
}

 
                
 
                You have to use the following libraries: 
                -llxrt -lpthread 
                
 
                and the following include pathes: 
                -I/usr/realtime/include -I/usr/local/rtnet/include 
                
 
                
 
                Andreas Kasper
 
                
 
                
 
                
 
                Zitat Ramon Rusli <mon_...@yahoo.com>: 
                 
                   
                     
                       
                        Dear,

How can I use rtnet to send or receive packet in c? i am a bit confused because 
no examples or tutorial to build the program using rtnet while I search it in 
internet. i want to make a real time packet sending program and a real time 
packet receiver program using rtnet 0.9.12 and xenomai 2.5.4. the operating 
system that I use is linux fedora 13 kernel 2.6.32.11. 

Is it just add some include and some lines from standard udp packet server and 
client program? 

thanks a lot
==========================
//the standard udp packet server that I build (server.c)
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/socket.h>
#include
 <mqueue.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <pthread.h>
#include <sys/mman.h>
#include <signal.h>
#include <limits.h>
#define PORT 7788
#define BUFLEN 65000
#define NPACK 10000000

void diep (char *s)
{
    perror (s);
    exit (1);
}

int main (void)
{
    struct sockaddr_in si_me, si_other;
    int s, i, slen=sizeof(si_other);
    char buf[BUFLEN];

    if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))== -1)
    {
        diep("socket");    
    }

    memset ((char *) &si_me, 0, sizeof(si_me));
    si_me.sin_family = AF_INET;
    si_me.sin_port = htons(PORT);
   
 si_me.sin_addr.s_addr = htonl(INADDR_ANY);
    if (bind(s, &si_me, sizeof(si_me)) == -1)
    {
        diep("bind");
    }

    for(i = 0; i < NPACK; i++)
    {
        if(recvfrom(s, buf, BUFLEN, 0, &si_other, &slen) == -1)
        {
            diep("recvfrom()");
        }
        printf("received packet from %s:%d\n Data: %s\n\n", 
inet_ntoa(si_other.sin_addr), ntohs(si_other.sin_port), buf);
    }
    close(s);
    return 0;
}


=============================
//the standard udp packet client (client.c)
#include <stdlib.h>
#include
 <unistd.h>
#include <string.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <mqueue.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <pthread.h>
#include <sys/mman.h>
#include <signal.h>
#include <limits.h>

#define PORT 7788
#define BUFLEN 65000
#define NPACK 10000000
#define SRV_IP "167.205.34.150"

void diep (char *s)
{
    perror (s);
    exit (1);
}

int main ()
{
    struct sockaddr_in si_other;
    int s, i, slen=sizeof(si_other);
    char buf[BUFLEN];

    if((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
    {
        diep("socket");
   
 }

    memset((char *) &si_other, 0, sizeof(si_other));
    si_other.sin_family=AF_INET;
    si_other.sin_port = htons(PORT);
    if(inet_aton(SRV_IP, &si_other.sin_addr)==0)
    {
        fprintf(stderr, "inet_aton () failed\n");
        exit (1);
    }    

    for(i=0; i< NPACK; i++)
    {
        printf("sending packet %d\n", i);
        sprintf(buf, "This is packet %d\n",i);
        if (sendto(s, buf, BUFLEN, 0, &si_other, slen) == -1)
        {
            diep("sendto()");
       
 }
    }
    close(s);
return 0;
}
============================
 
                       
                     
                  
 
                
              
            
          
        
      
    
 
  


      
------------------------------------------------------------------------------
Free Software Download: Index, Search & Analyze Logs and other IT data in 
Real-Time with Splunk. Collect, index and harness all the fast moving IT data 
generated by your applications, servers and devices whether physical, virtual
or in the cloud. Deliver compliance at lower cost and gain new business 
insights. http://p.sf.net/sfu/splunk-dev2dev 
_______________________________________________
RTnet-users mailing list
RTnet-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rtnet-users

Reply via email to