コード例 #1
0
ファイル: TextAnalyse.cpp プロジェクト: monokura/csharp
//意味のある単語まで飛ぶ
bool TextAnalyse::next( void )
{
	for(;;)
	{
		if( pos >= last ) return false;

		//コメントを飛ばす
		if( commentNoSkip == false && pos[0] == '/' && pos[1] == '/' )
		{
			pos += 2;
			for(; pos < last && pos[0] != '\n'; pos += checksize( pos ) ){}
			if( pos >= last ) return false;
			pos ++;
		}
		else
		if( commentNoSkip == false && pos[0] == '/' && pos[1] == '*' )
		{
			pos += 2;
			for(; pos < last && ( pos[0] != '*' || pos[1] != '/' ) ; pos += checksize( pos ) ){}
			if( pos >= last ) return false;
			pos += 2;
		}
		else
		//空白を飛ばす
		if( checkC( *pos ) == false )
		{
			for(; pos < last && checkC( *pos ) == false; pos ++ ){}
			if( pos >= last ) return false;
		}
		else break ;
	}

	return true;
}
コード例 #2
0
ファイル: root.c プロジェクト: aahud/harvey
int
vtrootunpack(VtRoot *r, uint8_t *p)
{
	uint8_t *op = p;
	uint vers;
	memset(r, 0, sizeof(*r));

	vers = U16GET(p);
	if(vers != VtRootVersion) {
		werrstr("unknown root version");
		return -1;
	}
	p += 2;
	memmove(r->name, p, sizeof(r->name));
	r->name[sizeof(r->name)-1] = 0;
	p += sizeof(r->name);
	memmove(r->type, p, sizeof(r->type));
	r->type[sizeof(r->type)-1] = 0;
	p += sizeof(r->type);
	memmove(r->score, p, VtScoreSize);
	p +=  VtScoreSize;
	r->blocksize = U16GET(p);
	if(checksize(r->blocksize) < 0)
		return -1;
	p += 2;
	memmove(r->prev, p, VtScoreSize);
	p += VtScoreSize;

	assert(p-op == VtRootSize);
	return 0;
}
コード例 #3
0
ファイル: io-mmap.c プロジェクト: coreyreichle/xastir
struct io_file *io_open(const char *fname) {
	struct io_file * const f = malloc(sizeof *f);

	if (NULL == f) return NULL;
	f->fd = open(fname,O_RDWR|O_CREAT,0666);
        f->prot = PROT_READ|PROT_WRITE;
        if (f->fd < 0) {
                f->fd = open(fname,O_RDONLY);
                f->prot = PROT_READ;
        }
	if (f->fd < 0) {
		perror(fname);
		free(f);
		return NULL;
	}

	f->map = NULL;
	f->map_offset = 0;
	f->map_size = 0;
	f->map_page = getpagesize();
	f->file_size = 0;
	f->buffer_offset = 0;
	f->buffer_size = 0;
	if (checksize(f)) {
		close(f->fd);
		free(f);
		return NULL;
	}

