1
0
mirror of https://github.com/rofl0r/proxychains-ng synced 2025-01-08 06:02:51 +08:00

move isnumericipv4() to common.c

This commit is contained in:
rofl0r 2020-10-28 10:39:27 +00:00
parent 486f8200ad
commit 452830283c
3 changed files with 30 additions and 29 deletions

View File

@ -23,6 +23,33 @@ const char *proxy_state_strmap[] = {
"busy", "busy",
}; };
/* isnumericipv4() taken from libulz */
int pc_isnumericipv4(const char* ipstring) {
size_t x = 0, n = 0, d = 0;
int wasdot = 0;
while(1) {
switch(ipstring[x]) {
case 0: goto done;
case '.':
if(!n || wasdot) return 0;
d++;
wasdot = 1;
break;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
n++;
wasdot = 0;
break;
default:
return 0;
}
x++;
}
done:
if(d == 3 && n >= 4 && n <= 12) return 1;
return 0;
}
// stolen from libulz (C) rofl0r // stolen from libulz (C) rofl0r
void pc_stringfromipv4(unsigned char *ip_buf_4_bytes, char *outbuf_16_bytes) { void pc_stringfromipv4(unsigned char *ip_buf_4_bytes, char *outbuf_16_bytes) {
unsigned char *p; unsigned char *p;

View File

@ -17,6 +17,7 @@ extern const char *proxy_state_strmap[];
char *get_config_path(char* default_path, char* pbuf, size_t bufsize); char *get_config_path(char* default_path, char* pbuf, size_t bufsize);
void pc_stringfromipv4(unsigned char *ip_buf_4_bytes, char *outbuf_16_bytes); void pc_stringfromipv4(unsigned char *ip_buf_4_bytes, char *outbuf_16_bytes);
int pc_isnumericipv4(const char* ipstring);
//RcB: DEP "common.c" //RcB: DEP "common.c"
#endif #endif

View File

@ -1,6 +1,7 @@
#include <stdio.h> #include <stdio.h>
#include <ctype.h> #include <ctype.h>
#include <string.h> #include <string.h>
#include "common.h"
/* /*
simple reader for /etc/hosts simple reader for /etc/hosts
@ -24,7 +25,6 @@ void hostsreader_close(struct hostsreader *ctx) {
fclose(ctx->f); fclose(ctx->f);
} }
static int isnumericipv4(const char* ipstring);
int hostsreader_get(struct hostsreader *ctx, char* buf, size_t bufsize) { int hostsreader_get(struct hostsreader *ctx, char* buf, size_t bufsize) {
while(1) { while(1) {
if(!fgets(buf, bufsize, ctx->f)) return 0; if(!fgets(buf, bufsize, ctx->f)) return 0;
@ -51,7 +51,7 @@ int hostsreader_get(struct hostsreader *ctx, char* buf, size_t bufsize) {
} }
if(!l || !*p) continue; if(!l || !*p) continue;
*p = 0; *p = 0;
if(isnumericipv4(ctx->ip)) return 1; if(pc_isnumericipv4(ctx->ip)) return 1;
} }
} }
@ -94,30 +94,3 @@ int main(int a, char**b) {
printf("%s\n", ret ? ret : "null"); printf("%s\n", ret ? ret : "null");
} }
#endif #endif
/* isnumericipv4() taken from libulz */
static int isnumericipv4(const char* ipstring) {
size_t x = 0, n = 0, d = 0;
int wasdot = 0;
while(1) {
switch(ipstring[x]) {
case 0: goto done;
case '.':
if(!n || wasdot) return 0;
d++;
wasdot = 1;
break;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
n++;
wasdot = 0;
break;
default:
return 0;
}
x++;
}
done:
if(d == 3 && n >= 4 && n <= 12) return 1;
return 0;
}