henesyinit from p9f47575dc5 years agoHistory
39 lines · 531 B · C
RawDownload
#include <u.h>#include <libc.h>#include "ip.h" intparseip(uchar *to, char *from){	int i;	char *p; 	p = from;	memset(to, 0, 4);	for(i = 0; i < 4 && *p; i++){		to[i] = strtoul(p, &p, 0);		if(*p == '.')			p++;	} 	switch(CLASS(to)){	case 0:	/* class A - 1 byte net */	case 1:		if(i == 3){			to[3] = to[2];			to[2] = to[1];			to[1] = 0;		} else if (i == 2){			to[3] = to[1];			to[1] = 0;		}		break;	case 2:	/* class B - 2 byte net */		if(i == 3){			to[3] = to[2];			to[2] = 0;		}		break;	}	return 0;}