⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 distifudp.c

📁 VXWORKS源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* distIfUdp.c - distributed objects UDP adapter library (VxFusion option) *//* Copyright 1999-2002 Wind River Systems, Inc. *//*modification history--------------------01l,22oct01,jws  fix diab compiler warnings (SPR 71117)01k,11jun99,drm  Changing flags to host byte order before checking for                 broadcast flag.01j,24may99,drm  Adding vxfusion prefix to VxFusion related includes.01i,19may99,drm  Changing WindMP to VxFusion.01h,25feb99,drm  added additional status output during initialization01g,22feb99,drm  adding #include for distNetLib.h01f,30oct98,drm  documentation updates01e,29oct98,drm  removed maxTBufs argument to distIfUdpInit01d,01sep98,drm  removed pDistIf definition01c,04aug98,drm  cleanup and bug fixes01b,20may98,drm  removed compiler warning messages01a,04apr98,jag  written.*//*DESCRIPTIONThis module implements a UDP adapter for VxFusion.  This is the default adapter that VxFusion uses when it starts up.There are only two external routines: distIfUdpInit() and distIfUdpStart().Both are called by the VxFusion initialization routine distInit() and should not be called directly by the user.AVAILABILITYThis module is distributed as a component of the unbundled distributedmessage queues option, VxFusion.INCLUDE FILES: distIfUdp.hSEE ALSO: distLib*//* includes */#include "vxWorks.h"#include "string.h"#include "stdio.h"#include "taskLib.h"#include "sysLib.h"#include "inetLib.h"#include "sockLib.h"#include "netLib.h"#include "ioLib.h"#include "wdLib.h"#include "usrLib.h"#include "sys/ioctl.h"#include "netinet/in.h"#include "net/if.h"#include "selectLib.h"#include "errnoLib.h"#include "vxfusion/distIfLib.h"#include "vxfusion/distStatLib.h"#include "vxfusion/distNetLib.h"#include "drv/vxfusion/distIfUdp.h"/* defines */#define UNUSED_ARG(x)  if (sizeof(x)) {};  /* suppress compiler warning */#define SOCKOPT_ON  1                   /* 1 = on for setsockopt() */#define sleep(timeO) taskDelay (timeO * (sysClkRateGet())) /* macro *//* locals */LOCAL DIST_IF distIfUdp;                /* used to set pDistIf */LOCAL BOOL distIfUdpInstalled = FALSE;  /* indicates whether driver installed */LOCAL BOOL distIfUdpStarted   = FALSE;  /* indicates whether driver started */LOCAL int ioSocket = 0;                 /* socket used to send/rcv messages */LOCAL unsigned long  myIpAddr      = 0; /* used to uniquely identify node */LOCAL unsigned long  myIpBcastAddr = 0; /* address used to broadcast packets *//* forward declarations */STATUS distIfUdpStart (void *pConf);                 /* startup function */LOCAL STATUS distIfUdpSend (DIST_NODE_ID nodeIdDest,                             DIST_TBUF *pTBuf,                            int priority);           /* send function */LOCAL int distIfUdpIoctl (int func, ...);            /* ioctl function */LOCAL void distIfUdpInputTask (void);                /* input function *//***************************************************************************** distIfUdpInit - initialize the UDP driver (VxFusion option)** Initialize the UDP driver for VxFusion.** \is* \i This routine initializes the UDP driver by doing the following:* * * Temporarily opening a socket in order to determine the IP address, netmask, * and broadcast address for that interface.** Filling in the DIST_IF structure which provides the upper layers with some * necessary information about the adapter and transport * \ie** AVAILABILITY* This routine is distributed as a component of the unbundled distributed* message queues option, VxFusion.* * RETURNS: OK, or ERROR if the operation fails */STATUS distIfUdpInit    (    void *    pConf,        /* not currently used */    FUNCPTR * pStartup      /* Ptr to startup routine */    )    {    int bsocket;           /* socket used to obtain broadcast address */    int retVal;            /* variable used to check return value */    struct ifreq ifr;      /* interface request struct for socket ioctls */    struct in_addr ifAddr; /* ip address for the interface */    struct in_addr ifMask; /* netmask for the interface*/    *pStartup = (FUNCPTR) (distIfUdpStart);    if (distIfUdpInstalled)        {#ifdef DIST_DIAGNOSTIC        printf ("distIfUdpInit() - already initalized.\n");#endif        return (OK);        }    /*     * Temporarily open a socket in order to determine the node IP address,      * netmask, and broadcast address.     */    bsocket = socket (AF_INET, SOCK_RAW, 0);    if (bsocket == -1)        {        printf ("distIfUdpInit() - can't open RAW socket (errno = %d)\n",                errno);        printf ("Unable to initialize VxFusion UDP adapter.\n");        return (ERROR);        }    bzero ((char *)&ifr, sizeof (struct ifreq));    if ((strlen (pConf) + 1) > IFNAMSIZ)        {        printf ("distIfUdpInit() - interface name too long");        printf ("Unable to initialize VxFusion UDP adapter.\n");        close (bsocket);        return (ERROR);        }    strcpy (ifr.ifr_name, (char *) pConf);    /* Get interface IP address */    retVal = ioctl (bsocket, (int)SIOCGIFADDR, (int)&ifr);    if (retVal != 0)        {        printf ("distIfUdpInit() - ioctl SIOCGIFADDR failed (errno = %d)\n",                errno);        printf ("Unable to initialize VxFusion UDP adapter.\n");        close (bsocket);        return (ERROR);        }    ifAddr.s_addr = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr;    myIpAddr = ntohl (ifAddr.s_addr);    /* Get interface IP Netmask */    retVal = ioctl (bsocket, (int)SIOCGIFNETMASK, (int)&ifr);    if (retVal != 0)        {        printf ("distIfUdpInit() - ioctl SIOCGIFNETMASK failed (errno=%d)\n",                errno);        printf ("Unable to initialize VxFusion UDP adapter.\n");        close (bsocket);        return (ERROR);        }    ifMask.s_addr = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr;    close (bsocket);    /*     * Extract network address and fill host portion with ones     * in order to create broadcast address.     */    myIpBcastAddr = (ifAddr.s_addr & ifMask.s_addr) | ~ifMask.s_addr;    myIpBcastAddr = ntohl (myIpBcastAddr);      /* Fill in the distIfUdp structure */    distIfUdp.distIfName          = "UDP adapter";    distIfUdp.distIfMTU           = UDP_MTU_BUF_SZ;    distIfUdp.distIfHdrSize       = sizeof (NET_HDR);    distIfUdp.distIfBroadcastAddr = myIpBcastAddr;    distIfUdp.distIfRngBufSz      = UDP_RING_BUF_SZ;    distIfUdp.distIfMaxFrags      = UDP_MAX_FRAGS;      distIfUdp.distIfSend          = distIfUdpSend;    distIfUdp.distIfIoctl         = distIfUdpIoctl;    pDistIf = &distIfUdp;    distIfUdpInstalled = TRUE;    printf ("VxFusion UDP adapter initialized OK\n");    return (OK);    }/***************************************************************************** distIfUdpStart - start the UDP adapter (VxFusion option)** This routine creates a socket that is used for communications.  After* enabling the broadcast option on the socket, it spawns the input task.** AVAILABILITY* This routine is distributed as a component of the unbundled distributed* message queues option, VxFusion.** RETURNS: OK, or ERROR if unable to perform the socket operations or * spawn the input task*/STATUS distIfUdpStart    (    void * pConf      /* ptr to configuration data - not used here */    )    {    int optval;                       /* options value for setsockopt() */    struct sockaddr_in addrToListen;  /* socket info needed for bind() call */        UNUSED_ARG(pConf);        if (distIfUdpStarted)        {#ifdef DIST_DIAGNOSTIC        printf ("distIfUdpStart() - already started.\n");#endif        return (OK);        }    /* Open socket */    if ((ioSocket = socket (AF_INET, SOCK_DGRAM, 0)) < 0)        {        printf ("distIfUdpStart() - ioSocket open failed (errno = %d)\n",                errno);        printf ("Unable to start VxFusion UDP adapter.\n");        return (ERROR);        }    /* Enable broadcast option for socket. */    optval = SOCKOPT_ON;    if ((setsockopt (ioSocket, SOL_SOCKET, SO_BROADCAST, (char *)&optval,                     sizeof (optval))) < 0)        {        printf ("distIfUdpStart() - setsockopt SO_BROADCAST failed ");        printf ("(errno = %d)\n", errno);        printf ("Unable to start VxFusion UDP adapter.\n");        close (ioSocket);        return (ERROR);        }    /* Initialize source address. */    bzero ((char *)&addrToListen, sizeof (addrToListen));    addrToListen.sin_addr.s_addr = INADDR_ANY;    addrToListen.sin_family      = AF_INET;    addrToListen.sin_port        = htons (UDP_IO_PORT);    /* Bind to the socket */          if ((bind (ioSocket, (struct sockaddr *)&addrToListen,                sizeof (addrToListen))) < 0)        {        printf ("distIfUdpStart() - ioSocket bind failed (errno = %d)\n",

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -