various ip scanning fixes

master
leitner 24 years ago
parent 3076acc1f2
commit b3edc1f613

@ -13,7 +13,7 @@ unsigned int scan_ip4(const char *s,char ip[4])
len+=(j=scan_ulong(s,&u))+1; len+=(j=scan_ulong(s,&u))+1;
if (!j) return 0; if (!j) return 0;
ip[i]=u; s+=j; ip[i]=u; s+=j;
if (*s!='.') return 0; ++s; if (i<3 && *s!='.') return 0; ++s;
} }
return len-1; return len-1;
} }

@ -22,6 +22,10 @@ unsigned int scan_ip6(const char *s,char ip[16])
for (i=0; i<16; i++) ip[i]=0; for (i=0; i<16; i++) ip[i]=0;
if ((i=scan_ip4(s,ip+12))) {
for (len=0; len<12; ++len) ip[len]=V4mappedprefix[len];
return i;
}
for (;;) { for (;;) {
if (*s == ':') { if (*s == ':') {
len++; len++;
@ -36,7 +40,7 @@ unsigned int scan_ip6(const char *s,char ip[16])
if (!i) return 0; if (!i) return 0;
if (prefixlen==12 && s[i]=='.') { if (prefixlen==12 && s[i]=='.') {
/* the last 4 bytes may be written as IPv4 address */ /* the last 4 bytes may be written as IPv4 address */
i=ip4_scan(s,ip+12); i=scan_ip4(s,ip+12);
if (i) if (i)
return i+len; return i+len;
else else
@ -64,7 +68,7 @@ unsigned int scan_ip6(const char *s,char ip[16])
break; break;
} }
if (suffixlen+prefixlen<=12 && s[i]=='.') { if (suffixlen+prefixlen<=12 && s[i]=='.') {
int j=ip4_scan(s,suffix+suffixlen); int j=scan_ip4(s,suffix+suffixlen);
if (j) { if (j) {
suffixlen+=4; suffixlen+=4;
len+=j; len+=j;

@ -25,11 +25,7 @@ int socket_mcleave6(int s,const char ip[16])
return socket_mcleave4(s,ip+12); return socket_mcleave4(s,ip+12);
#ifdef LIBC_HAS_IP6 #ifdef LIBC_HAS_IP6
byte_copy(&opt.ipv6mr_multiaddr,16,ip); byte_copy(&opt.ipv6mr_multiaddr,16,ip);
#ifdef __GLIBC__
opt.ipv6mr_interface=0; opt.ipv6mr_interface=0;
#else
opt.ipv6mr_ifindex=0;
#endif
return setsockopt(s,IPPROTO_IPV6,IPV6_DROP_MEMBERSHIP,&opt,sizeof opt); return setsockopt(s,IPPROTO_IPV6,IPV6_DROP_MEMBERSHIP,&opt,sizeof opt);
#else #else
errno=EPROTO; errno=EPROTO;

9
t.c

@ -14,10 +14,19 @@
__asm__ __volatile__ ("rdtsc" : "=a" (low) : : "edx") __asm__ __volatile__ ("rdtsc" : "=a" (low) : : "edx")
int main(int argc,char* argv[]) { int main(int argc,char* argv[]) {
char ip[16];
int i;
if ((i=scan_ip6(argv[1],ip))) {
char buf[128];
buf[fmt_ip6(buf,ip)]=0;
puts(buf);
}
#if 0
char buf[100]; char buf[100];
strcpy(buf,"foobarbaz"); strcpy(buf,"foobarbaz");
buf[fmt_fill(buf,3,5,100)]=0; buf[fmt_fill(buf,3,5,100)]=0;
printf("\"%s\"\n",buf); printf("\"%s\"\n",buf);
#endif
#if 0 #if 0
unsigned long len; unsigned long len;
char *c=mmap_read("/etc/passwd",&len); char *c=mmap_read("/etc/passwd",&len);

Loading…
Cancel
Save