Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

goto prevails...

Name: Anonymous 2007-09-14 18:15 ID:exfP63F/

...teh haterz phail.

int valid_ip(const char *ip_addr) {
    int rem;
    size_t dots;
    char ch, *ip_ptr;

    if (!(ip_ptr = (char *) ip_addr)) {
        return 0;
    }

    dots = 0, rem = 3;    __asm {xor ebx, ebx};
    for (; ch = *ip_ptr; ++ip_ptr) {
        __asm push ecx __asm mov ecx, ebx __asm jecxz ECX_WEAK0 __asm dec ecx
        __asm jecxz ECX_WEAK1 __asm dec ecx __asm jecxz ECX_WEAK2 __asm jmp STRONG
        ECX_WEAK0: goto WEAK0; ECX_WEAK1: goto WEAK1; ECX_WEAK2: goto WEAK2;

        STRONG:
        __asm pop ecx
        switch (ch) {
        case '0': case '1':    case '2': case '3':    case '4': case '5': case '6':    case '7': case '8':    case '9': --rem; goto DIGIT_CHECK;
        case '.': ++dots; goto DOT_CHECK;
        default: return 0;
        }

        WEAK0:
        __asm pop ecx
        switch (ch) {
        case '0': case '1':    --rem; __asm {mov ebx, 3}; goto DIGIT_CHECK;
        case '2': --rem; __asm {inc ebx}; goto DIGIT_CHECK;
        case '3': case '4': case '5': case '6': case '7': case '8': case '9': rem -= 2; __asm {mov ebx, 3}; goto DIGIT_CHECK;
        case '.': ++dots; goto DOT_CHECK;
        default: return 0;
        }

        WEAK1:
        __asm pop ecx
        switch (ch) {
        case '0': case '1':    case '2': case '3':    case '4': --rem; __asm {mov ebx, 3}; goto DIGIT_CHECK;
        case '5': --rem; __asm {inc ebx}; goto DIGIT_CHECK;
        case '6': case '7': case '8': case '9': rem = 0; __asm {mov ebx, 3}; goto DIGIT_CHECK;
        case '.': ++dots; goto DOT_CHECK;
        default: return 0;
        }

        WEAK2:
        __asm pop ecx
        switch (ch) {
        case '0': case '1':    case '2': case '3':    case '4': case '5': --rem; __asm {mov ebx, 3}; goto DIGIT_CHECK;
        case '.': ++dots; goto DOT_CHECK;
        default: return 0;
        }

        DIGIT_CHECK: if (rem < 0) {return 0;} else {continue;}
        DOT_CHECK: if (rem == 3 || dots > 3) {return 0;} else {rem = 3; __asm {xor ebx, ebx}; continue;}
    }

    return (rem != 3 && dots == 3) ? 1 : 0;
}

Name: Anonymous 2007-09-17 13:34 ID:Heaven

lrn2{3}

Name: Anonymous 2007-09-17 13:41 ID:Heaven

inet_addr(ip) != -1

Name: Anonymous 2007-09-17 15:58 ID:6JABiyR0

>>38
Then you phail. The function decent programmers would use to check ips uses multiplication, and this method runs 5.5 secs or faster for 10 million function calls. The state method which only checks, but uses no multiplication and runs in 3.4 secs or faster for 10 million function calls. The array method is a combination of the state method and its co-occurring conversion of the string to an array. This method never takes more than 4.0 secs per 10 million calls. Additionally, the multiplication method is fairly steady with how much time it takes whereas both the state and array versions can see significant improvements on different inputs, and this is quite common in fact.

32.437 seconds to see if it is valid and you don't even have the array converted. Truly sad.

Name: Anonymous 2007-09-17 16:01 ID:Heaven

>>42
Doesn't work for 255.255.255.255

Name: Anonymous 2007-09-17 17:02 ID:0ojmGquM

int valid_ipv4( const char * ip )
{
    uint32_t address   = 0;
    uint8_t  dot_count = 0;

    for( ; *ip; ip++ )
    {  
        if ( *ip >= '0'
          && *ip <= '9' )
        {
            address = ~(~address|0xFF) + ((address&0xFF)*10) + (*ip - '0');
        }
        else if ( * ip == '.' )
        {
            address <<= 8;
            dot_count++;
        }
    }  

    return dot_count == 4 && address <= 4294967295uL;
}

Name: Anonymous 2007-09-17 17:03 ID:Heaven

Oops, forgot to return 0 on invalid chars.

Name: Anonymous 2007-09-17 17:39 ID:lD0ddHF+

>>45
Overuse of explicitly sized types, not using isdigit() where appropriate, not using bitwise and where appropriate, not protecting against overflow and IP's with four dots considered harmful.

According to your function "....", "1239128930128.0129831209380.09480227193.9128103.9120382", and "(260 dots here)" are valid IPv4 adresses.

"address <= 4294967295uL" is always true.

Name: Anonymous 2007-09-17 17:44 ID:Heaven

>>47

I know, I just wanted to use ~(~address|0xFF) + ((address&0xFF)*10)

