Пример #1
0
rtipChannel::~rtipChannel()
{
	if (slcid_ >= 0) {
		int st = RcapCloseRequest(u_short(slcid_), 0);
		if (st != 1)
			printf("rcap close: %d\n", st);
	}
	if (rlcid_ >= 0) {
		int st = RcapCloseRequest(u_short(rlcid_), 0);
		if (st != 1)
			printf("rcap close: %d\n", st);
	}
}
Пример #2
0
//---------------------------------------------------------------------------
int TIsoTcpSocket::isoSendBuffer(void *Data, int Size)
{
	int Result;
	u_int IsoSize;

    ClrIsoError();
	// Total Size = Size + Header Size
	IsoSize =Size+DataHeaderSize;
	// Checks the length
	if ((IsoSize>0) && (IsoSize<=IsoFrameSize))
	{
		// Builds the header
		Result =0;
		// TPKT
		PDU.TPKT.Version  = isoTcpVersion;
		PDU.TPKT.Reserved = 0;
		PDU.TPKT.HI_Lenght= (u_short(IsoSize)>> 8) & 0xFF;
		PDU.TPKT.LO_Lenght= u_short(IsoSize) & 0xFF;
		// COPT
		PDU.COTP.HLength   =sizeof(TCOTP_DT)-1;
		PDU.COTP.PDUType   =pdu_type_DT;
		PDU.COTP.EoT_Num   =pdu_EoT;
		// Fill payload
		if (Data!=0) // Data=null ==> use internal buffer PDU.Payload
            memcpy(&PDU.Payload, Data, Size);
        // Send over TCP/IP
        SendPacket(&PDU, IsoSize);

        if (LastTcpError!=0)
            Result =SetIsoError(errIsoSendPacket);
	}
Пример #3
0
//-----------------------------------------------------------------------------------------------
void Server::SetPortToBindToFromParameters( NamedProperties& parameters )
{
	std::string portAsString;

	parameters.Get( "param1", portAsString );

	FATAL_ASSERTION( portAsString != "", "Command: port did not receive the correct parameters.\nport expects a non empty string." );

	m_currentServerPort = u_short( atoi( portAsString.c_str() ) );
}
Пример #4
0
// Takes a header and its value
// Reads and processes popular Gnutella headers
// Returns true to have ReadHeaders keep going
BOOL CConnection::OnHeaderLine(CString& strHeader, CString& strValue)
{
	theApp.Message( MSG_DEBUG | MSG_FACILITY_INCOMING, _T("%s >> %s: %s"), (LPCTSTR)m_sAddress, (LPCTSTR)strHeader, (LPCTSTR)strValue );

	// It's the user agent header
	if ( strHeader.CompareNoCase( _T("User-Agent") ) == 0 )
	{
		// Copy the value into the user agent member string
		m_sUserAgent = strValue;	// This tells what software the remote computer is running
		m_bClientExtended = VendorCache.IsExtended( m_sUserAgent );
	}
	// It's the remote IP header
	else if ( strHeader.CompareNoCase( _T("Remote-IP") ) == 0 )
	{
		// Add this address to our record of them
		Network.AcquireLocalAddress( strValue );
	}
	// It's the x my address, listen IP, or node header, like "X-My-Address: 10.254.0.16:6349"
	else if (  strHeader.CompareNoCase( _T("X-My-Address") ) == 0
			|| strHeader.CompareNoCase( _T("Listen-IP") ) == 0
			|| strHeader.CompareNoCase( _T("X-Node") ) == 0
			|| strHeader.CompareNoCase( _T("Node") ) == 0 )
	{
		// Find another colon in the value
		int nColon = strValue.Find( ':' );

		// If the remote computer first contacted us and the colon is there but not first
		if ( ! m_bInitiated && nColon > 0 )
		{
			// Read the number after the colon into nPort
			int nPort = protocolPorts[ PROTOCOL_G1 ];	// Start out nPort as the default value, 6346
			if ( _stscanf( strValue.Mid( nColon + 1 ), _T("%lu"), &nPort ) == 1 && nPort != 0 )		// Make sure 1 number was found, and isn't 0
			{
				// Save the found port number in m_pHost
				m_pHost.sin_port = htons( u_short( nPort ) );	// Convert Windows little endian to big for the Internet with htons
			}
		}
	}
	else if ( strHeader.CompareNoCase( _T("Accept") ) == 0 )
	{
		if ( _tcsistr( strValue, _T("application/x-gnutella-packets") ) &&
			m_nProtocol != PROTOCOL_G2 )
			m_nProtocol = PROTOCOL_G1;
		if ( _tcsistr( strValue, _T("application/x-gnutella2") ) ||
			 _tcsistr( strValue, _T("application/x-shareaza") ) ||
			 _tcsistr( strValue, _T("application/x-peerproject") ) )
			m_nProtocol = PROTOCOL_G2;
	}

	// Have ReadHeaders keep going
	return TRUE;
}
Пример #5
0
Connection::Connection(int id, const char* ip, int port, int cryptKey){
	mID = id;
	mAddr.sin_family = AF_INET;
	mAddr.sin_addr.s_addr = inet_addr(ip);
	mAddr.sin_port = htons(u_short(port));
	mState = STATE_WAITING;
	mSocket = 0;
	mRecvSize = 6;
	mRecvCur = 0;
	mSendSize = 0;

	mKey = 0;

	mDisconnect = false;

	if(cryptKey == 0)
		mCrypt.Default();
	else
		mCrypt.Init(cryptKey);
}
Пример #6
0
int
ACE_SOCK_Dgram_Bcast::mk_broadcast (const ACE_TCHAR *host_name)
{
  ACE_TRACE ("ACE_SOCK_Dgram_Bcast::mk_broadcast");

  int one = 1;

  if (ACE_OS::setsockopt (this->get_handle (),
                          SOL_SOCKET,
                          SO_BROADCAST,
                          (char *) &one,
                          sizeof one) == -1)
    ACELIB_ERROR_RETURN ((LM_ERROR, ACE_TEXT("%p\n"),
                      ACE_TEXT("ACE_SOCK_Dgram_Bcast::mk_broadcast: setsockopt failed")),
                      -1);

#if !defined (ACE_WIN32) && !defined(__INTERIX)
  ACE_HANDLE s = this->get_handle ();

  char buf[BUFSIZ];
  struct ifconf ifc;

  ifc.ifc_len = sizeof buf;
  ifc.ifc_buf = buf;

  // Get interface structure and initialize the addresses using UNIX
  // techniques.
  if (ACE_OS::ioctl (s,
                     SIOCGIFCONF,
                     (char *) &ifc) == -1)
    ACELIB_ERROR_RETURN ((LM_ERROR, ACE_TEXT("%p\n"),
                      ACE_TEXT("ACE_SOCK_Dgram_Bcast::mk_broadcast: ioctl (get interface configuration)")),
                      ACE_INVALID_HANDLE);

  struct ifreq *ifr = ifc.ifc_req;

  struct sockaddr_in host_addr;

  // Get host ip address
  if (host_name)
    {
      hostent *hp = ACE_OS::gethostbyname (ACE_TEXT_ALWAYS_CHAR (host_name));

      if (hp == 0)
        return -1;
      else
        ACE_OS::memcpy ((char *) &host_addr.sin_addr.s_addr,
# ifdef ACE_HOSTENT_H_ADDR
                        (char *) hp->ACE_HOSTENT_H_ADDR,
# else
                        (char *) hp->h_addr,
# endif
                        hp->h_length);
    }


#if !defined(AIX) && !defined (__QNX__) && !defined (__FreeBSD__) && !defined(__NetBSD__) && !defined (ACE_VXWORKS) && !defined(__APPLE__)
  for (int n = ifc.ifc_len / sizeof (struct ifreq) ; n > 0;
       n--, ifr++)
#else
  /*
     There are addresses longer than sizeof (struct sockaddr) eg. IPv6
     or QNX::links. In this case address does not fit into struct ifreq.
     The code below could be applied everywhere, but not every system
         provides sockaddr.sa_len field.
   */
  for (int nbytes = ifc.ifc_len; nbytes >= (int) sizeof (struct ifreq) &&
        ((ifr->ifr_addr.sa_len > sizeof (struct sockaddr)) ?
          (nbytes >= (int) sizeof (ifr->ifr_name) + ifr->ifr_addr.sa_len) : 1);
        ((ifr->ifr_addr.sa_len > sizeof (struct sockaddr)) ?
          (nbytes -= sizeof (ifr->ifr_name) + ifr->ifr_addr.sa_len,
            ifr = (struct ifreq *)
              ((caddr_t) &ifr->ifr_addr + ifr->ifr_addr.sa_len)) :
          (nbytes -= sizeof (struct ifreq), ifr++)))
#endif /* !defined(AIX) && !defined (__QNX__) && !defined (__FreeBSD__) && !defined(__NetBSD__) && !defined (ACE_VXWORKS) && !defined(__APPLE__) */
    {
#if defined (__QNX__) || defined (ACE_VXWORKS)
      // Silently skip link interfaces
      if (ifr->ifr_addr.sa_family == AF_LINK)
        continue;
#endif /* __QNX__ || ACE_VXWORKS */
      // Compare host ip address with interface ip address.
      if (host_name)
        {
          struct sockaddr_in if_addr;

          ACE_OS::memcpy (&if_addr,
                          &ifr->ifr_addr,
                          sizeof if_addr);

          if (host_addr.sin_addr.s_addr != if_addr.sin_addr.s_addr)
            continue;
        }

      if (ifr->ifr_addr.sa_family != AF_INET)
        {
          // Note that some systems seem to generate 0 (AF_UNDEF) for
          // the sa_family, even when there are no errors!  Thus, we
          // only print an error if this is not the case, or if we're
          // in "debugging" mode.
          if (ifr->ifr_addr.sa_family != 0
              || ACE::debug ())
          ACELIB_DEBUG ((LM_DEBUG,
                      ACE_TEXT("warning %p: sa_family: %d\n"),
                      ACE_TEXT("ACE_SOCK_Dgram_Bcast::mk_broadcast: Not AF_INET"),
                      ifr->ifr_addr.sa_family));
          continue;
        }

      struct ifreq flags = *ifr;
      struct ifreq if_req = *ifr;

      if (ACE_OS::ioctl (s,
                         SIOCGIFFLAGS,
                         (char *) &flags) == -1)
        {
          ACELIB_ERROR ((LM_ERROR, ACE_TEXT("%p [%s]\n"),
                     ACE_TEXT("ACE_SOCK_Dgram_Bcast::mk_broadcast: ioctl (get interface flags)"),
                     flags.ifr_name));
          continue;
        }

      if (ACE_BIT_ENABLED (flags.ifr_flags,
                           IFF_UP) == 0)
        {
          ACELIB_ERROR ((LM_ERROR, ACE_TEXT("%p [%s]\n"),
                     ACE_TEXT("ACE_SOCK_Dgram_Bcast::mk_broadcast: Network interface is not up"),
                     flags.ifr_name));
          continue;
        }

      if (ACE_BIT_ENABLED (flags.ifr_flags,
                           IFF_LOOPBACK))
        continue;

      if (ACE_BIT_ENABLED (flags.ifr_flags,
                           IFF_BROADCAST))
        {
          if (ACE_OS::ioctl (s,
                             SIOCGIFBRDADDR,
                             (char *) &if_req) == -1)
            ACELIB_ERROR ((LM_ERROR, ACE_TEXT("%p [%s]\n"),
                       ACE_TEXT("ACE_SOCK_Dgram_Bcast::mk_broadcast: ioctl (get broadaddr)"),
                       flags.ifr_name));
          else
            {
              ACE_INET_Addr addr (reinterpret_cast <sockaddr_in *>
                                                   (&if_req.ifr_broadaddr),
                                  sizeof if_req.ifr_broadaddr);
              ACE_NEW_RETURN (this->if_list_,
                              ACE_Bcast_Node (addr,
                                              this->if_list_),
                              -1);
            }
        }
      else
        {
          if (host_name != 0)
            ACELIB_ERROR ((LM_ERROR, ACE_TEXT("%p [%s]\n"),
                        ACE_TEXT("ACE_SOCK_Dgram_Bcast::mk_broadcast: Broadcast is not enabled for this interface."),
                        flags.ifr_name));
        }
    }
#else
  ACE_UNUSED_ARG (host_name);

  ACE_INET_Addr addr (u_short (0),
                      ACE_UINT32 (INADDR_BROADCAST));
  ACE_NEW_RETURN (this->if_list_,
                  ACE_Bcast_Node (addr,
                                  this->if_list_),
                  -1);
#endif /* !ACE_WIN32 && !__INTERIX */
  if (this->if_list_ == 0)
    {
      errno = ENXIO;
      return -1;
    }
  else
    return 0;
}
Пример #7
0
int
ACE_INET_Addr::string_to_addr (const char s[], int address_family)
{
  ACE_TRACE ("ACE_INET_Addr::string_to_addr");
  int result;
  char *ip_buf = 0;
  char *ip_addr = 0;

  // Need to make a duplicate since we'll be overwriting the string.
  ACE_ALLOCATOR_RETURN (ip_buf,
                        ACE_OS::strdup (s),
                        -1);
  ip_addr = ip_buf;
  // We use strrchr because of IPv6 addresses.
  char *port_p = ACE_OS::strrchr (ip_addr, ':');
#if defined (ACE_HAS_IPV6)
  // Check for extended IPv6 format : '[' <ipv6 address> ']' ':' <port>
  if (ip_addr[0] == '[')
    {
      // find closing bracket
      char *cp_pos = ACE_OS::strchr (ip_addr, ']');
      // check for port separator after closing bracket
      // if not found leave it, error will come later
      if (cp_pos)
        {
          *cp_pos = '\0'; // blank out ']'
          ++ip_addr; // skip over '['
          if (cp_pos[1] == ':')
            port_p = cp_pos + 1;
          else
            port_p = cp_pos; // leads to error on missing port
        }
    }
#endif /* ACE_HAS_IPV6 */

  if (port_p == 0) // Assume it's a port number.
    {
      char *endp = 0;
      long const port = ACE_OS::strtol (ip_addr, &endp, 10);

      if (*endp == '\0')    // strtol scanned the entire string - all digits
        {
          if (port < 0 || port > ACE_MAX_DEFAULT_PORT)
            result = -1;
          else
            result = this->set (u_short (port), ACE_UINT32 (INADDR_ANY));
        }
      else // port name
        result = this->set (ip_addr, ACE_UINT32 (INADDR_ANY));
    }
  else
    {
      *port_p = '\0'; ++port_p; // skip over ':'

      char *endp = 0;
      long port = ACE_OS::strtol (port_p, &endp, 10);

      if (*endp == '\0')    // strtol scanned the entire string - all digits
        {
          if (port < 0 || port > ACE_MAX_DEFAULT_PORT)
            result = -1;
          else
            result = this->set (u_short (port), ip_addr, 1, address_family);
        }
      else
        result = this->set (port_p, ip_addr);
    }

  ACE_OS::free (ACE_MALLOC_T (ip_buf));
  return result;
}
Пример #8
0
/*
 * This is the tricky part -- do not casually change *anything* in here.  The
 * idea is to build the linked list of entries that are used by yfts_children
 * and yfts_read.  There are lots of special cases.
 *
 * The real slowdown in walking the tree is the stat calls.  If FTS_NOSTAT is
 * set and it's a physical walk (so that symbolic links can't be directories),
 * we can do things quickly.  First, if it's a 4.4BSD file system, the type
 * of the file is in the directory entry.  Otherwise, we assume that the number
 * of subdirectories in a node is equal to the number of links to the parent.
 * The former skips all stat calls.  The latter skips stat calls in any leaf
 * directories and for any files after the subdirectories in the directory have
 * been found, cutting the stat calls by about 2/3.
 */
static FTSENT *
fts_build(FTS * sp, int type)
{
    struct dirent *dp;
    FTSENT *p, *head;
    int nitems;
    FTSENT *cur, *tail;

#ifdef _win_
    dird dirpd;
    struct DIR *dirp;
#else
    DIR *dirp;
#endif

    void *oldaddr;
    int cderrno, descend, len, level, maxlen, nlinks, saved_errno,
        nostat, doadjust;
    char *cp;

    /* Set current node pointer. */
    cur = sp->fts_cur;

    /*
     * Open the directory for reading.  If this fails, we're done.
     * If being called from yfts_read, set the fts_info field.
     */
#ifdef FTS_WHITEOUT
    if (ISSET(FTS_WHITEOUT))
        oflag = DTF_NODUP|DTF_REWIND;
    else
        oflag = DTF_HIDEW|DTF_NODUP|DTF_REWIND;
#else
#define __opendir2(path, flag) opendir(path)
#endif
    if ((dirp = __opendir2(cur->fts_accpath, oflag)) == NULL) {
        if (type == BREAD) {
            cur->fts_info = FTS_DNR;
            cur->fts_errno = errno;
        }
        return (NULL);
    }

#ifdef _win_
    dirpd = get_dird(cur->fts_accpath);
#endif

    /*
     * Nlinks is the number of possible entries of type directory in the
     * directory if we're cheating on stat calls, 0 if we're not doing
     * any stat calls at all, -1 if we're doing stats on everything.
     */
    if (type == BNAMES) {
        nlinks = 0;
        /* Be quiet about nostat, GCC. */
        nostat = 0;
    } else if (ISSET(FTS_NOSTAT) && ISSET(FTS_PHYSICAL)) {
        nlinks = cur->fts_nlink - (ISSET(FTS_SEEDOT) ? 0 : 2);
        nostat = 1;
    } else {
        nlinks = -1;
        nostat = 0;
    }

#ifdef notdef
    (void)printf("nlinks == %d (cur: %d)\n", nlinks, cur->fts_nlink);
    (void)printf("NOSTAT %d PHYSICAL %d SEEDOT %d\n",
                 ISSET(FTS_NOSTAT), ISSET(FTS_PHYSICAL), ISSET(FTS_SEEDOT));
#endif
    /*
     * If we're going to need to stat anything or we want to descend
     * and stay in the directory, chdir.  If this fails we keep going,
     * but set a flag so we don't chdir after the post-order visit.
     * We won't be able to stat anything, but we can still return the
     * names themselves.  Note, that since yfts_read won't be able to
     * chdir into the directory, it will have to return different path
     * names than before, i.e. "a/b" instead of "b".  Since the node
     * has already been visited in pre-order, have to wait until the
     * post-order visit to return the error.  There is a special case
     * here, if there was nothing to stat then it's not an error to
     * not be able to stat.  This is all fairly nasty.  If a program
     * needed sorted entries or stat information, they had better be
     * checking FTS_NS on the returned nodes.
     */
    cderrno = 0;
    if (nlinks || type == BREAD) {
#ifndef _win_
        if (fts_safe_changedir(sp, cur, dirfd(dirp), NULL)) {
#else
        if (fts_safe_changedir(sp, cur, -1, dirpd)) {
#endif

            if (nlinks && type == BREAD)
                cur->fts_errno = errno;
            cur->fts_flags |= FTS_DONTCHDIR;
            descend = 0;
            cderrno = errno;
            (void)closedir(dirp);
            dirp = NULL;
#ifdef _win_
            close_dird(dirpd);
            dirpd = invalidDirD;
#else
            UNUSED(invalidDirD);
#endif
        } else
            descend = 1;
    } else
        descend = 0;

    /*
     * Figure out the max file name length that can be stored in the
     * current path -- the inner loop allocates more path as necessary.
     * We really wouldn't have to do the maxlen calculations here, we
     * could do them in yfts_read before returning the path, but it's a
     * lot easier here since the length is part of the dirent structure.
     *
     * If not changing directories set a pointer so that can just append
     * each new name into the path.
     */
    len = NAPPEND(cur);
    if (ISSET(FTS_NOCHDIR)) {
        cp = sp->fts_path + len;
        *cp++ = LOCSLASH_C;
    } else {
        /* GCC, you're too verbose. */
        cp = NULL;
    }
    len++;
    maxlen = sp->fts_pathlen - len;

    level = cur->fts_level + 1;

    /* Read the directory, attaching each entry to the `link' pointer. */
    doadjust = 0;

    //to ensure enough buffer
    TTempBuf dpe;

    for (head = tail = NULL, nitems = 0; dirp && (dp = yreaddir(dirp, (struct dirent*)dpe.Data())) != 0;) {
        if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name))
            continue;

        if ((p = fts_alloc(sp, dp->d_name, (int)strlen(dp->d_name))) == NULL)
            goto mem1;
        if (strlen(dp->d_name) >= (size_t)maxlen) {    /* include space for NUL */
            oldaddr = sp->fts_path;
            if (fts_palloc(sp, strlen(dp->d_name) +len + 1)) {
                /*
                 * No more memory for path or structures.  Save
                 * errno, free up the current structure and the
                 * structures already allocated.
                 */
mem1:
                saved_errno = errno;
                if (p)
                    free(p);
                fts_lfree(head);
                (void)closedir(dirp);
#ifdef _win_
                close_dird(dirpd);
#endif
                cur->fts_info = FTS_ERR;
                SET(FTS_STOP);
                errno = saved_errno;
                return (NULL);
            }
            /* Did realloc() change the pointer? */
            if (oldaddr != sp->fts_path) {
                doadjust = 1;
                if (ISSET(FTS_NOCHDIR))
                    cp = sp->fts_path + len;
            }
            maxlen = sp->fts_pathlen - len;
        }

        if (len + strlen(dp->d_name) >= USHRT_MAX) {
            /*
             * In an FTSENT, fts_pathlen is a u_short so it is
             * possible to wraparound here.  If we do, free up
             * the current structure and the structures already
             * allocated, then error out with ENAMETOOLONG.
             */
            free(p);
            fts_lfree(head);
            (void)closedir(dirp);
#ifdef _win_
            close_dird(dirpd);
#endif
            cur->fts_info = FTS_ERR;
            SET(FTS_STOP);
            errno = ENAMETOOLONG;
            return (NULL);
        }
        p->fts_level = (short)level;
        p->fts_parent = sp->fts_cur;
        p->fts_pathlen = u_short(len + strlen(dp->d_name));

#ifdef FTS_WHITEOUT
        if (dp->d_type == DT_WHT)
            p->fts_flags |= FTS_ISW;
#endif

        if (cderrno) {
            if (nlinks) {
                p->fts_info = FTS_NS;
                p->fts_errno = cderrno;
            } else
                p->fts_info = FTS_NSOK;
            p->fts_accpath = cur->fts_accpath;
        } else if (nlinks == 0
#ifdef DT_DIR
                   || (nostat &&
                       dp->d_type != DT_DIR && dp->d_type != DT_UNKNOWN)
#endif
                  ) {
            p->fts_accpath =
                ISSET(FTS_NOCHDIR) ? p->fts_path : p->fts_name;
            p->fts_info = FTS_NSOK;
        } else {
            /* Build a file name for fts_stat to stat. */
            if (ISSET(FTS_NOCHDIR)) {
                p->fts_accpath = p->fts_path;
                memmove((void*)cp, (void*)p->fts_name, (size_t)p->fts_namelen + 1);
            } else
                p->fts_accpath = p->fts_name;
            /* Stat it. */
            p->fts_info = fts_stat(sp, p, 0);

            /* Decrement link count if applicable. */
            if (nlinks > 0 && (p->fts_info == FTS_D ||
                               p->fts_info == FTS_DC || p->fts_info == FTS_DOT))
                --nlinks;
        }

        /* We walk in directory order so "ls -f" doesn't get upset. */
        p->fts_link = NULL;
        if (head == NULL)
            head = tail = p;
        else {
            tail->fts_link = p;
            tail = p;
        }
        ++nitems;
    }
    if (dirp) {
        (void)closedir(dirp);
#ifdef _win_
        close_dird(dirpd);
#endif
    }

    /*
     * If realloc() changed the address of the path, adjust the
     * addresses for the rest of the tree and the dir list.
     */
    if (doadjust)
        fts_padjust(sp);

    /*
     * If not changing directories, reset the path back to original
     * state.
     */
    if (ISSET(FTS_NOCHDIR)) {
        if (len == sp->fts_pathlen || nitems == 0)
            --cp;
        *cp = '\0';
    }

    /*
     * If descended after called from yfts_children or after called from
     * yfts_read and nothing found, get back.  At the root level we use
     * the saved fd; if one of yfts_open()'s arguments is a relative path
     * to an empty directory, we wind up here with no other way back.  If
     * can't get back, we're done.
     */
    if (descend && (type == BCHILD || !nitems) &&
            (cur->fts_level == FTS_ROOTLEVEL ?
             FCHDIR(sp, sp->fts_rfd) :
             fts_safe_changedir(sp, cur->fts_parent, -1, ".."))) {
        cur->fts_info = FTS_ERR;
        SET(FTS_STOP);
        return (NULL);
    }

    /* If didn't find anything, return NULL. */
    if (!nitems) {
        if (type == BREAD)
            cur->fts_info = FTS_DP;
        return (NULL);
    }

    /* Sort the entries. */
    if (sp->fts_compar && nitems > 1)
        head = fts_sort(sp, head, nitems);
    return (head);
}