	return f;
}
コード例 #4
0
ファイル: disk161.c プロジェクト: ops-class/sys161
static
void
docreate(const char *file, const char *sizespec, int doforce)
{
    int fd;
    off_t size;

    if (!doforce) {
        fd = open(file, O_RDONLY);
        if (fd >= 0) {
            fprintf(stderr, "disk161: %s: %s\n", file,
                    strerror(EEXIST));
            exit(1);
        }
    }

    fd = doopen(file, O_RDWR|O_CREAT|O_TRUNC, 0664);
    doflock(file, fd, LOCK_EX);
    size = getsize(sizespec);
    checksize(size);
    dotruncate(file, fd, HEADERSIZE + size);
    writeheader(file, fd);
    doflock(file, fd, LOCK_UN);
    close(fd);
}
コード例 #5
0
ファイル: lundump.c プロジェクト: bbayles/netsa-pkg
static void checkHeader (LoadState *S) {
  checkliteral(S, LUA_SIGNATURE + 1, "not a");  /* 1st char already checked */
  if (LoadByte(S) != LUAC_VERSION)
    error(S, "version mismatch in");
  if (LoadByte(S) != LUAC_FORMAT)
    error(S, "format mismatch in");
  checkliteral(S, LUAC_DATA, "corrupted");
  checksize(S, int);
  checksize(S, size_t);
  checksize(S, Instruction);
  checksize(S, lua_Integer);
  checksize(S, lua_Number);
  if (LoadInteger(S) != LUAC_INT)
    error(S, "endianness mismatch in");
  if (LoadNumber(S) != LUAC_NUM)
    error(S, "float format mismatch in");
}
main()
{
char name[100];
printf("Enter the string");
scanf("%s",name);
size=checksize(&name);
enter(&name);
}
コード例 #7
0
ファイル: disk161.c プロジェクト: ops-class/sys161
static
void
doresize(const char *file, const char *sizespec)
{
    enum { M_SET, M_PLUS, M_MINUS } mode;
    off_t oldsize, newsize;
    int fd;

    if (*sizespec == '+') {
        sizespec++;
        mode = M_PLUS;
    }
    else if (*sizespec == '-') {
        sizespec++;
        mode = M_MINUS;
    }
    else {
        mode = M_SET;
    }

    newsize = getsize(sizespec);
    fd = doopen(file, O_RDWR, 0);
    doflock(file, fd, LOCK_EX);
    checkheader(file, fd);
    oldsize = filesize(file, fd);
    oldsize -= HEADERSIZE;
    switch (mode) {
    case M_SET:
        break;
    case M_PLUS:
        if (oldsize + newsize < oldsize) {
            /* overflow */
            fprintf(stderr, "+%s: Result too large\n", sizespec);
            exit(1);
        }
        newsize = oldsize + newsize;
        break;
    case M_MINUS:
        if (oldsize < newsize) {
            /* underflow */
            fprintf(stderr, "-%s: Result too small\n", sizespec);
            exit(1);
        }
        newsize = oldsize - newsize;
        break;
    }

    checksize(newsize);
    dotruncate(file, fd, HEADERSIZE + newsize);
    doflock(file, fd, LOCK_UN);
    close(fd);
}
コード例 #8
0
ファイル: TextAnalyse.cpp プロジェクト: monokura/csharp
//次の行に移動する
bool TextAnalyse::nextline( void )
{
	for(;;)
	{
		if( pos >= last ) return false;

		if( pos[0] == '\n' )
		{
			pos++;
			break;
		}

		pos += checksize( pos );
	}

	return true;
}
コード例 #9
0
ファイル: io-mmap.c プロジェクト: coreyreichle/xastir
int io_in(struct io_file *f,int pos,void *i,int len) {
	int end = pos + len;
	if (0 == len) return pos;
	if (NULL == f || -1 == pos) return -1;
	if (NULL == i) return pos + len;
	if (remap(f,pos,len)) return -1;
	if (unbuffer(f)) return -1;

	if (pos >= f->file_size && checksize(f)) return -1;
	if (pos >= f->file_size) {
/* TODO: fill with zeroes instead */
		fputs("read: EOF\n",stderr);
		return -1;
	}

	if (end > (int)(f->map_offset + f->map_size))
		end = f->map_offset + f->map_size;
	if (end > f->file_size)
		end = f->file_size;
	memcpy(i,pos - f->map_offset + (char *) f->map,end - pos);
	return io_in(f,end,end - pos + (char *) i,len + pos - end);
}
コード例 #10
0
ファイル: server.cpp プロジェクト: M-griffin/NTP
bool NTPSRV::recvfinfo()
{

    char message[255];
    char tMsg[255]= {0};
    char szBuf[2048];
    int nRet;

    // Get Information Packet From Client
    char tmpin[1000]= {0};
    std::string msgEop;
    int id;

    logntp ( "Receiving File Info.. .", NODE );

    // Loop through RECV() Untll We Get all of the Packet
    for ( ;; )
    {
        memset ( szBuf, 0, sizeof ( szBuf ) ); // clear buffer
        nRet = recv ( msock.rsock, szBuf, sizeof ( szBuf ), 0 );

        if ( nRet == INVALID_SOCKET )
        {
            memset ( &finfo2[0][NODE],0,sizeof ( FILEINFO ) );
            sprintf ( message,"Error: Recv() Getting File Info, Re-Trying.. ." );
            logntp ( message, NODE );
            strcpy ( finfo2[0][NODE].status,message );
        }
        else if ( nRet == SOCKET_ERROR )
        {
#ifdef _WIN32
            if ( ( nRet = WSAGetLastError () ) != WSAEWOULDBLOCK )
            {
#else
            if ( errno != WSAEWOULDBLOCK )
            {
#endif
                memset ( &finfo2[0][NODE],0,sizeof ( FILEINFO ) );
                sprintf ( message,"Error: Getting File Info, Lost Connection.. ." );
                logntp ( message, NODE );
                strcpy ( finfo2[0][NODE].status,message );
                closesocks();
                return false;
            }
        }
        else
            strcat ( tmpin,szBuf );

        // Check for End of String!
        msgEop = tmpin;
        id = 0;
        id = msgEop.find ( "\r\n\r\n", 0 );
        // Received End of Packet
        if ( id != -1 ) break;

    } // End of For Recv Loop

    strcpy ( tmpin,tmpin );

    // After Receiving Full Packet, Chop it up so we can Sort the Information
    char tmppak[255]= {0};
    memset ( tmppak,0,255 );
    int pamcnt, ab;
    pamcnt = 0;
    ab = 0;
    int num = 0;
    std::string cut;
    int id1;

    char arg[255]= {0};

    // Cut Up Recevied Packet and Get the Following Information
    for ( int i = 0; ; i++ )
    {
        if ( tmpin[i] == '\0' ) break;
        if ( tmpin[i] == '\n' )
        {
            ++pamcnt;
            // Check for BBS Version String
            if ( pamcnt == 1 )
            {
                strcpy ( finfo[0][NODE].bbsver,tmppak );
                memset ( tmppak,0,sizeof ( tmppak ) );
                ab = 0;
                sprintf ( message,"BBS Version: %s",finfo[0][NODE].bbsver );
                logntp ( message, NODE );

                // If Not Correction Version, Exit!
                if ( strcmp ( finfo[0][NODE].bbsver,BBSVER ) != 0 )
                {
                    memset ( &finfo2[0][NODE],0,sizeof ( FILEINFO ) );
                    sprintf ( message,"Error: Otherside is using NTP %s, Please Update!",finfo[0][NODE].bbsver );
                    logntp ( message, NODE );
                    strcpy ( finfo2[0][NODE].status,message );
                    closesocks();
                    return false;
                }
            }
            // Check for Filename String
            else if ( pamcnt == 2 )
            {
                ab = 0;
                strcpy ( arg,tmppak );
                memset ( tmppak,0,sizeof ( tmppak ) );

                // Get True Filename and cute off Path if found!!
                for ( int i = 0; ; i++ )          // Count for Romoval of ExeName from Path
                {
                    if ( arg[i] == '\0' ) break;  // End of String, Break
#ifdef _WIN32
                    if ( arg[i] == '\\' ) num = i; // Find last or only '\' in String
#else
                    if ( arg[i] == '/' ) num = i; // Find last or only '/' in String
#endif
                }
                if ( num == 0 )
                {
                    strcpy ( finfo[0][NODE].filename,arg );
                }
                else
                {
                    int r = 0;
                    for ( int i = num+1; ; i++ )  // Copy all Chars after last '\'
                    {
                        if ( arg[i] == '\0' ) break;
                        finfo[0][NODE].filename[r] = arg[i];
                        r++;
                    }
                }
                sprintf ( message,"Filename: %s",finfo[0][NODE].filename );
                logntp ( message, NODE );
            }
            // Check for Filesize String
            else if ( pamcnt == 3 )
            {
                memset ( arg,0,sizeof ( arg ) );
                strcpy ( arg,tmppak );
                finfo[0][NODE].size = atol ( arg );
                memset ( tmppak,0,sizeof ( tmppak ) );
                ab = 0;
                sprintf ( message,"Filesize: %i",finfo[0][NODE].size );
                logntp ( message, NODE );
            }
            // Check for Batch Queue String
            else if ( pamcnt == 4 )
            {
                strcpy ( finfo[0][NODE].bqueue,tmppak );
                memset ( tmppak,0,sizeof ( tmppak ) );
                ab = 0;
                sprintf ( message,"Queue: %s",finfo[0][NODE].bqueue );
                logntp ( message, NODE );
                break;
            }
        }
        else
        {
            tmppak[ab] = tmpin[i];
            ab++;
        }
    }
    return true;
}

int NTPSRV::resume()
{

    // Check if we are getting New File or Resuming Old
    long totbyte=0;                    // Total Bytes Received
    char message[255];
    char rezBuf[2048]= {0};
    char tBuf[2048]= {0};
    int nRet;

    // Get File Size to check for Resume or Complete
    checksize(); // Where file is in byte count for resume

    sprintf ( rezBuf,"%i\r\n\r\n",finfo[0][NODE].flsz );

    // If Filesize 0, This is a New File, No Resume / Recovery
    if ( finfo[0][NODE].flsz == 0 )
    {
        for ( ;; )
        {
            nRet = send ( msock.rsock, rezBuf, sizeof ( rezBuf ), 0 );

            if ( nRet == INVALID_SOCKET )
            {
                sprintf ( message,"Error: Send() With Resume Info - Re-Trying!" );
                logntp ( message, NODE );
                strcpy ( finfo[0][NODE].status,message );
                memcpy ( &finfo2[0][NODE],&finfo[0][NODE],sizeof ( FILEINFO ) );
            }
            else if ( nRet == SOCKET_ERROR )
            {
#ifdef _WIN32
                if ( ( nRet = WSAGetLastError () ) != WSAEWOULDBLOCK )
                {
#else
                if ( errno != WSAEWOULDBLOCK )
                {
#endif
                    //Draw Transfer Status
                    sprintf ( message,"Error: Send() With Resume Info - Lost Connection!" );
                    logntp ( message, NODE );
                    strcpy ( finfo[0][NODE].status,message );
                    memcpy ( &finfo2[0][NODE],&finfo[0][NODE],sizeof ( FILEINFO ) );
                    closesocks();
                    return ( 2 );
                }
            }
            else
            {
                return ( 0 );
            }
        }
    }

    // If filesize == We Already have complete File!
    if ( finfo[0][NODE].flsz == finfo[0][NODE].size ) // Exit if the original file is same size as new
    {
        for ( ;; )
        {
            nRet = send ( msock.rsock, rezBuf, sizeof ( rezBuf ), 0 );

            if ( nRet == INVALID_SOCKET )
            {
                sprintf ( message,"Error: Send() With Resume Size - Retrying!" );
                logntp ( message, NODE );
                strcpy ( finfo[0][NODE].status,message );
                memcpy ( &finfo2[0][NODE],&finfo[0][NODE],sizeof ( FILEINFO ) );
            }
            else if ( nRet == SOCKET_ERROR )
            {
#ifdef _WIN32
                if ( ( nRet = WSAGetLastError () ) != WSAEWOULDBLOCK )
                {
#else
                if ( errno != WSAEWOULDBLOCK )
                {
#endif
                    //Draw Transfer Status
                    sprintf ( message,"Error: Send() With Resume Size - Lost Connection!" );
                    logntp ( message, NODE );
                    strcpy ( finfo[0][NODE].status,message );
                    memcpy ( &finfo2[0][NODE],&finfo[0][NODE],sizeof ( FILEINFO ) );
                    closesocks();
                    return ( 2 );
                }
            }
            else
            {
                sprintf ( message,"Error: You Already Have This Full File!" );
                logntp ( message, NODE );
                strcpy ( finfo[0][NODE].status,message );
                memcpy ( &finfo2[0][NODE],&finfo[0][NODE],sizeof ( FILEINFO ) );
                closesocks();
                return ( 2 );
            }
        }
    }

    // Else this is a Resume Recovery, Send Where we last Leftoff in Bytes
    for ( ;; )
    {
        nRet = send ( msock.rsock, rezBuf, sizeof ( rezBuf ), 0 );

        if ( nRet == INVALID_SOCKET )
        {
            sprintf ( message,"Error: Sending Resume Reply, Re-Trying!" );
            logntp ( message, NODE );
            strcpy ( finfo[0][NODE].status,message );
            memcpy ( &finfo2[0][NODE],&finfo[0][NODE],sizeof ( FILEINFO ) );
        }
        else if ( nRet == SOCKET_ERROR )
        {
#ifdef _WIN32
            if ( ( nRet = WSAGetLastError () ) != WSAEWOULDBLOCK )
            {
#else
            if ( errno != WSAEWOULDBLOCK )
            {
#endif
                //Draw Transfer Status
                sprintf ( message,"Error: Sending Resume Reply, Lost Connection!" );
                logntp ( message, NODE );
                strcpy ( finfo[0][NODE].status,message );
                memcpy ( &finfo2[0][NODE],&finfo[0][NODE],sizeof ( FILEINFO ) );
                closesocks();
                return ( 2 );
            }
        }
        else
        {
            break;
        }
    }
    return ( 1 );
}

void NTPSRV::recvfdata()
{

    char szBuf[2048];
    char message[255];
    int nRet;

    int c, i, j=1;
    long totbyte=0;
    FILE *nfp;

    // Create / Open File Depending on New / Resume
    if ( finfo[0][NODE].resum ) // True
    {
        totbyte = finfo[0][NODE].flsz;
        if ( ( nfp = fopen ( finfo[0][NODE].filename, "a+b" ) ) ==  NULL )
        {
            sprintf ( message,"Error! can't create: '%s'\n",finfo[0][NODE].filename );
            erbreak[0][NODE] = true;
            logntp ( message, NODE );
            strcpy ( finfo[0][NODE].status,message );
            memcpy ( &finfo2[0][NODE],&finfo[0][NODE],sizeof ( FILEINFO ) );
            closesocks();
            return;
        }
    }
    else   // False
    {
        if ( ( nfp = fopen ( finfo[0][NODE].filename, "w+b" ) ) ==  NULL )
        {
            sprintf ( message,"Error! can't create: '%s'\n",finfo[0][NODE].filename );
            erbreak[0][NODE] = true;
            logntp ( message, NODE );
            strcpy ( finfo[0][NODE].status,message );
            memcpy ( &finfo2[0][NODE],&finfo[0][NODE],sizeof ( FILEINFO ) );
            closesocks();
            return;
        }
    }

    // Kickoff File Transfer TransferGUI
#ifdef _WIN32
    HANDLE ahThread;
    ahThread = ( HANDLE ) _beginthread ( TransferGUI, 0, ( void* ) NODE );
#else
    pthread_t thread;
    pthread_create ( &thread, NULL, TransferGUI, ( void* ) NODE );
#endif
    Sleep ( 2000 );

    // Receive data from the client
    j=1;
    while ( j>0 )
    {
        memset ( szBuf, 0, sizeof ( szBuf ) );		// clear buffer

        nRet = recv ( msock.rsock,      			// Connected client
                      szBuf,							// Receive buffer
                      sizeof ( szBuf ),					// Lenght of buffer
                      0 );								// Flags
        j=nRet;

        if ( nRet == INVALID_SOCKET )
        {
            // On Invalid, Do at least 6 Retries on the Connection before Error out!
            for ( int rtry = 0; ; rtry++ )
            {
                Sleep ( 1000 );
                if ( rtry == 10 )
                {
#ifdef _WIN32
                    if ( ( nRet = WSAGetLastError () ) != WSAEWOULDBLOCK )
                    {
#else
                    if ( errno != WSAEWOULDBLOCK )
                    {
#endif
                        if ( finfo[0][NODE].size == totbyte )
                        {
                            j = 0;
                            break;
                        }
                        sprintf ( message,"Disconnected!" );
                        logntp ( message, NODE );
                        strcpy ( finfo[0][NODE].status,message );
                        memcpy ( &finfo2[0][NODE],&finfo[0][NODE],sizeof ( FILEINFO ) );
                        fclose ( nfp );
                        closesocks();
                        erbreak[0][NODE] = true;
                        return;
                    }
                    else rtry = 0;
                }

                nRet = recv ( msock.rsock,      		// Connected client
                              szBuf,						// Receive buffer
                              sizeof ( szBuf ),				// Lenght of buffer
                              0 );							// Flags

                j = nRet;
                if ( nRet == INVALID_SOCKET ) continue;
                else if ( nRet == SOCKET_ERROR ) break;
                else break;
            }
        }

        if ( nRet == SOCKET_ERROR )
        {
#ifdef _WIN32
            if ( ( nRet = WSAGetLastError () ) != WSAEWOULDBLOCK )
            {
#else
            if ( errno != WSAEWOULDBLOCK )
            {
#endif
                if ( finfo[0][NODE].size == totbyte )
                {
                    j = 0;    // Exit Casue File is Finished
                    break;
                }
                sprintf ( message,"Disconnected!" );
                logntp ( message, NODE );
                strcpy ( finfo[0][NODE].status,message );
                memcpy ( &finfo2[0][NODE],&finfo[0][NODE],sizeof ( FILEINFO ) );
                fclose ( nfp );
                closesocks();
                erbreak[0][NODE] = true;
                return;
            }
        }
        // receive data from client and save to file
        i=0;
        while ( nRet > i )
        {
            // End Transfer User Side once File is Complete!
            if ( totbyte == finfo[0][NODE].size ) break;
            c=szBuf[i];
            putc ( c, nfp );
            i++;
            totbyte++;
            finfo[0][NODE].bRecv = totbyte;
        }
        if ( totbyte == finfo[0][NODE].size ) break;
    }

    // Close Sockets to end Transfer
    closesocks();

    // Break out of GUI!
    erbreak[0][NODE] = true;

    // close file
    fclose ( nfp );

    // End of File Transfer is Reached Here if Successful!
    char fRecv[50]= {0};             // Bytes Received [Buffer]
    char fLeft[50]= {0};             // Bytes Left     [Buffer]
    char tLeft[50]= {0};             // Time Left
    long lftbyte=0;                  // Bytes Left Total

    // If Current Node is Toggled ON, Display End Transfer Stats For This Node
    if ( nstate == NODE )
    {
        // Get True File Size for End of Transfer
        checksize();
        // Draw GUI File Bytes Received / Left Information
        sprintf ( fRecv,"%.f ", ( float ) finfo[0][NODE].flsz ); // Display True Total
        lftbyte = ( finfo[0][NODE].size - finfo[0][NODE].flsz );	// Should always be 0!
        if ( lftbyte < 0 )
        {
            lftbyte = 0;
        }
        sprintf ( fLeft,"%.f ", ( float ) lftbyte );       // Display True Left

        // Draw Time & Transfer Status
        sprintf ( tLeft,"00:00:00 " );
        sprintf ( message,"Successful! " );
        strcpy ( finfo[0][NODE].status,message );
        logntp ( message, NODE );

#ifdef _WIN32
        percenttop ( 100 );
        drawpercent ( 100 );
        drawreceived ( fRecv,9,7 );
        drawleft ( fLeft,9,7 );
        drawtleft ( tLeft,15,7 );
        drawstatus ( message,15,7 );
#else
        printf ( "\n%s\n",message );
        printf ( "\nTime Left  : %s\n",tLeft );
#endif
    }

    // Copy File Stats to finfo2 for Message Window
    memcpy ( &finfo2[0][NODE],&finfo[0][NODE],sizeof ( FILEINFO ) );

    // Give 2 Second Delay for Stats to show!
#ifdef _WIN32
    Sleep ( 2000 );
#else
    sleep ( 2 );
#endif

}


#ifdef _WIN32
void DLNodeTransfer ( void *p )
{
#else
void *DLNodeTransfer ( void *p )
{
#endif

    //PASSING *pass = (PASSING*) p;
    NTPSRV *ntpsrv = ( NTPSRV* ) p;
    char message[255];

    // Set Node to Active for Connection
    finfo[0][ntpsrv->NODE].InUse = true;
    // Set GUI Error Break to False
    erbreak[0][ntpsrv->NODE] = false;

    // Get File Info
    if ( !ntpsrv->recvfinfo() )
    {
        sprintf ( message,"Error Getting FileInfo.. ." );
        ntpsrv->logntp ( message, ntpsrv->NODE );
        // end of Transfer Reset Node
        finfo[0][ntpsrv->NODE].InUse = false;
#ifdef _WIN32
        return;
#else
        return NULL;
#endif
    }

    // Check for Resume
    int i = ntpsrv->resume();
    if ( i == 2 ) // Error
    {
        sprintf ( message,"Error Getting Resume Info.. ." );
        ntpsrv->logntp ( message, ntpsrv->NODE );
        // end of Transfer Reset Node
        finfo[0][ntpsrv->NODE].InUse = false;
#ifdef _WIN32
        return;
#else
        return NULL;
#endif
    }
    else if ( i == 0 )
    {
        finfo[0][ntpsrv->NODE].resum = false;
    }
    else
    {
        finfo[0][ntpsrv->NODE].resum = true;
    }

    refreshbar();  // Refreshing Node Lightbar to Reflect Connection

    // receive file data & Start GUI Thread
    ntpsrv->recvfdata();

    // end of Transfer Reset Node to Inactive
    finfo[0][ntpsrv->NODE].InUse = false;

    refreshbar();  // Refreshing Node Lightbar to Reflect Connection
}


void StreamServer ( short nPort, SOCKET l1 )
{

    char message[255];
    NTPSRV ntpsrv;

    memset ( &finfo,0,sizeof ( finfo ) );
    memset ( &finfo2,0,sizeof ( finfo2 ) );

    // Set Default Node States
    finfo[0][0].InUse = false;
    finfo[0][ClientsConnected].InUse = false;

    // Get Handle to Incomming Connections
    SOCKET listenSocket = l1;

    // Setup for Incomming connections
    SOCKET remoteSocket;
    int sin_size;
    sin_size = sizeof ( struct sockaddr_in );

    struct sockaddr_in their_addr;

    // Main Program Loops on Incomming Connections
    for ( ;; )
    {

        // Clears the struct to recevie information from the user
        memset ( &their_addr,0,sizeof ( their_addr ) );

#ifdef _WIN32
        remoteSocket = accept ( listenSocket,
                                ( struct sockaddr * ) &their_addr,
                                &sin_size );
#else
        remoteSocket = accept ( listenSocket,
                                ( struct sockaddr * ) &their_addr,
                                ( socklen_t * ) &sin_size );
#endif
        if ( remoteSocket == INVALID_SOCKET )
        {
            sprintf ( message,"Error: accept() - Incomming Connection!" );
            //ntpsrv.logntp(message);
            return;
        }

        NodeGUI ( PORT );

        // Loop through nodes to find node not in use for next connection
        ClientsConnected = 1;
        while ( finfo[0][ClientsConnected].InUse )
        {
            if ( ClientsConnected > 5 ) ClientsConnected = 1;
            else ClientsConnected++;
#ifdef _WIN32
            Sleep ( 1000 );
#else
            sleep ( 1 );
#endif
        }
        ntpsrv.NODE = ClientsConnected;

        // Call Destructor to make sure everything is clean before starting
        memset ( &finfo[0][ClientsConnected],0,sizeof ( FILEINFO ) );
        ntpsrv.NODE = ClientsConnected; // just in case.. test later if needed

        // Set Node to Flase untill file Data is confirmed
        finfo[0][ntpsrv.NODE].InUse = true;

        // Asign Remote Connections IP Address
        finfo[0][ntpsrv.NODE].their_addr = their_addr;

        // Fill Socket Struct on Completed Connection
        ntpsrv.msock.rsock = remoteSocket;
        ntpsrv.msock.lsock = listenSocket;

        // Kick off Node Transfer Thread Here
#ifdef _WIN32
        HANDLE ahThread;
        ahThread = ( HANDLE ) _beginthread ( DLNodeTransfer, 0, ( void* ) &ntpsrv );
#else
        pthread_t thread;
        pthread_create ( &thread, NULL, DLNodeTransfer, ( void* ) ntpsrv );
#endif

    } // End of For Loop
}


void StartServer ( short nPort )
{

    NTPSRV ntpsrv;
    char message[255];

    // Create a TCP/IP stream socket to "listen" with
    SOCKET	listenSocket;

    listenSocket = socket ( AF_INET,			// Address family
                            SOCK_STREAM,		// Socket type
                            IPPROTO_TCP );		// Protocol

    if ( listenSocket == INVALID_SOCKET )
    {
        sprintf ( message,"Error: ListenSocket!" );
        ntpsrv.logntp ( message, 1 );
#ifdef _WIN32
        WSACleanup();
#endif
        exit ( 1 );
    }

    // Fill in the address structure
#ifdef _WIN32
    SOCKADDR_IN saServer;
#else
    struct sockaddr_in saServer;
#endif

    saServer.sin_family = AF_INET;
    saServer.sin_addr.s_addr = INADDR_ANY;	// Let WinSock supply address
    saServer.sin_port = htons ( nPort );		// Use port from command line
#ifndef _WIN32
    memset ( & ( saServer.sin_zero ), '\0', 8 );
#endif

    char szBuf[2048];
    int nRet;

#ifdef _WIN32
    // bind the name to the socket
    nRet = bind ( listenSocket,				// Socket
                  ( LPSOCKADDR ) &saServer,		// Our address
                  sizeof ( struct sockaddr ) );	// Size of address structure
#else
    // bind the name to the socket
    nRet = bind ( listenSocket,
                  ( struct sockaddr * ) &saServer,
                  sizeof ( saServer ) );
#endif
    if ( nRet == INVALID_SOCKET )
    {
        sprintf ( message,"Error: bind() ListenSocket!" );
        ntpsrv.logntp ( message, 1 );
#ifdef _WIN32
        closesocket ( listenSocket );
        WSACleanup();
#else
        close ( listenSocket );
#endif
        exit ( 1 );
    }

#ifdef _WIN32
    nRet = gethostname ( szBuf, sizeof ( szBuf ) );
    if ( nRet == INVALID_SOCKET )
    {
        sprintf ( message,"Error: gethostname()" );
        ntpsrv.logntp ( message, 1 );
#ifdef _WIN32
        closesocket ( listenSocket );
        WSACleanup();
#else
        close ( listenSocket );
#endif
        exit ( 1 );
    }
#endif

#ifdef _WIN32
    // Set the socket to listen
    nRet = listen ( listenSocket, 5 );
#else
    nRet = listen ( listenSocket, 5 );
#endif
    if ( nRet == INVALID_SOCKET )
    {
        sprintf ( message,"Error: listen() - For Connection!" );
        ntpsrv.logntp ( message, 1 );
#ifdef _WIN32
        closesocket ( listenSocket );
        WSACleanup();
#else
        close ( listenSocket );
#endif
        exit ( 1 );
    }

    /*
    //Start Node GUI
    #ifdef _WIN32
    HANDLE ahThread;
    ahThread = (HANDLE)_beginthread( NodeGUI, 0, (void*)&nPort);
    #else
    pthread_t thread;
    pthread_create(&thread, NULL, NodeGUI, (void*)nPort);
    #endif
    */

    NodeGUI ( nPort );

    // Main Program Loop Here after Winsock Init
    while ( 1 )
    {
        StreamServer ( nPort, listenSocket );
    }
}
コード例 #11
0
ファイル: frequantizer.cpp プロジェクト: tsob/frequantizer
	virtual void compute (
                        int count,
                        FAUSTFLOAT** input,
                        FAUSTFLOAT** output
                       )
	{
		checksize(count); //check ctrl block & FFT buffer sizes behave

		//linear amplitude factor from dB volume input variable
		float fSlow0 = (
		    0.0010000000000000009f * powf(10,(0.05f * fslider0))
		);

		//mute (really "on") button
		float fSlow1 = fcheckbox0;

		// incoming audio for this ctrl block
		FAUSTFLOAT* input0  = input[0];

		// outgoing audio for this ctrl block
		FAUSTFLOAT* output0 = output[0];


		//Queue up this control block of input samples for the various
		//FFTs...
		for (i = 0; i < count; i++){
		      insig0[i+fftcountin[0]] = input0[i];
		      insig1[i+fftcountin[1]] = input0[i];
		      insig2[i+fftcountin[2]] = input0[i];
		      insig3[i+fftcountin[3]] = input0[i];
		      insig4[i+fftcountin[4]] = input0[i];
		      insig5[i+fftcountin[5]] = input0[i];
		}
		for (i = 0; i < numwindows; i++) fftcountin[i] += count;

		//check/perform the fft/quantization/iffts for the various
		//fft sizes...


		if (fftcountin[0] == n[0])
		{
		      for (i = 0; i < n[0]; i++) in0[i] = insig0[i];
		      sinewindow(in0, n[0]); //window input
		      fftw_execute(pf0);  //forward transform

		      // quantize fft values
		      bits = (int) fslider1; //bit depth from GUI
		      for(i=0; i<nc[0]; i++){
			fftout0[i][0] = quantize(bits, fftout0[i][0], (int) n[0]/2.0);
			fftout0[i][1] = quantize(bits, fftout0[i][1], (int) n[0]/2.0);
		      }

		      fftw_execute(pb0); // backward transform

		      // scale by n after inverse tranform
		      for(i=0; i<n[0]; i++) out0[i] /= n[0];

		      sinewindow(out0, n[0]); //window output

		      //overlap-and-add
		      for (i = 0; i < halfn[0]; i++){
			outsig0[fftcountout[0]+i] = fmin(
			    1.0, fmax(-1.0, out0[i] + halfframe0[i])
			);
			insig0[i]     = insig0[i + halfn[0]];
			halfframe0[i] = out0[i + halfn[0]];
		      }

		      fftcountin[0]  -= halfn[0];
		      fftcountout[0] += halfn[0];
		}

		if (fftcountin[1] == n[1])
		{
		      for (i = 0; i < n[1]; i++) in1[i] = insig1[i];
		      sinewindow(in1, n[1]); //window input
		      fftw_execute(pf1);  //forward transform

		      // quantize fft values
		      bits = (int) fslider1; //bit depth from GUI
		      for(i=0; i<nc[1]; i++){
			fftout1[i][0] = quantize(bits, fftout1[i][0], (int) n[1]/2.0);
			fftout1[i][1] = quantize(bits, fftout1[i][1], (int) n[1]/2.0);
		      }

		      fftw_execute(pb1); // backward transform

		      // scale by n after inverse tranform
		      for(i=0; i<n[1]; i++) out1[i] /= n[1];

		      sinewindow(out1, n[1]); //window output

		      //overlap-and-add
		      for (i = 0; i < halfn[1]; i++){
			outsig1[fftcountout[1]+i] = fmin(
			    1.0, fmax(-1.0, out1[i] + halfframe1[i])
			);
			insig1[i]     = insig1[i + halfn[1]];
			halfframe1[i] = out1[i + halfn[1]];
		      }

		      fftcountin[1]  -= halfn[1];
		      fftcountout[1] += halfn[1];
		}

		if (fftcountin[2] == n[2]) //perform the fft/quantization/ifft
		{
		      for (i = 0; i < n[2]; i++) in2[i] = insig2[i];
		      sinewindow(in2, n[2]); //window input
		      fftw_execute(pf2);  //forward transform

		      // quantize fft values
		      bits = (int) fslider1; //bit depth from GUI
		      for(i=0; i<nc[2]; i++){
			fftout2[i][0] = quantize(bits, fftout2[i][0], (int) n[2]/2.0);
			fftout2[i][1] = quantize(bits, fftout2[i][1], (int) n[2]/2.0);
		      }

		      fftw_execute(pb2); // backward transform

		      // scale by n after inverse tranform
		      for(i=0; i<n[2]; i++) out2[i] /= n[2];

		      sinewindow(out2, n[2]); //window output

		      //overlap-and-add
		      for (i = 0; i < halfn[2]; i++){
			outsig2[fftcountout[2]+i] = fmin(
			    1.0, fmax(-1.0, out2[i] + halfframe2[i])
			);
			insig2[i]     = insig2[i + halfn[2]];
			halfframe2[i] = out2[i + halfn[2]];
		      }

		      fftcountin[2]  -= halfn[2];
		      fftcountout[2] += halfn[2];
		}

		if (fftcountin[3] == n[3]) //perform the fft/quantization/ifft
		{
		      for (i = 0; i < n[3]; i++) in3[i] = insig3[i];
		      sinewindow(in3, n[3]); //window input
		      fftw_execute(pf3);  //forward transform

		      // quantize fft values
		      bits = (int) fslider1; //bit depth from GUI
		      for(i=0; i<nc[3]; i++){
			fftout3[i][0] = quantize(bits, fftout3[i][0], (int) n[3]/2.0);
			fftout3[i][1] = quantize(bits, fftout3[i][1], (int) n[3]/2.0);
		      }

		      fftw_execute(pb3); // backward transform

		      // scale by n after inverse tranform
		      for(i=0; i<n[3]; i++) out3[i] /= n[3];

		      sinewindow(out3, n[3]); //window output

		      //overlap-and-add
		      for (i = 0; i < halfn[3]; i++){
			outsig3[fftcountout[3]+i] = fmin(
			    1.0, fmax(-1.0, out3[i] + halfframe3[i])
			);
			insig3[i]     = insig3[i + halfn[3]];
			halfframe3[i] = out3[i + halfn[3]];
		      }

		      fftcountin[3]  -= halfn[3];
		      fftcountout[3] += halfn[3];
		}

		if (fftcountin[4] == n[4]) //perform the fft/quantization/ifft
		{
		      for (i = 0; i < n[4]; i++) in4[i] = insig4[i];
		      sinewindow(in4, n[4]); //window input
		      fftw_execute(pf4);  //forward transform

		      // quantize fft values
		      bits = (int) fslider1; //bit depth from GUI
		      for(i=0; i<nc[4]; i++){
			fftout4[i][0] = quantize(bits, fftout4[i][0], (int) n[4]/2.0);
			fftout4[i][1] = quantize(bits, fftout4[i][1], (int) n[4]/2.0);
		      }

		      fftw_execute(pb4); // backward transform

		      // scale by n after inverse tranform
		      for(i=0; i<n[4]; i++) out4[i] /= n[4];

		      sinewindow(out4, n[4]); //window output

		      //overlap-and-add
		      for (i = 0; i < halfn[4]; i++){
			outsig4[fftcountout[4]+i] = fmin(
			    1.0, fmax(-1.0, out4[i] + halfframe4[i])
			);
			insig4[i]     = insig4[i + halfn[4]];
			halfframe4[i] = out4[i + halfn[4]];
		      }

		      fftcountin[4]  -= halfn[4];
		      fftcountout[4] += halfn[4];
		}

		if (fftcountin[5] == n[5]) //perform the fft/quantization/ifft
		{
		      for (i = 0; i < n[5]; i++) in5[i] = insig5[i];
		      sinewindow(in5, n[5]); //window input
		      fftw_execute(pf5);  //forward transform

		      // quantize fft values
		      bits = (int) fslider1; //bit depth from GUI
		      for(i=0; i<nc[5]; i++){
			fftout5[i][0] = quantize(bits, fftout5[i][0], (int) n[5]/2.0);
			fftout5[i][1] = quantize(bits, fftout5[i][1], (int) n[5]/2.0);
		      }

		      fftw_execute(pb5); // backward transform

		      // scale by n after inverse tranform
		      for(i=0; i<n[5]; i++) out5[i] /= n[5];

		      sinewindow(out5, n[5]); //window output

		      //overlap-and-add
		      for (i = 0; i < halfn[5]; i++){
			outsig5[fftcountout[5]+i] = fmin(
			    1.0, fmax(-1.0, out5[i] + halfframe5[i])
			);
			insig5[i]     = insig5[i + halfn[5]];
			halfframe5[i] = out5[i + halfn[5]];
		      }

		      fftcountin[5]  -= halfn[5];
		      fftcountout[5] += halfn[5];
		}


		//--------------
		// combine into count-segmented audio streams for each fft
		for (i = 0; i < count; ++i) output0[i] = (FAUSTFLOAT) 0.0;
		for (i = 0; i < numwindows; i++) //for crossfading
		{
		    fftamount[i] = max(1.0 - fabs(11.0+i-fslider2),0.0);
		}
		if (fftcountout[0]>0){
		      for (i = 0; i < count; ++i){
			  output0[i] += (FAUSTFLOAT)(outsig0[i] * fftamount[0]);
		      }
		      for (i = 0; i<(fftcountout[0]-count); i++){
			  outsig0[i] = outsig0[i + count];
		      }
		      fftcountout[0] -= count;
		}
		if (fftcountout[1]>0){
		      for (i = 0; i < count; ++i){
			  output0[i] += (FAUSTFLOAT)(outsig1[i] * fftamount[1]);
		      }
		      for (i = 0; i<(fftcountout[1]-count); i++){
			  outsig1[i] = outsig1[i + count];
		      }
		      fftcountout[1] -= count;
		}
		if (fftcountout[2]>0){
		      for (i = 0; i < count; ++i){
			  output0[i] += (FAUSTFLOAT)(outsig2[i] * fftamount[2]);
		      }
		      for (i = 0; i<(fftcountout[2]-count); i++){
			  outsig2[i] = outsig2[i + count];
		      }
		      fftcountout[2] -= count;
		}
		if (fftcountout[3]>0){
		      for (i = 0; i < count; ++i){
			  output0[i] += (FAUSTFLOAT)(outsig3[i] * fftamount[3]);
		      }
		      for (i = 0; i<(fftcountout[3]-count); i++){
			  outsig3[i] = outsig3[i + count];
		      }
		      fftcountout[3] -= count;
		}
		if (fftcountout[4]>0){
		      for (i = 0; i < count; ++i){
			  output0[i] += (FAUSTFLOAT)(outsig4[i] * fftamount[4]);
		      }
		      for (i = 0; i<(fftcountout[4]-count); i++){
			  outsig4[i] = outsig4[i + count];
		      }
		      fftcountout[4] -= count;
		}
		if (fftcountout[5]>0){
		      for (i = 0; i < count; ++i){
			  output0[i] += (FAUSTFLOAT)(outsig5[i] * fftamount[5]);
		      }
		      for (i = 0; i<(fftcountout[5]-count); i++){
			  outsig5[i] = outsig5[i + count];
		      }
		      fftcountout[5] -= count;
		}

		//-------------------------------------------------------------
		//Volume and mute
		for (int i=0; i<count; i++) {
			output0[i] = (FAUSTFLOAT)(fSlow1 * ((float)output0[i] * fSlow0));
		}
	}
コード例 #12
0
ファイル: TextAnalyse.cpp プロジェクト: monokura/csharp
//次の文字列を取得
bool TextAnalyse::getstr( char *buf, bool nomove )
{
	int i, j;
	char *temp;

	next();
	temp = pos;
	if( pos >= last ) return false;

	//最初の文字が " かどうかで処理を分岐
	if( pos[0] == '\"' )
	{
		// " があるところまでコピー
		pos++;
		for( j = 0, i = 0; pos + i < last && pos[i] != '\"'; )
		{
			if( checksize( pos + i ) == 2 )
			{
				buf[j  ] = pos[i  ];
				buf[j+1] = pos[i+1];
				i += 2;
				j += 2;
			}
			else
			{
				//¥の後に”がある場合は”を文字列の一部としてみなす
				if( pos + i + 1 < last && pos[i] == '\\' && pos[i+1] == '\"' )
				{
					buf[j] = '\"';
					j++;
					i += 2;
				}
				else
				//改行、タブは無視する
				if( pos[i] != '\r' && pos[i] != '\n' && pos[i] != '\t' )
				{
					buf[j] = pos[i];
					j++;
					i++;
				}
				else
				{
					i++;
				}
			}
		}
		buf[j] = '\0';
		pos += i;
		if( *pos == '\"' ) pos++;
	}
	else
	{
		//意味が無い文字があるところまでコピー
		for( i = 0; pos + i < last && checkC( pos[i] ) == true; )
		{
			if( checksize( pos + i ) == 2 )
			{
				buf[i  ] = pos[i  ];
				buf[i+1] = pos[i+1];
				i += 2;
			}
			else
			{
				buf[i] = pos[i];
				i ++;
			}
		}
		buf[i] = '\0';
		pos += i;
	}

	if( nomove ) pos = temp;

	return true;
}
コード例 #13
0
ファイル: sana2.cpp プロジェクト: sunfirefox/WinUAE
static int dev_do_io_2 (struct s2devstruct *dev, uaecptr request, int quick)
{
	uae_u8 flags = get_byte (request + 30);
	uae_u32 command = get_word (request + 28);
	uae_u32 packettype = get_long (request + 32 + 4);
	uaecptr data = get_long (request + 32 + 4 + 4 + SANA2_MAX_ADDR_BYTES * 2 + 4);
	uae_u32 datalength = get_long (request + 32 + 4 + 4 + SANA2_MAX_ADDR_BYTES * 2);
	uaecptr srcaddr = request + 32 + 4 + 4;
	uaecptr dstaddr = request + 32 + 4 + 4 + SANA2_MAX_ADDR_BYTES;
	uaecptr statdata = get_long (request + 32 + 4 + 4 + SANA2_MAX_ADDR_BYTES * 2 + 4 + 4);
	uaecptr buffermgmt = get_long (request + 32 + 4 + 4 + SANA2_MAX_ADDR_BYTES * 2 + 4 + 4 + 4);
	uae_u32 io_error = 0;
	uae_u32 wire_error = 0;
	int i;
	int async = 0;
	struct priv_s2devstruct *pdev = getps2devstruct (request);

	if (log_net)
		write_log (_T("S2: C=%02d T=%04X S=%02X%02X%02X%02X%02X%02X D=%02X%02X%02X%02X%02X%02X L=%d D=%08X SD=%08X BM=%08X\n"),
		command, packettype,
		get_byte (srcaddr + 0), get_byte (srcaddr + 1), get_byte (srcaddr + 2), get_byte (srcaddr + 3), get_byte (srcaddr + 4), get_byte (srcaddr + 5),
		get_byte (dstaddr + 0), get_byte (dstaddr + 1), get_byte (dstaddr + 2), get_byte (dstaddr + 3), get_byte (dstaddr + 4), get_byte (dstaddr + 5), 
		datalength, data, statdata, buffermgmt);

	if (command == CMD_READ || command == S2_READORPHAN || command == CMD_WRITE || command == S2_BROADCAST || command == S2_MULTICAST) {
		if (!pdev->copyfrombuff || !pdev->copytobuff) {
			io_error = S2ERR_BAD_ARGUMENT;
			wire_error = S2WERR_BUFF_ERROR;
			goto end;
		}
	}

	switch (command)
	{
	case CMD_READ:
		if (!dev->online)
			goto offline;
		async = 1;
		break;

	case S2_READORPHAN:
		if (!dev->online)
			goto offline;
		async = 1;
		break;

	case S2_BROADCAST:
	case CMD_WRITE:
		if (!dev->online)
			goto offline;
		if (!checksize (request, dev))
			goto toobig;
		async = 1;
		break;

	case S2_MULTICAST:
		if (!dev->online)
			goto offline;
		if ((get_byte (dstaddr + 0) & 1) == 0) {
			io_error = S2ERR_BAD_ADDRESS;
			wire_error = S2WERR_BAD_MULTICAST;
			goto end;
		}
		if (!checksize (request, dev))
			goto toobig;
		async = 1;
		break;

	case CMD_FLUSH:
		dev->flush_timeout_cnt = 0;
		dev->flush_timeout = FLUSH_TIMEOUT;
		if (log_net)
			write_log (_T("CMD_FLUSH started %08x\n"), request);
		uae_sem_wait (&async_sem);
		flush (pdev);
		uae_sem_post (&async_sem);
		async = 1;
		uaenet_vsync_requested++;
		break;

	case S2_ADDMULTICASTADDRESS:
		addmulticastaddresses (dev, amigaaddrto64 (srcaddr), 0);
		break;
	case S2_DELMULTICASTADDRESS:
		if (!delmulticastaddresses (dev, amigaaddrto64 (srcaddr), 0)) {
			io_error = S2ERR_BAD_STATE;
			wire_error = S2WERR_BAD_MULTICAST;
		}
		break;
	case S2_ADDMULTICASTADDRESSES:
		addmulticastaddresses (dev, amigaaddrto64 (srcaddr), amigaaddrto64 (dstaddr));
		break;
	case S2_DELMULTICASTADDRESSES:
		if (!delmulticastaddresses (dev, amigaaddrto64 (srcaddr), amigaaddrto64 (dstaddr))) {
			io_error = S2ERR_BAD_STATE;
			wire_error = S2WERR_BAD_MULTICAST;
		}
		break;

	case S2_DEVICEQUERY:
		{
			int size = get_long (statdata);
			if (size > 30)
				size = 30;
			put_long (statdata + 4, size);
			if (size >= 12)
				put_long (statdata + 8, 0);
			if (size >= 16)
				put_long (statdata + 12, 0);
			if (size >= 18)
				put_word (statdata + 16, ADDR_SIZE * 8);
			if (size >= 22)
				put_long (statdata + 18, dev->td->mtu);
			if (size >= 26)
				put_long (statdata + 22, 10000000);
			if (size >= 30)
				put_long (statdata + 26, S2WireType_Ethernet);
		}
		break;

	case S2_GETTYPESTATS:
		if (pdev->trackcnt) {
			put_long (statdata + 0, pdev->packetssent);
			put_long (statdata + 4, pdev->packetsreceived);
			put_long (statdata + 8, pdev->bytessent);
			put_long (statdata + 12, pdev->bytesreceived);
			put_long (statdata + 16, pdev->packetsdropped);
		} else {
			io_error = S2ERR_BAD_STATE;
			wire_error = S2WERR_NOT_TRACKED;
		}
		break;

	case S2_GETGLOBALSTATS:
		put_long (statdata + 0, dev->packetsreceived);
		put_long (statdata + 4, dev->packetssent);
		put_long (statdata + 8, dev->baddata);
		put_long (statdata + 12, dev->overruns);
		put_long (statdata + 16, 0);
		put_long (statdata + 20, dev->unknowntypesreceived);
		put_long (statdata + 24, dev->reconfigurations);
		put_long (statdata + 28, dev->online_secs);
		put_long (statdata + 32, dev->online_micro);
		break;

	case S2_GETSPECIALSTATS:
		put_long (statdata + 1, 0);
		break;

	case S2_GETSTATIONADDRESS:
		for (i = 0; i < ADDR_SIZE; i++) {
			put_byte (srcaddr + i, dev->td->mac[i]);
			put_byte (dstaddr + i, dev->td->mac[i]);
		}
		break;

	case S2_CONFIGINTERFACE:
		if (dev->configured) {
			io_error = S2ERR_BAD_STATE;
			wire_error = S2WERR_IS_CONFIGURED;
		} else {
			dev->configured = TRUE;
		}
		break;

	case S2_ONLINE:
		if (!dev->configured) {
			io_error = S2ERR_BAD_STATE;
			wire_error = S2WERR_NOT_CONFIGURED;
		}
		if (!dev->adapter) {
			io_error = S2ERR_OUTOFSERVICE;
			wire_error = S2WERR_RCVREL_HDW_ERR;
		}
		if (!io_error) {
			uaenet_vsync_requested++;
			async = 1;
		}
		break;

	case S2_TRACKTYPE:
		if (packettype <= 65535) {
			if (pdev->tracks[packettype]) {
				io_error = S2ERR_BAD_STATE;
				wire_error = S2WERR_ALREADY_TRACKED;
			} else {
				pdev->tracks[packettype] = 1;
				pdev->trackcnt++;
			}
		} else {
			io_error = S2ERR_BAD_ARGUMENT;
		}
		break;
	case S2_UNTRACKTYPE:
		if (packettype <= 65535) {
			if (!pdev->tracks[packettype]) {
				io_error = S2ERR_BAD_STATE;
				wire_error = S2WERR_NOT_TRACKED;
			} else {
				pdev->tracks[packettype] = 0;
				pdev->trackcnt--;
			}
		} else {
			io_error = S2ERR_BAD_ARGUMENT;
		}
		break;

	case S2_OFFLINE:
		if (dev->online) {
			dev->online = 0;
			checkevents (dev, S2EVENT_OFFLINE, 1);
		}
		break;

	case S2_ONEVENT:
		{
			uae_u32 events;
			uae_u32 wanted_events = get_long (request + 32);
			if (wanted_events & ~KNOWN_EVENTS) {
				io_error = S2ERR_NOT_SUPPORTED;
				events = S2WERR_BAD_EVENT;
			} else {
				if (dev->online)
					events = S2EVENT_ONLINE;
				else
					events = S2EVENT_OFFLINE;
				events &= wanted_events;
				if (events) {
					wire_error = events;
				} else {
					async = 1;
				}
			}
		}
		break;

	default:
		io_error = IOERR_NOCMD;
		break;

offline:
		io_error = S2ERR_OUTOFSERVICE;
		wire_error = S2WERR_UNIT_OFFLINE;
		break;
toobig:
		io_error = S2ERR_MTU_EXCEEDED;
		wire_error = S2WERR_GENERIC_ERROR;
		break;

	}
end:
	if (log_net && (io_error || wire_error))
		write_log (_T("-> %d (%d)\n"), io_error, wire_error);
	put_long (request + 32, wire_error);
	put_byte (request + 31, io_error);
	return async;
}