Name: Anonymous 2007-09-17 18:14 ID:Heaven

The only working good code is >>14's
the rest fail.

Name: Anonymous 2007-09-17 19:41 ID:TTUu4Vdm


'---FUNCTION: IP string -> uinteger and vice versa
function ip2u(what as string) as uinteger
 if what="" then return 0
 return (16777216*val(extractField(".",what,1)))+(65536*val(extractField(".",what,2)))+(256*val(extractField(".",what,3)))+val(extractField(".",what,4))
 end function
function u2ip(numericIP as uinteger) as string
 dim t00 as uinteger,t01 as uinteger,t02 as uinteger,t03 as uinteger
 t00=(numericIP and 4278190080)/(256*256*256)
 t01=(numericIP and 16711680)/(256*256)
 t02=(numericIP and 65280)/256
 t03=(numericIP and 255)
 return mid$(str$(t00),1)+"."+mid$(str$(t01),1)+"."+mid$(str$(t02),1)+"."+mid$(str$(t03),1)
end function

Name: Anonymous 2007-09-17 19:43 ID:TTUu4Vdm


'---FUNCTION: extracts a field from a string, delimited with separator characters
'--- returns chr(4) if field index is more than number of fields in string
function extractField(sepChars as string, fromWhat as string, whichField as integer) as string
 dim l1 as integer,t1 as integer=1
 if whichField<1 then return "[invalid field index]"
 if sepChars="" then
  if whichField=1 then return fromWhat else return chr(4)
  end if
 if fromWhat="" then return ""
 if whichField=1 then
  t1=0:l1=1
 else
  for l1=1 to len(fromWhat)
   if instr(mid$(fromWhat,l1,1),any sepChars)<>0 then t1=t1+1
   if t1=whichField then l1=l1+1:exit for
   next
  end if
 if t1=1 then return chr(4)
 if l1>len(fromWhat) then return ""

 t1=instr(l1,fromWhat,any sepChars)
 if t1=0 then t1=len(fromWhat)+1
 if t1=l1 then return ""

 return mid$(fromWhat,l1,t1-l1)
 end function

Name: Anonymous 2007-09-17 20:47 ID:6JABiyR0

>>49
Sure it will. Once they remove sixes, sevens, eights and nines from IP addresses.

Name: Anonymous 2007-09-17 21:22 ID:Heaven

Just use a good RE compiler.

Name: Anonymous 2007-09-18 7:17 ID:rN94/ALw

Finite State Machine

Name: Anonymous 2007-09-18 9:09 ID:Heaven

>>54
Enjoy your Sipser.

Name: Anonymous 2007-09-18 9:25 ID:54frs8Ah

>>55
Enjoy your sister

Name: Anonymous 2007-09-18 11:30 ID:msefIVlF

int valid_ip(char *ip_addr){
 int n0,n1,n2,n3,c,l;
 c=sscanf(ip_addr,"%d.%d.%d.%d\0",&n0,&n1,&n2,&n3,&l);
 return c<4||l<strlen(ip_addr)||n0<0||n0>255||n1<0||n1>255||n2<0||n2>255||n3<0||n3>255?0:1;
}


or:
/^0*[12]?\d{0,1,2}\,0*[12]?\d{0,1,2}\,0*[12]?\d{0,1,2}\,0*[12]?\d{0,1,2}$/

Name: Anonymous 2007-09-18 11:34 ID:KbHXwcZh

>>54
Internet Hate Machine

Name: Anonymous 2007-09-18 13:44 ID:zrLwgfHN

>>57
Your version runs slower than the Java one. You phail. Massively.

Name: Anonymous 2007-09-18 14:14 ID:Mkr3CpES

>>56
Onii-chan♥♥♥ XD~~~~

Name: Anonymous 2007-09-18 14:51 ID:6ALPpOe+

OH GOD JUST SHUT THE FUCK UP ALL OF YOU, GODDAMN

Name: Anonymous 2007-09-18 16:37 ID:zrLwgfHN

>>61
Phail. Do not collect $200.

goto HELL;

Name: HELL 2007-09-18 21:57 ID:IbzdH18i

fputs("welcome to hell lol", stdout);

Name: Anonymous 2007-09-19 5:04 ID:9EYBPMPB

>>60
Incest-licious!
Incest is the best, put your sister to the test.

Name: Anonymous 2007-09-19 6:29 ID:Heaven

I'd so like to fuck my sister
But I don't have any :(

Name: Anonymous 2007-09-19 9:37 ID:88+6PpNZ

>>64
; put out
put: No such file or directory

Name: Anonymous 2009-03-06 12:41

Piped through a vocoder with 4 completely?

Name: Trollbot9000 2009-07-01 10:45

0xff address 0xFF 10!

Name: Anonymous 2010-12-17 1:34

Are you GAY?
Are you a NIGGER?
Are you a GAY NIGGER?

If you answered "Yes" to all of the above questions, then GNAA (GAY NIGGER ASSOCIATION OF AMERICA) might be exactly what you've been looking for!

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List