static u_short
fts_stat(FTS * sp, FTSENT * p, int follow)
{
    dev_t dev;
    ino_t ino;
    struct stat *sbp, sb;
    int saved_errno;
    /* If user needs stat info, stat buffer already allocated. */
    sbp = ISSET(FTS_NOSTAT) ? &sb : p->fts_statp;

#ifdef FTS_WHITEOUT
    /* check for whiteout */
    if (p->fts_flags & FTS_ISW) {
        if (sbp != &sb) {
            memset(sbp, '\0', sizeof (*sbp));
            sbp->st_mode = S_IFWHT;
        }
        return (FTS_W);
    }
#endif

    /*
     * If doing a logical walk, or application requested FTS_FOLLOW, do
     * a stat(2).  If that fails, check for a non-existent symlink.  If
     * fail, set the errno from the stat call.
     */
    if (ISSET(FTS_LOGICAL) || follow) {
        if (stat(p->fts_accpath, sbp)) {
            saved_errno = errno;
            if (!lstat(p->fts_accpath, sbp)) {
                errno = 0;
                return (FTS_SLNONE);
            }
            p->fts_errno = saved_errno;
            memset(sbp, 0, sizeof(struct stat));
            return (FTS_NS);
        }
    }
    else if (lstat(p->fts_accpath, sbp)) {
        p->fts_errno = errno;
        memset(sbp, 0, sizeof(struct stat));
        return (FTS_NS);
    }

    if (S_ISDIR(sbp->st_mode)) {
        /*
         * Set the device/inode.  Used to find cycles and check for
         * crossing mount points.  Also remember the link count, used
         * in fts_build to limit the number of stat calls.  It is
         * understood that these fields are only referenced if fts_info
         * is set to FTS_D.
         */
        dev = p->fts_dev = sbp->st_dev;
        ino = p->fts_ino = sbp->st_ino;
        p->fts_nlink = sbp->st_nlink;

        const char* fts_name_x = p->fts_name;
        if (ISDOT(fts_name_x))
            return (FTS_DOT);

        /*
         * Cycle detection is done by brute force when the directory
         * is first encountered.  If the tree gets deep enough or the
         * number of symbolic links to directories is high enough,
         * something faster might be worthwhile.
         */

        //There is no way to detect symlink or mount cycles on win32

#ifndef _win_
        FTSENT *t;
        for (t = p->fts_parent;
                t->fts_level >= FTS_ROOTLEVEL; t = t->fts_parent)
            if (ino == t->fts_ino && dev == t->fts_dev) {
                p->fts_cycle = t;
                return (FTS_DC);
            }
#endif /*_win_*/
        return (FTS_D);

    }
    if (S_ISLNK(sbp->st_mode))
        return (FTS_SL);
    if (S_ISREG(sbp->st_mode))
        return (FTS_F);
    return (FTS_DEFAULT);
}
Пример #9
0
void main ( int argc, char **argv )
{
    extern void InitEZ(void);

    InitEZ();

    VkApp       *app;

 //COMMS----------------------------------------------   
    int op = 0 ;
    extern char *optarg;
    extern int optind, operr;

    // Multicast Defaults
    int multicast = TRUE;
    u_short port;
    char group[25];
    u_char ttl = IDU_DEF_MC_TTL;
    port = 0;
    int loopback = FALSE;
    //int loopback = TRUE;

    char net_interface[20];
    
    //initialize global data structures
    oodidu.ood_rudder_angle = 0;   
    oodidu.ood_rpm = 0;   
    oodidu.ood_port_bell = 0;   
    oodidu.ood_stbd_bell = 0;   
    oodidu.space_holder = 0;

 //COMMS----------------------------------------------   

    strncpy ( group, IDU_DEF_MC_GROUP,25 );   //COMMS
    strcpy ( net_interface, "" );             //COMMS

 //COMMS----------------------------------------------   
   while ((op = getopt(argc, argv, "P:p:G:g:T:t:BblLI:i:")) != -1)
      {
      switch (op)
         {
         case 'p':
         case 'P':
            port = u_short(atoi(optarg));
            break;
         case 'G':
         case 'g':
            strncpy ( group, optarg, 25 );
            break;
         case 't':
         case 'T':
            ttl =  u_char(atoi(optarg));
            break;
         case 'b':
         case 'B':
            multicast = FALSE;
            break; 
         case 'l':
         case 'L':
            loopback = TRUE;
            break;
         case 'i':
         case 'I':
            strncpy ( net_interface, optarg, 19 );
            break;
         default:
            cerr << "Usage:  idudump [-p <network port>] \n"
                 << "                [-i <network interface>] \n"
                 << "                [-g <multicast group>] \n"
                 << "                [-t <multicast ttl>] \n"
                 << "                [-b   (to enable broadcast) \n";
            exit(0);
            break;
         }
      }

   if ( multicast )
      {
      if ( port == 0 )
         port = IDU_DEF_MC_PORT;
      net = new IDU_net_manager ( group, port, ttl, net_interface,
                                  loopback );
      }
   else
      {
      if ( port == 0 )
         port = IDU_DEF_BC_PORT;
      net = new IDU_net_manager ( port, net_interface, loopback );
      }

   if ( !net->net_open() )
      {
      cerr << "Could not open network." << endl;
      exit(0);
      }
   else
      {
      net->add_to_receive_list(Test_Type);
      net->add_to_receive_list(NPSNET_To_SHIP_Type);
      }

   if ( multicast )
      {
      cerr << "\tMode:     \tMulticast" << endl;
      cerr << "\tPort:     \t" << (int)port << endl;
      cerr << "\tGroup:    \t" << group << endl;
      cerr << "\tTTL:      \t" << (int)ttl << endl;
      cerr << "\tInterface:\t" << net_interface << endl;
      cerr << "\tLoopback: \t";
      if ( loopback )
         cerr << "ON" << endl;
      else
         cerr << "OFF" << endl;
      cerr << endl;
      }
   else
      {
      cerr << "\tMode:     \tBroadcast" << endl;
      cerr << "\tPort:     \t" << (int)port << endl;
      cerr << "\tInterface:\t" << net_interface << endl << endl;
      cerr << "\tLoopback: \t";
      if ( loopback )
         cerr << "ON" << endl;
      else
         cerr << "OFF" << endl;
      cerr << endl;
      }
  //COMMS----------------------------------------------   


    //initialize packet
    //packet = new SHIP_MSG_DATA;
    
    // Create an application object
    app = new VkApp("Application", &argc, argv); 

    // Create the top level windows

    VkSimpleWindow *shipControlWindow  = 
                    new ShipControlWindowMainWindow("shipControlWindow");
    shipControlWindow->show();
cerr<<"Starting Application..."<<endl;
    app->run ();
}