Skip to content

Commit

Permalink
move stringfromipv4 into common.c
Browse files Browse the repository at this point in the history
  • Loading branch information
rofl0r committed Nov 7, 2012
1 parent 8b19829 commit c698d48
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 27 deletions.
24 changes: 24 additions & 0 deletions src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,30 @@
#include <unistd.h>
#include <stdio.h>

// stolen from libulz (C) rofl0r
void pc_stringfromipv4(unsigned char *ip_buf_4_bytes, char *outbuf_16_bytes) {
unsigned char *p;
char *o = outbuf_16_bytes;
unsigned char n;
for(p = ip_buf_4_bytes; p < ip_buf_4_bytes + 4; p++) {
n = *p;
if(*p >= 100) {
if(*p >= 200)
*(o++) = '2';
else
*(o++) = '1';
n %= 100;
}
if(*p >= 10) {
*(o++) = (n / 10) + '0';
n %= 10;
}
*(o++) = n + '0';
*(o++) = '.';
}
o[-1] = 0;
}

static int check_path(char *path) {
if(!path)
return 0;
Expand Down
1 change: 1 addition & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <stddef.h>

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);

//RcB: DEP "common.c"
#endif
24 changes: 0 additions & 24 deletions src/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,6 @@ extern int tcp_connect_time_out;
extern int proxychains_quiet_mode;
extern unsigned int remote_dns_subnet;

// stolen from libulz (C) rofl0r
void pc_stringfromipv4(unsigned char *ip_buf_4_bytes, char *outbuf_16_bytes) {
unsigned char *p;
char *o = outbuf_16_bytes;
unsigned char n;
for(p = ip_buf_4_bytes; p < ip_buf_4_bytes + 4; p++) {
n = *p;
if(*p >= 100) {
if(*p >= 200)
*(o++) = '2';
else
*(o++) = '1';
n %= 100;
}
if(*p >= 10) {
*(o++) = (n / 10) + '0';
n %= 10;
}
*(o++) = n + '0';
*(o++) = '.';
}
o[-1] = 0;
}

static int poll_retry(struct pollfd *fds, nfds_t nfsd, int timeout) {
int ret;
int time_remain = timeout;
Expand Down
2 changes: 0 additions & 2 deletions src/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ int proxy_getaddrinfo(const char *node, const char *service,
const struct addrinfo *hints, struct addrinfo **res);
void proxy_freeaddrinfo(struct addrinfo *res);

void pc_stringfromipv4(unsigned char *ip_buf_4_bytes, char *outbuf_16_bytes);

void core_initialize(void);
void core_unload(void);

Expand Down
2 changes: 1 addition & 1 deletion tests/test_gethostent.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <netdb.h>
#include <stdio.h>
#include "../src/core.h"
#include "../src/common.h"

void printhostent(struct hostent *hp) {
char ipbuf[16];
Expand Down
1 change: 1 addition & 0 deletions tests/test_proxy_gethostbyname.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "../src/core.h"
#include "../src/common.h"
#include <stdio.h>

void printhostent(struct hostent *hp) {
Expand Down

0 comments on commit c698d48

Please sign in to comment.