what`s wrong with the routine ? the operation system is vxworks - VxWorks

This is a discussion on what`s wrong with the routine ? the operation system is vxworks - VxWorks ; #include "taskLib.h" #include #include "strLib.h" #include #include #include #include #include #include #include "types/vxTypesOld.h" #include "sockLib.h" #include "inetLib.h" #include "stdioLib.h" #include "unistd.h" #include "socket.h" #include "arpa/inet.h" #include "in.h" int rev() { int i; int rcv_fd; struct sockaddr_in local; char pBuf[1024]; int ...

+ Reply to Thread
Results 1 to 6 of 6

Thread: what`s wrong with the routine ? the operation system is vxworks

  1. what`s wrong with the routine ? the operation system is vxworks

    #include "taskLib.h"
    #include
    #include "strLib.h"
    #include
    #include
    #include
    #include
    #include
    #include
    #include "types/vxTypesOld.h"
    #include "sockLib.h"
    #include "inetLib.h"
    #include "stdioLib.h"
    #include "unistd.h"
    #include "socket.h"
    #include "arpa/inet.h"
    #include "in.h"

    int rev()
    {
    int i;
    int rcv_fd;
    struct sockaddr_in local;
    char pBuf[1024];
    int status;
    int noblock=1;

    bzero ((char *) &local, sizeof (struct sockaddr_in));
    local.sin_family=AF_INET;
    local.sin_port=htons(8888);
    local.sin_addr.s_addr= htonl(INADDR_ANY);



    if ((rcv_fd = socket (AF_INET, SOCK_DGRAM, 0)) == ERROR)
    {
    perror ("open receive socket ERROR");
    close (rcv_fd);
    return (ERROR);
    }




    status = ioctl (rcv_fd, FIONBIO, &noblock);
    if(setsockopt(rcv_fd,SOL_SOCKET,SO_BROADCAST,(char *)
    (&noblock),sizeof(int))==ERROR)
    {
    perror("setsockopt failed");
    return ERROR;
    }



    if(bind(rcv_fd,(struct sockaddr*)&local,sizeof(struct
    sockaddr))==ERROR)
    {
    perror ("bind receive socket ERROR");
    close (rcv_fd);
    return (ERROR);
    }


    while(1)

    {
    sleep(1);
    i = recvfrom (rcv_fd,pBuf,1024,0,NULL,NULL);

    if(i>=0)
    printf("%s\n",pBuf);
    }
    close(rcv_fd);

    return 0;

    }

  2. Re: what`s wrong with the routine ? the operation system is vxworks

    It would be helpful to know what you were expecting to observe and
    what you actually did observe.

    Peter

    On Jul 25, 7:16*am, 84529...@qq.com wrote:
    > #include "taskLib.h"
    > #include
    > #include "strLib.h"
    > #include
    > #include
    > #include
    > #include
    > #include
    > #include
    > #include "types/vxTypesOld.h"
    > #include "sockLib.h"
    > #include "inetLib.h"
    > #include "stdioLib.h"
    > #include "unistd.h"
    > #include "socket.h"
    > #include "arpa/inet.h"
    > #include "in.h"
    >
    > int rev()
    > {
    > * * * * int i;
    > * * * * int rcv_fd;
    > * * * * struct sockaddr_in local;
    > * * * * char pBuf[1024];
    > * * * * int status;
    > * * * * int noblock=1;
    >
    > * * * * bzero ((char *) &local, sizeof (struct sockaddr_in));
    > * * * * local.sin_family=AF_INET;
    > * * * * local.sin_port=htons(8888);
    > * * * * local.sin_addr.s_addr= htonl(INADDR_ANY);
    >
    > * * * * if ((rcv_fd = socket (AF_INET, SOCK_DGRAM, 0)) == ERROR)
    > * * * * {
    > * * * * * * * * perror ("open receive socket *ERROR");
    > * * * * * * * * close (rcv_fd);
    > * * * * * * * * return (ERROR);
    > * * * * }
    >
    > * * * * status = ioctl (rcv_fd, FIONBIO, &noblock);
    > * * * * if(setsockopt(rcv_fd,SOL_SOCKET,SO_BROADCAST,(char *)
    > (&noblock),sizeof(int))==ERROR)
    > * * * * {
    > * * * * * * * * perror("setsockopt failed");
    > * * * * * * * * return ERROR;
    > * * * * }
    >
    > * * * * if(bind(rcv_fd,(struct sockaddr*)&local,sizeof(struct
    > sockaddr))==ERROR)
    > * * * * {
    > * * * * * * * * perror ("bind receive socket *ERROR");
    > * * * * * * * * close (rcv_fd);
    > * * * * * * * * return (ERROR);
    > * * * * }
    >
    > * * * * while(1)
    >
    > * * * * {
    > * * * * * * * * sleep(1);
    > * * * * * * * * i = recvfrom (rcv_fd,pBuf,1024,0,NULL,NULL);
    >
    > * * * * * * * * if(i>=0)
    > * * * * * * * * printf("%s\n",pBuf);
    > * * * * }
    > * * * * close(rcv_fd);
    >
    > * * * * return 0;
    >
    >
    >
    > }



  3. Re: what`s wrong with the routine ? the operation system is vxworks

    > 84529229@qq.com wrote [2008-07-25 6:16 AM]:

    > printf("%s\n",pBuf);


    Why should pBuf contain a null-terminated string?

  4. Re: what`s wrong with the routine ? the operation system is vxworks

    On 7月25日, 下午9时09分, peter.mit...@gmail.com wrote:
    > It would be helpful to know what you were expecting to observe and
    > what you actually did observe.
    >
    > Peter
    >
    > On Jul 25, 7:16 am, 84529...@qq.com wrote:
    >
    >
    >
    > > #include "taskLib.h"
    > > #include
    > > #include "strLib.h"
    > > #include
    > > #include
    > > #include
    > > #include
    > > #include
    > > #include
    > > #include "types/vxTypesOld.h"
    > > #include "sockLib.h"
    > > #include "inetLib.h"
    > > #include "stdioLib.h"
    > > #include "unistd.h"
    > > #include "socket.h"
    > > #include "arpa/inet.h"
    > > #include "in.h"

    >
    > > int rev()
    > > {
    > > int i;
    > > int rcv_fd;
    > > struct sockaddr_in local;
    > > char pBuf[1024];
    > > int status;
    > > int noblock=1;

    >
    > > bzero ((char *) &local, sizeof (struct sockaddr_in));
    > > local.sin_family=AF_INET;
    > > local.sin_port=htons(8888);
    > > local.sin_addr.s_addr= htonl(INADDR_ANY);

    >
    > > if ((rcv_fd = socket (AF_INET, SOCK_DGRAM, 0)) == ERROR)
    > > {
    > > perror ("open receive socket ERROR");
    > > close (rcv_fd);
    > > return (ERROR);
    > > }

    >
    > > status = ioctl (rcv_fd, FIONBIO, &noblock);
    > > if(setsockopt(rcv_fd,SOL_SOCKET,SO_BROADCAST,(char *)
    > > (&noblock),sizeof(int))==ERROR)
    > > {
    > > perror("setsockopt failed");
    > > return ERROR;
    > > }

    >
    > > if(bind(rcv_fd,(struct sockaddr*)&local,sizeof(struct
    > > sockaddr))==ERROR)
    > > {
    > > perror ("bind receive socket ERROR");
    > > close (rcv_fd);
    > > return (ERROR);
    > > }

    >
    > > while(1)

    >
    > > {
    > > sleep(1);
    > > i = recvfrom (rcv_fd,pBuf,1024,0,NULL,NULL);

    >
    > > if(i>=0)
    > > printf("%s\n",pBuf);
    > > }
    > > close(rcv_fd);

    >
    > > return 0;

    >
    > > }- 隐藏被引用文字 -

    >
    > - 显示引用的文字 -


    i want to observe the communication of the client and server ,
    but return of the recvfrom() is zero,and the buffer pBuf is NULL.
    so i think maybe some wrong in some function.but i cann`t find it ,so
    i hope you can help me , or tell me what `s wrong with the function.

  5. Re: what`s wrong with the routine ? the operation system is vxworks

    Is UDP included in your kernel build ?
    INCLUDE_UDP

  6. Re: what`s wrong with the routine ? the operation system is vxworks

    On Jul 31, 1:15*pm, george.ara...@gd-ais.com wrote:
    > Is UDP included in your kernel build ?
    > INCLUDE_UDP


    Also, have you looked at the example in the VxWorks Network manual ?

+ Reply to Thread