dish/src/dish.cxx
//----------------------------------------------------------------
// This static function will create unsigned integer IP from decimal
// delimeted string.
// ----------------------------------------------------------------
This static function will create unsigned integer IP from decimal
delimeted string.
This static function will create unsigned integer IP from decimal delimeted string .
static unsigned IpFromDecDelim(const char* host) {
    int i,j,k;
    char val[10];
    union {
	struct {
            unsigned char b1;
            unsigned char b2;
            unsigned char b3;
            unsigned char b4;
	} s_unb;
	unsigned long s_ad;
    }conv;
    k=0;
    j=0;
    for(i=0;i<strlen(host);i++) {
        if(host[i]=='.') {
            val[j]=0;
            switch(k) {
            case 0 : conv.s_unb.b1 = atoi(val); break;
            case 1 : conv.s_unb.b2 = atoi(val); break;
            case 2 : conv.s_unb.b3 = atoi(val); break;
            case 3 : conv.s_unb.b4 = atoi(val); break;
            }
            j=0;
            val[j]=0;
            k++;
            continue;
        }
        val[j++]=host[i];
    }
    val[j]=0;
    if(j>0) {
        switch(k) {
        case 0 : conv.s_unb.b1 = atoi(val); break;
        case 1 : conv.s_unb.b2 = atoi(val); break;
        case 2 : conv.s_unb.b3 = atoi(val); break;
        case 3 : conv.s_unb.b4 = atoi(val); break;
        }
    }
    return conv.s_ad;
}
static unsigned IpFromDecDelim ( const char * host ) { int i , j , k ; char val [ 10 ] ; union { struct { unsigned char b1 ; unsigned char b2 ; unsigned char b3 ; unsigned char b4 ; } s_unb ; unsigned long s_ad ; } conv ; k = 0 ; j = 0 ; for ( i = 0 ; i < strlen ( host ) ; i ++ ) { if ( host [ i ] == ' ' ) { val [ j ] = 0 ; switch ( k ) { case 0 : conv . s_unb . b1 = atoi ( val ) ; break ; case 1 : conv . s_unb . b2 = atoi ( val ) ; break ; case 2 : conv . s_unb . b3 = atoi ( val ) ; break ; case 3 : conv . s_unb . b4 = atoi ( val ) ; break ; } j = 0 ; val [ j ] = 0 ; k ++ ; continue ; } val [ j ++ ] = host [ i ] ; } val [ j ] = 0 ; if ( j > 0 ) { switch ( k ) { case 0 : conv . s_unb . b1 = atoi ( val ) ; break ; case 1 : conv . s_unb . b2 = atoi ( val ) ; break ; case 2 : conv . s_unb . b3 = atoi ( val ) ; break ; case 3 : conv . s_unb . b4 = atoi ( val ) ; break ; } } return conv . s_ad ; }
This static function will create unsigned integer IP from decimal
delimeted string.
This static function will create unsigned integer IP from decimal delimeted string .