Remove most tabs in nbase. This probably needs some fixes, but the tabs really confused my vim.

This commit is contained in:
d33tah 2013-08-09 00:16:52 +00:00
parent 627dbb2848
commit b2187f6749
12 changed files with 444 additions and 444 deletions

View file

@ -175,7 +175,7 @@ char* WSAAPI gai_strerrorA (int errcode)
#ifndef HAVE_GETADDRINFO
void freeaddrinfo(struct addrinfo *res) {
struct addrinfo *next;
do {
next = res->ai_next;
free(res);
@ -186,70 +186,70 @@ void freeaddrinfo(struct addrinfo *res) {
address specified in network byte order */
static struct addrinfo *new_ai(unsigned short portno, u32 addr)
{
struct addrinfo *ai;
struct addrinfo *ai;
ai = (struct addrinfo *) safe_malloc(sizeof(struct addrinfo) + sizeof(struct sockaddr_in));
memset(ai, 0, sizeof(struct addrinfo) + sizeof(struct sockaddr_in));
ai->ai_family = AF_INET;
ai->ai_addrlen = sizeof(struct sockaddr_in);
ai->ai_addr = (struct sockaddr *)(ai + 1);
ai->ai_addr->sa_family = AF_INET;
ai = (struct addrinfo *) safe_malloc(sizeof(struct addrinfo) + sizeof(struct sockaddr_in));
memset(ai, 0, sizeof(struct addrinfo) + sizeof(struct sockaddr_in));
ai->ai_family = AF_INET;
ai->ai_addrlen = sizeof(struct sockaddr_in);
ai->ai_addr = (struct sockaddr *)(ai + 1);
ai->ai_addr->sa_family = AF_INET;
#if HAVE_SOCKADDR_SA_LEN
ai->ai_addr->sa_len = ai->ai_addrlen;
ai->ai_addr->sa_len = ai->ai_addrlen;
#endif
((struct sockaddr_in *)(ai)->ai_addr)->sin_port = portno;
((struct sockaddr_in *)(ai)->ai_addr)->sin_addr.s_addr = addr;
return(ai);
((struct sockaddr_in *)(ai)->ai_addr)->sin_port = portno;
((struct sockaddr_in *)(ai)->ai_addr)->sin_addr.s_addr = addr;
return(ai);
}
int getaddrinfo(const char *node, const char *service,
const struct addrinfo *hints, struct addrinfo **res) {
int getaddrinfo(const char *node, const char *service,
const struct addrinfo *hints, struct addrinfo **res) {
struct addrinfo *cur, *prev = NULL;
struct hostent *he;
struct in_addr ip;
unsigned short portno;
int i;
if (service)
portno = htons(atoi(service));
else
portno = 0;
if (hints && hints->ai_flags & AI_PASSIVE) {
*res = new_ai(portno, htonl(0x00000000));
return 0;
}
if (!node) {
*res = new_ai(portno, htonl(0x7f000001));
return 0;
}
if (inet_pton(AF_INET, node, &ip)) {
*res = new_ai(portno, ip.s_addr);
return 0;
}
he = gethostbyname(node);
if (he && he->h_addr_list[0]) {
for (i = 0; he->h_addr_list[i]; i++) {
cur = new_ai(portno, ((struct in_addr *)he->h_addr_list[i])->s_addr);
if (prev)
prev->ai_next = cur;
prev->ai_next = cur;
else
*res = cur;
*res = cur;
prev = cur;
}
return 0;
}
return EAI_NODATA;
}
#endif /* HAVE_GETADDRINFO */

View file

@ -142,35 +142,35 @@
#endif
int getnameinfo(const struct sockaddr *sa, size_t salen,
char *host, size_t hostlen,
char *serv, size_t servlen, int flags) {
char *host, size_t hostlen,
char *serv, size_t servlen, int flags) {
struct sockaddr_in *sin = (struct sockaddr_in *)sa;
struct hostent *he;
if (sin->sin_family != AF_INET || salen != sizeof(struct sockaddr_in))
return EAI_FAMILY;
if (serv != NULL) {
Snprintf(serv, servlen, "%d", ntohs(sin->sin_port));
return 0;
}
if (host) {
if (flags & NI_NUMERICHOST) {
if (flags & NI_NUMERICHOST) {
Strncpy(host, inet_ntoa(sin->sin_addr), hostlen);
return 0;
} else {
he = gethostbyaddr((char *)&sin->sin_addr, sizeof(struct in_addr),
AF_INET);
if (he == NULL) {
if (flags & NI_NAMEREQD)
return EAI_NONAME;
Strncpy(host, inet_ntoa(sin->sin_addr), hostlen);
return 0;
he = gethostbyaddr((char *)&sin->sin_addr, sizeof(struct in_addr),
AF_INET);
if (he == NULL) {
if (flags & NI_NAMEREQD)
return EAI_NONAME;
Strncpy(host, inet_ntoa(sin->sin_addr), hostlen);
return 0;
}
assert(he->h_name);
Strncpy(host, he->h_name, hostlen);
return 0;

View file

@ -14,7 +14,7 @@
* SOFTWARE.
*/
/* Modified by Fyodor (fyodor@nmap.org) for inclusion in the Nmap
/* Modified by Fyodor (fyodor@nmap.org) for inclusion in the Nmap
* Security Scanner.
*
* $Id$
@ -64,81 +64,81 @@ static const char *inet_ntop6(const unsigned char *src, char *dst, size_t size);
/* char *
* inet_ntop(af, src, dst, size)
* convert a network format address to presentation format.
* convert a network format address to presentation format.
* return:
* pointer to presentation format address (`dst'), or NULL (see errno).
* pointer to presentation format address (`dst'), or NULL (see errno).
* author:
* Paul Vixie, 1996.
* Paul Vixie, 1996.
*/
const char *
inet_ntop(int af, const void *src, char *dst, size_t size)
{
switch (af) {
case AF_INET:
return (inet_ntop4((const unsigned char *) src, dst, size));
switch (af) {
case AF_INET:
return (inet_ntop4((const unsigned char *) src, dst, size));
#if HAVE_IPV6
case AF_INET6:
return (inet_ntop6((const unsigned char *) src, dst, size));
case AF_INET6:
return (inet_ntop6((const unsigned char *) src, dst, size));
#endif
default:
default:
#ifndef WIN32
errno = EAFNOSUPPORT;
errno = EAFNOSUPPORT;
#endif
return (NULL);
}
/* NOTREACHED */
return (NULL);
}
/* NOTREACHED */
}
/* const char *
* inet_ntop4(src, dst, size)
* format an IPv4 address, more or less like inet_ntoa()
* format an IPv4 address, more or less like inet_ntoa()
* return:
* `dst' (as a const)
* `dst' (as a const)
* notes:
* (1) uses no statics
* (2) takes a u_char* not an in_addr as input
* (1) uses no statics
* (2) takes a u_char* not an in_addr as input
* author:
* Paul Vixie, 1996.
* Paul Vixie, 1996.
*/
static const char *
inet_ntop4(const unsigned char *src, char *dst, size_t size)
{
const size_t MIN_SIZE = 16; /* space for 255.255.255.255\0 */
int n = 0;
char *next = dst;
const size_t MIN_SIZE = 16; /* space for 255.255.255.255\0 */
int n = 0;
char *next = dst;
if (size < MIN_SIZE) {
if (size < MIN_SIZE) {
#ifndef WIN32
errno = ENOSPC;
errno = ENOSPC;
#endif
return NULL;
}
do {
unsigned char u = *src++;
if (u > 99) {
*next++ = '0' + u/100;
u %= 100;
*next++ = '0' + u/10;
u %= 10;
}
else if (u > 9) {
*next++ = '0' + u/10;
u %= 10;
}
*next++ = '0' + u;
*next++ = '.';
n++;
} while (n < 4);
*--next = 0;
return dst;
return NULL;
}
do {
unsigned char u = *src++;
if (u > 99) {
*next++ = '0' + u/100;
u %= 100;
*next++ = '0' + u/10;
u %= 10;
}
else if (u > 9) {
*next++ = '0' + u/10;
u %= 10;
}
*next++ = '0' + u;
*next++ = '.';
n++;
} while (n < 4);
*--next = 0;
return dst;
}
#if HAVE_IPV6
/* const char *
* inet_ntop6(src, dst, size)
* convert IPv6 binary address into presentation (printable) format
* convert IPv6 binary address into presentation (printable) format
* author:
* Paul Vixie, 1996.
* Paul Vixie, 1996.
*/
static const char *
inet_ntop6(const unsigned char *src, char *dst, size_t size)
@ -159,8 +159,8 @@ inet_ntop6(const unsigned char *src, char *dst, size_t size)
/*
* Preprocess:
* Copy the input (bytewise) array into a wordwise array.
* Find the longest run of 0x00's in src[] for :: shorthanding.
* Copy the input (bytewise) array into a wordwise array.
* Find the longest run of 0x00's in src[] for :: shorthanding.
*/
next_src = src;
src_end = src + IN6ADDRSZ;

View file

@ -14,7 +14,7 @@
* SOFTWARE.
*/
/* Modified by Fyodor (fyodor@nmap.org) for inclusion in the Nmap
/* Modified by Fyodor (fyodor@nmap.org) for inclusion in the Nmap
* Security Scanner.
*
* $Id$
@ -62,184 +62,184 @@
* sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX.
*/
static int inet_pton4 (const char *src, unsigned char *dst);
static int inet_pton4 (const char *src, unsigned char *dst);
#if HAVE_IPV6
static int inet_pton6 (const char *src, unsigned char *dst);
static int inet_pton6 (const char *src, unsigned char *dst);
#endif
/* int
* inet_pton(af, src, dst)
* convert from presentation format (which usually means ASCII printable)
* to network format (which is usually some kind of binary format).
* convert from presentation format (which usually means ASCII printable)
* to network format (which is usually some kind of binary format).
* return:
* 1 if the address was valid for the specified address family
* 0 if the address wasn't valid (`dst' is untouched in this case)
* -1 if some other error occurred (`dst' is untouched in this case, too)
* 1 if the address was valid for the specified address family
* 0 if the address wasn't valid (`dst' is untouched in this case)
* -1 if some other error occurred (`dst' is untouched in this case, too)
* author:
* Paul Vixie, 1996.
* Paul Vixie, 1996.
*/
int
inet_pton(int af, const char *src, void *dst)
{
switch (af) {
case AF_INET:
return (inet_pton4(src, (unsigned char *) dst));
switch (af) {
case AF_INET:
return (inet_pton4(src, (unsigned char *) dst));
#if HAVE_IPV6
case AF_INET6:
return (inet_pton6(src, (unsigned char *) dst));
case AF_INET6:
return (inet_pton6(src, (unsigned char *) dst));
#endif
default:
default:
#ifndef WIN32
errno = EAFNOSUPPORT;
errno = EAFNOSUPPORT;
#endif
return (-1);
}
/* NOTREACHED */
return (-1);
}
/* NOTREACHED */
}
/* int
* inet_pton4(src, dst)
* like inet_aton() but without all the hexadecimal and shorthand.
* like inet_aton() but without all the hexadecimal and shorthand.
* return:
* 1 if `src' is a valid dotted quad, else 0.
* 1 if `src' is a valid dotted quad, else 0.
* notice:
* does not touch `dst' unless it's returning 1.
* does not touch `dst' unless it's returning 1.
* author:
* Paul Vixie, 1996.
* Paul Vixie, 1996.
*/
static int
inet_pton4(const char *src, unsigned char *dst)
{
static const char digits[] = "0123456789";
int saw_digit, octets, ch;
unsigned char tmp[INADDRSZ], *tp;
static const char digits[] = "0123456789";
int saw_digit, octets, ch;
unsigned char tmp[INADDRSZ], *tp;
saw_digit = 0;
octets = 0;
*(tp = tmp) = 0;
while ((ch = *src++) != '\0') {
const char *pch;
saw_digit = 0;
octets = 0;
*(tp = tmp) = 0;
while ((ch = *src++) != '\0') {
const char *pch;
if ((pch = strchr(digits, ch)) != NULL) {
unsigned int newval = (unsigned int) (*tp * 10 + (pch - digits));
if ((pch = strchr(digits, ch)) != NULL) {
unsigned int newval = (unsigned int) (*tp * 10 + (pch - digits));
if (newval > 255)
return (0);
*tp = newval;
if (! saw_digit) {
if (++octets > 4)
return (0);
saw_digit = 1;
}
} else if (ch == '.' && saw_digit) {
if (octets == 4)
return (0);
*++tp = 0;
saw_digit = 0;
} else
return (0);
}
if (octets < 4)
return (0);
if (newval > 255)
return (0);
*tp = newval;
if (! saw_digit) {
if (++octets > 4)
return (0);
saw_digit = 1;
}
} else if (ch == '.' && saw_digit) {
if (octets == 4)
return (0);
*++tp = 0;
saw_digit = 0;
} else
return (0);
}
if (octets < 4)
return (0);
memcpy(dst, tmp, INADDRSZ);
return (1);
memcpy(dst, tmp, INADDRSZ);
return (1);
}
#if HAVE_IPV6
/* int
* inet_pton6(src, dst)
* convert presentation level address to network order binary form.
* convert presentation level address to network order binary form.
* return:
* 1 if `src' is a valid [RFC1884 2.2] address, else 0.
* 1 if `src' is a valid [RFC1884 2.2] address, else 0.
* notice:
* (1) does not touch `dst' unless it's returning 1.
* (2) :: in a full address is silently ignored.
* (1) does not touch `dst' unless it's returning 1.
* (2) :: in a full address is silently ignored.
* credit:
* inspired by Mark Andrews.
* inspired by Mark Andrews.
* author:
* Paul Vixie, 1996.
* Paul Vixie, 1996.
*/
static int
inet_pton6(const char *src, unsigned char *dst)
{
static const char xdigits_l[] = "0123456789abcdef",
xdigits_u[] = "0123456789ABCDEF";
unsigned char tmp[IN6ADDRSZ], *tp, *endp, *colonp;
const char *xdigits, *curtok;
int ch, saw_xdigit;
unsigned int val;
static const char xdigits_l[] = "0123456789abcdef",
xdigits_u[] = "0123456789ABCDEF";
unsigned char tmp[IN6ADDRSZ], *tp, *endp, *colonp;
const char *xdigits, *curtok;
int ch, saw_xdigit;
unsigned int val;
memset((tp = tmp), '\0', IN6ADDRSZ);
endp = tp + IN6ADDRSZ;
colonp = NULL;
/* Leading :: requires some special handling. */
if (*src == ':')
if (*++src != ':')
return (0);
curtok = src;
saw_xdigit = 0;
val = 0;
while ((ch = *src++) != '\0') {
const char *pch;
memset((tp = tmp), '\0', IN6ADDRSZ);
endp = tp + IN6ADDRSZ;
colonp = NULL;
/* Leading :: requires some special handling. */
if (*src == ':')
if (*++src != ':')
return (0);
curtok = src;
saw_xdigit = 0;
val = 0;
while ((ch = *src++) != '\0') {
const char *pch;
if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
pch = strchr((xdigits = xdigits_u), ch);
if (pch != NULL) {
val <<= 4;
val |= (pch - xdigits);
if (val > 0xffff)
return (0);
saw_xdigit = 1;
continue;
}
if (ch == ':') {
curtok = src;
if (!saw_xdigit) {
if (colonp)
return (0);
colonp = tp;
continue;
}
if (tp + INT16SZ > endp)
return (0);
*tp++ = (unsigned char) (val >> 8) & 0xff;
*tp++ = (unsigned char) val & 0xff;
saw_xdigit = 0;
val = 0;
continue;
}
if (ch == '.' && ((tp + INADDRSZ) <= endp) &&
inet_pton4(curtok, tp) > 0) {
tp += INADDRSZ;
saw_xdigit = 0;
break; /* '\0' was seen by inet_pton4(). */
}
return (0);
}
if (saw_xdigit) {
if (tp + INT16SZ > endp)
return (0);
*tp++ = (unsigned char) (val >> 8) & 0xff;
*tp++ = (unsigned char) val & 0xff;
}
if (colonp != NULL) {
/*
* Since some memmove()'s erroneously fail to handle
* overlapping regions, we'll do the shift by hand.
*/
const int n = tp - colonp;
int i;
if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
pch = strchr((xdigits = xdigits_u), ch);
if (pch != NULL) {
val <<= 4;
val |= (pch - xdigits);
if (val > 0xffff)
return (0);
saw_xdigit = 1;
continue;
}
if (ch == ':') {
curtok = src;
if (!saw_xdigit) {
if (colonp)
return (0);
colonp = tp;
continue;
}
if (tp + INT16SZ > endp)
return (0);
*tp++ = (unsigned char) (val >> 8) & 0xff;
*tp++ = (unsigned char) val & 0xff;
saw_xdigit = 0;
val = 0;
continue;
}
if (ch == '.' && ((tp + INADDRSZ) <= endp) &&
inet_pton4(curtok, tp) > 0) {
tp += INADDRSZ;
saw_xdigit = 0;
break; /* '\0' was seen by inet_pton4(). */
}
return (0);
}
if (saw_xdigit) {
if (tp + INT16SZ > endp)
return (0);
*tp++ = (unsigned char) (val >> 8) & 0xff;
*tp++ = (unsigned char) val & 0xff;
}
if (colonp != NULL) {
/*
* Since some memmove()'s erroneously fail to handle
* overlapping regions, we'll do the shift by hand.
*/
const int n = tp - colonp;
int i;
for (i = 1; i <= n; i++) {
endp[- i] = colonp[n - i];
colonp[n - i] = 0;
}
tp = endp;
}
if (tp != endp)
return (0);
memcpy(dst, tmp, IN6ADDRSZ);
return (1);
for (i = 1; i <= n; i++) {
endp[- i] = colonp[n - i];
colonp[n - i] = 0;
}
tp = endp;
}
if (tp != endp)
return (0);
memcpy(dst, tmp, IN6ADDRSZ);
return (1);
}
#endif

View file

@ -137,8 +137,8 @@
* * 'inline' is defined to what is neccessary for the C compiler being
* used (which may be nothing)
*
* * snprintf, inet_pton, memcpy, and bzero are
* provided if you don't have them (prototypes for these are
* * snprintf, inet_pton, memcpy, and bzero are
* provided if you don't have them (prototypes for these are
* included either way).
*
* * WORDS_BIGENDIAN is defined if platform is big endian
@ -149,7 +149,7 @@
*
* * Insures that getopt_* functions exist (such as getopt_long_only)
*
* * Various string functions such as Strncpy() and strcasestr() see protos
* * Various string functions such as Strncpy() and strcasestr() see protos
* for more info.
*
* * IPv6 structures like 'sockaddr_storage' are provided if they do
@ -198,7 +198,7 @@
#endif
#if HAVE_NETDB_H
#include <netdb.h>
#include <netdb.h>
#endif
#if HAVE_INTTYPES_H
@ -242,7 +242,7 @@ typedef int64_t s64;
#define MIN(x,y) (((x)<(y))?(x):(y))
#endif
#ifndef ABS
#define ABS(x) (((x) >= 0)?(x):-(x))
#define ABS(x) (((x) >= 0)?(x):-(x))
#endif
/* Timeval subtraction in microseconds */
@ -501,7 +501,7 @@ char *path_get_dirname(const char *path);
char *path_get_basename(const char *path);
/* A few simple wrappers for the most common memory allocation routines which will exit() if the
allocation fails, so you don't always have to check -- see nbase_memalloc.c */
allocation fails, so you don't always have to check -- see nbase_memalloc.c */
void *safe_malloc(size_t size);
void *safe_realloc(void *ptr, size_t size);
/* Zero-initializing version of safe_malloc */

View file

@ -179,13 +179,13 @@ const char *inet_ntop(int af, const void *src, char *dst, size_t size);
#ifndef HAVE_SOCKADDR_STORAGE
/* Just needs to be big enough to hold sockaddr_in or
sockaddr_in6. I should really align it at 64 bits, but 32 is
probably fine as hosts that actually want to store a
sockaddr_in6 in here should already have this defined (see
RFC2355). */
sockaddr_in6. I should really align it at 64 bits, but 32 is
probably fine as hosts that actually want to store a
sockaddr_in6 in here should already have this defined (see
RFC2355). */
struct sockaddr_storage {
u32 padding[32];
};
u32 padding[32];
};
#endif /* SOCKADDR_STORAGE */
/* Compares two sockaddr_storage structures with a return value like strcmp.
@ -240,8 +240,8 @@ const char *inet_ntop_ez(const struct sockaddr_storage *ss, size_t sslen);
struct sockaddr;
int getnameinfo(const struct sockaddr *sa, size_t salen,
char *host, size_t hostlen,
char *serv, size_t servlen, int flags);
char *host, size_t hostlen,
char *serv, size_t servlen, int flags);
#endif /* !HAVE_GETNAMEINFO */
#if !HAVE_GETADDRINFO
@ -266,8 +266,8 @@ struct addrinfo {
#endif
void freeaddrinfo(struct addrinfo *res);
int getaddrinfo(const char *node, const char *service,
const struct addrinfo *hints, struct addrinfo **res);
int getaddrinfo(const char *node, const char *service,
const struct addrinfo *hints, struct addrinfo **res);
#endif /* !HAVE_GETADDRINFO */

View file

@ -158,9 +158,9 @@ extern int errno;
equivalents. So you can use EMSGSIZE or EINTR. */
int socket_errno() {
#ifdef WIN32
return WSAGetLastError();
return WSAGetLastError();
#else
return errno;
return errno;
#endif
}
@ -171,16 +171,16 @@ int socket_errno() {
*/
char *socket_strerror(int errnum) {
#ifdef WIN32
static char buffer[128];
static char buffer[128];
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS |
FORMAT_MESSAGE_MAX_WIDTH_MASK,
0, errnum, 0, buffer, sizeof(buffer), NULL);
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS |
FORMAT_MESSAGE_MAX_WIDTH_MASK,
0, errnum, 0, buffer, sizeof(buffer), NULL);
return buffer;
return buffer;
#else
return strerror(errnum);
return strerror(errnum);
#endif
}
@ -238,13 +238,13 @@ const char *inet_ntop_ez(const struct sockaddr_storage *ss, size_t sslen) {
if (sslen < sizeof(struct sockaddr_in))
return NULL;
return inet_ntop(AF_INET, &sin->sin_addr, str, sizeof(str));
}
}
#if HAVE_IPV6
else if(sin->sin_family == AF_INET6) {
if (sslen < sizeof(struct sockaddr_in6))
return NULL;
return inet_ntop(AF_INET6, &sin6->sin6_addr, str, sizeof(str));
}
}
#endif
//Some laptops report the ip and address family of disabled wifi cards as null
//so yes, we will hit this sometimes.
@ -684,9 +684,9 @@ unsigned long nbase_adler32(unsigned char *buf, int len)
* buffer. It uses current locale to determine if a character is printable or
* not. It prints 73char+\n wide lines like these:
0000 e8 60 65 86 d7 86 6d 30 35 97 54 87 ff 67 05 9e .`e...m05.T..g..
0010 07 5a 98 c0 ea ad 50 d2 62 4f 7b ff e1 34 f8 fc .Z....P.bO{..4..
0020 c4 84 0a 6a 39 ad 3c 10 63 b2 22 c4 24 40 f4 b1 ...j9.<.c.".$@..
0000 e8 60 65 86 d7 86 6d 30 35 97 54 87 ff 67 05 9e .`e...m05.T..g..
0010 07 5a 98 c0 ea ad 50 d2 62 4f 7b ff e1 34 f8 fc .Z....P.bO{..4..
0020 c4 84 0a 6a 39 ad 3c 10 63 b2 22 c4 24 40 f4 b1 ...j9.<.c.".$@..
* The lines look basically like Wireshark's hex dump.
* WARNING: This function returns a pointer to a DYNAMICALLY allocated buffer
@ -735,20 +735,20 @@ char *hexdump(const u8 *cp, u32 length){
line2print[4]=' '; /* Replace the '\0' inserted by snprintf() with a space */
hex=HEX_START; asc=ASC_START;
do { /* Print 16 bytes in both hex and ascii */
if (i%16 == 8) hex++; /* Insert space every 8 bytes */
if (i%16 == 8) hex++; /* Insert space every 8 bytes */
snprintf(printbyte, sizeof(printbyte), "%02x", cp[i]);/* First print the hex number */
line2print[hex++]=printbyte[0];
line2print[hex++]=printbyte[1];
line2print[hex++]=' ';
line2print[asc++]=asciify[ cp[i] ]; /* Then print its ASCII equivalent */
i++;
} while (i < length && i%16 != 0);
i++;
} while (i < length && i%16 != 0);
/* Copy line to output buffer */
line2print[LINE_LEN-1]='\n';
memcpy(current_line, line2print, LINE_LEN);
current_line += LINE_LEN;
}
buffer[bytes2alloc-1]='\0';
buffer[bytes2alloc-1]='\0';
return buffer;
} /* End of hexdump() */
@ -789,7 +789,7 @@ int optcmp(const char *a, const char *b) {
while(*a && *b) {
if (*a == '_' || *a == '-') {
if (*b != '_' && *b != '-')
return 1;
return 1;
}
else if (*a != *b)
return 1;
@ -804,18 +804,18 @@ int optcmp(const char *a, const char *b) {
* is readable by the executing process. Returns two if it is readable
* and is a directory. Otherwise returns 0. */
int file_is_readable(const char *pathname) {
char *pathname_buf = strdup(pathname);
int status = 0;
struct stat st;
char *pathname_buf = strdup(pathname);
int status = 0;
struct stat st;
#ifdef WIN32
// stat on windows only works for "dir_name" not for "dir_name/" or "dir_name\\"
int pathname_len = strlen(pathname_buf);
char last_char = pathname_buf[pathname_len - 1];
// stat on windows only works for "dir_name" not for "dir_name/" or "dir_name\\"
int pathname_len = strlen(pathname_buf);
char last_char = pathname_buf[pathname_len - 1];
if( last_char == '/'
|| last_char == '\\')
pathname_buf[pathname_len - 1] = '\0';
if( last_char == '/'
|| last_char == '\\')
pathname_buf[pathname_len - 1] = '\0';
#endif

View file

@ -145,17 +145,17 @@
/* data for our random state */
struct nrand_handle {
u8 i, j, s[256], *tmp;
int tmplen;
u8 i, j, s[256], *tmp;
int tmplen;
};
typedef struct nrand_handle nrand_h;
static void nrand_addrandom(nrand_h *rand, u8 *buf, int len) {
int i;
u8 si;
/* Mix entropy in buf with s[]...
*
*
* This is the ARC4 key-schedule. It is rather poor and doesn't mix
* the key in very well. This causes a bias at the start of the stream.
* To eliminate most of this bias, the first N bytes of the stream should
@ -174,7 +174,7 @@ static void nrand_addrandom(nrand_h *rand, u8 *buf, int len) {
static u8 nrand_getbyte(nrand_h *r) {
u8 si, sj;
/* This is the core of ARC4 and provides the pseudo-randomness */
r->i = (r->i + 1);
si = r->s[r->i];
@ -245,7 +245,7 @@ void nrand_init(nrand_h *r) {
int get_random_bytes(void *buf, int numbytes) {
static nrand_h state;
static int state_init = 0;
/* Initialize if we need to */
if (!state_init) {
nrand_init(&state);
@ -303,7 +303,7 @@ unsigned short get_random_ushort() {
/* This function is magic ;-)
*
*
* Sometimes Nmap wants to generate IPs that look random
* but don't have any duplicates. The strong RC4 generator
* can't be used for this purpose because it can generate duplicates
@ -321,7 +321,7 @@ u32 get_random_unique_u32() {
static u32 state, tweak1, tweak2, tweak3;
static int state_init = 0;
u32 output;
/* Initialize if we need to */
if (!state_init) {
get_random_bytes(&state, sizeof(state));
@ -389,7 +389,7 @@ u32 get_random_unique_u32() {
* duplicates.
*/
state = (((state * 1664525) & 0xFFFFFFFF) + 1013904223) & 0xFFFFFFFF;
output = state;
/* With a normal LCG, we would just output the state.

View file

@ -137,12 +137,12 @@
#ifndef HAVE_USLEEP
void usleep(unsigned long usec) {
#ifdef HAVE_NANOSLEEP
struct timespec ts;
ts.tv_sec = usec / 1000000;
ts.tv_nsec = (usec % 1000000) * 1000;
struct timespec ts;
ts.tv_sec = usec / 1000000;
ts.tv_nsec = (usec % 1000000) * 1000;
nanosleep(&ts, NULL);
#else /* Windows style */
Sleep( usec / 1000 );
Sleep( usec / 1000 );
#endif /* HAVE_NANOSLEEP */
}
#endif
@ -150,19 +150,19 @@ nanosleep(&ts, NULL);
#ifdef WIN32
int gettimeofday(struct timeval *tv, struct timeval *tz)
{
struct _timeb timebuffer;
struct _timeb timebuffer;
_ftime( &timebuffer );
_ftime( &timebuffer );
tv->tv_sec = (long) timebuffer.time;
tv->tv_usec = timebuffer.millitm * 1000;
return 0;
tv->tv_sec = (long) timebuffer.time;
tv->tv_usec = timebuffer.millitm * 1000;
return 0;
};
unsigned int sleep(unsigned int seconds)
{
Sleep(1000*seconds);
return(0);
Sleep(1000*seconds);
return(0);
};
#endif /* WIN32 */

View file

@ -130,7 +130,7 @@
//This disables the warning 4800 http://msdn.microsoft.com/en-us/library/b6801kcy(v=vs.71).aspx
#pragma warning(disable : 4800)
/* It doesn't really have struct IP, but we use a different one instead
of the one that comes with Nmap */
of the one that comes with Nmap */
#define HAVE_STRUCT_IP 1
/* #define HAVE_STRUCT_ICMP 1 */
#define HAVE_STRNCASECMP 1
@ -185,7 +185,7 @@ typedef signed __int64 int64_t;
#define _CRT_SECURE_NO_DEPRECATE 1
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS 1
#endif
#endif
#pragma warning(disable: 4996)
#ifdef __GNUC__

View file

@ -8,22 +8,22 @@
* Copyright (c) 1995-1999 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@ -148,8 +148,8 @@ as_append_char (struct state *state, unsigned char c)
static int
append_number(struct state *state,
unsigned long num, unsigned base, char *rep,
int width, int prec, int flags, int minusp)
unsigned long num, unsigned base, char *rep,
int width, int prec, int flags, int minusp)
{
int len = 0;
int i;
@ -185,7 +185,7 @@ append_number(struct state *state,
width--;
while(width-- > 0){
if((*state->append_char)(state, '0'))
return 1;
return 1;
len++;
}
}
@ -193,7 +193,7 @@ append_number(struct state *state,
if(flags & alternate_flag && (base == 16 || base == 8)){
if(base == 16)
if((*state->append_char)(state, rep[10] + 23)) /* XXX */
return 1;
return 1;
if((*state->append_char)(state, '0'))
return 1;
}
@ -231,16 +231,16 @@ append_number(struct state *state,
state->s[-i-1] = state->s[-len+i];
state->s[-len+i] = c;
}
return 0;
}
static int
append_string (struct state *state,
unsigned char *arg,
int width,
int prec,
int flags)
unsigned char *arg,
int width,
int prec,
int flags)
{
if(prec != -1)
width -= prec;
@ -249,39 +249,39 @@ append_string (struct state *state,
if(!(flags & minus_flag))
while(width-- > 0)
if((*state->append_char) (state, ' '))
return 1;
return 1;
if (prec != -1) {
while (*arg && prec--)
if ((*state->append_char) (state, *arg++))
return 1;
return 1;
} else {
while (*arg)
if ((*state->append_char) (state, *arg++))
return 1;
return 1;
}
if(flags & minus_flag)
while(width-- > 0)
if((*state->append_char) (state, ' '))
return 1;
return 1;
return 0;
}
static int
append_char(struct state *state,
unsigned char arg,
int width,
int flags)
unsigned char arg,
int width,
int flags)
{
while(!(flags & minus_flag) && --width > 0)
if((*state->append_char) (state, ' '))
return 1;
if((*state->append_char) (state, arg))
return 1;
while((flags & minus_flag) && --width > 0)
if((*state->append_char) (state, ' '))
return 1;
return 0;
}
@ -317,163 +317,163 @@ xyzprintf (struct state *state, const char *char_format, va_list ap)
/* flags */
while((c = *format++)){
if(c == '-')
flags |= minus_flag;
else if(c == '+')
flags |= plus_flag;
else if(c == ' ')
flags |= space_flag;
else if(c == '#')
flags |= alternate_flag;
else if(c == '0')
flags |= zero_flag;
else
break;
if(c == '-')
flags |= minus_flag;
else if(c == '+')
flags |= plus_flag;
else if(c == ' ')
flags |= space_flag;
else if(c == '#')
flags |= alternate_flag;
else if(c == '0')
flags |= zero_flag;
else
break;
}
if((flags & space_flag) && (flags & plus_flag))
flags ^= space_flag;
flags ^= space_flag;
if((flags & minus_flag) && (flags & zero_flag))
flags ^= zero_flag;
flags ^= zero_flag;
/* width */
if (isdigit((int) c))
do {
width = width * 10 + c - '0';
c = *format++;
} while(isdigit((int) c));
do {
width = width * 10 + c - '0';
c = *format++;
} while(isdigit((int) c));
else if(c == '*') {
width = va_arg(ap, int);
c = *format++;
width = va_arg(ap, int);
c = *format++;
}
/* precision */
if (c == '.') {
prec = 0;
c = *format++;
if (isdigit((int) c))
do {
prec = prec * 10 + c - '0';
c = *format++;
} while(isdigit((int) c));
else if (c == '*') {
prec = va_arg(ap, int);
c = *format++;
}
prec = 0;
c = *format++;
if (isdigit((int) c))
do {
prec = prec * 10 + c - '0';
c = *format++;
} while(isdigit((int) c));
else if (c == '*') {
prec = va_arg(ap, int);
c = *format++;
}
}
/* size */
if (c == 'h') {
short_flag = 1;
c = *format++;
short_flag = 1;
c = *format++;
} else if (c == 'l') {
long_flag = 1;
c = *format++;
long_flag = 1;
c = *format++;
}
switch (c) {
case 'c' :
if(append_char(state, va_arg(ap, int), width, flags))
return -1;
break;
if(append_char(state, va_arg(ap, int), width, flags))
return -1;
break;
case 's' :
if (append_string(state,
va_arg(ap, unsigned char*),
width,
prec,
flags))
return -1;
break;
if (append_string(state,
va_arg(ap, unsigned char*),
width,
prec,
flags))
return -1;
break;
case 'd' :
case 'i' : {
long arg;
unsigned long num;
int minusp = 0;
long arg;
unsigned long num;
int minusp = 0;
PARSE_INT_FORMAT(arg, ap, signed);
PARSE_INT_FORMAT(arg, ap, signed);
if (arg < 0) {
minusp = 1;
num = -arg;
} else
num = arg;
if (arg < 0) {
minusp = 1;
num = -arg;
} else
num = arg;
if (append_number (state, num, 10, "0123456789",
width, prec, flags, minusp))
return -1;
break;
if (append_number (state, num, 10, "0123456789",
width, prec, flags, minusp))
return -1;
break;
}
case 'u' : {
unsigned long arg;
unsigned long arg;
PARSE_INT_FORMAT(arg, ap, unsigned);
PARSE_INT_FORMAT(arg, ap, unsigned);
if (append_number (state, arg, 10, "0123456789",
width, prec, flags, 0))
return -1;
break;
if (append_number (state, arg, 10, "0123456789",
width, prec, flags, 0))
return -1;
break;
}
case 'o' : {
unsigned long arg;
unsigned long arg;
PARSE_INT_FORMAT(arg, ap, unsigned);
PARSE_INT_FORMAT(arg, ap, unsigned);
if (append_number (state, arg, 010, "01234567",
width, prec, flags, 0))
return -1;
break;
if (append_number (state, arg, 010, "01234567",
width, prec, flags, 0))
return -1;
break;
}
case 'x' : {
unsigned long arg;
unsigned long arg;
PARSE_INT_FORMAT(arg, ap, unsigned);
PARSE_INT_FORMAT(arg, ap, unsigned);
if (append_number (state, arg, 0x10, "0123456789abcdef",
width, prec, flags, 0))
return -1;
break;
if (append_number (state, arg, 0x10, "0123456789abcdef",
width, prec, flags, 0))
return -1;
break;
}
case 'X' :{
unsigned long arg;
unsigned long arg;
PARSE_INT_FORMAT(arg, ap, unsigned);
PARSE_INT_FORMAT(arg, ap, unsigned);
if (append_number (state, arg, 0x10, "0123456789ABCDEF",
width, prec, flags, 0))
return -1;
break;
if (append_number (state, arg, 0x10, "0123456789ABCDEF",
width, prec, flags, 0))
return -1;
break;
}
case 'p' : {
unsigned long arg = (unsigned long)va_arg(ap, void*);
unsigned long arg = (unsigned long)va_arg(ap, void*);
if (append_number (state, arg, 0x10, "0123456789ABCDEF",
width, prec, flags, 0))
return -1;
break;
if (append_number (state, arg, 0x10, "0123456789ABCDEF",
width, prec, flags, 0))
return -1;
break;
}
case 'n' : {
int *arg = va_arg(ap, int*);
*arg = state->s - state->str;
break;
int *arg = va_arg(ap, int*);
*arg = state->s - state->str;
break;
}
case '\0' :
--format;
/* FALLTHROUGH */
--format;
/* FALLTHROUGH */
case '%' :
if ((*state->append_char)(state, c))
return -1;
break;
if ((*state->append_char)(state, c))
return -1;
break;
default :
if ( (*state->append_char)(state, '%')
|| (*state->append_char)(state, c))
return -1;
break;
if ( (*state->append_char)(state, '%')
|| (*state->append_char)(state, c))
return -1;
break;
}
} else
if ((*state->append_char) (state, c))
return -1;
return -1;
}
return 0;
}

View file

@ -133,46 +133,46 @@
#ifndef HAVE_STRCASECMP
int strcasecmp(const char *s1, const char *s2)
{
int i, ret;
char *cp1, *cp2;
cp1 = safe_malloc(strlen(s1) + 1);
cp2 = safe_malloc(strlen(s2) + 1);
int i, ret;
char *cp1, *cp2;
for (i = 0; i < strlen(s1) + 1; i++)
cp1[i] = tolower((int) (unsigned char) s1[i]);
for (i = 0; i < strlen(s2) + 1; i++)
cp2[i] = tolower((int) (unsigned char) s2[i]);
ret = strcmp(cp1, cp2);
free(cp1);
free(cp2);
cp1 = safe_malloc(strlen(s1) + 1);
cp2 = safe_malloc(strlen(s2) + 1);
return ret;
for (i = 0; i < strlen(s1) + 1; i++)
cp1[i] = tolower((int) (unsigned char) s1[i]);
for (i = 0; i < strlen(s2) + 1; i++)
cp2[i] = tolower((int) (unsigned char) s2[i]);
ret = strcmp(cp1, cp2);
free(cp1);
free(cp2);
return ret;
}
#endif
#ifndef HAVE_STRNCASECMP
int strncasecmp(const char *s1, const char *s2, size_t n)
{
int i, ret;
char *cp1, *cp2;
cp1 = safe_malloc(strlen(s1) + 1);
cp2 = safe_malloc(strlen(s2) + 1);
int i, ret;
char *cp1, *cp2;
for (i = 0; i < strlen(s1) + 1; i++)
cp1[i] = tolower((int) (unsigned char) s1[i]);
for (i = 0; i < strlen(s2) + 1; i++)
cp2[i] = tolower((int) (unsigned char) s2[i]);
ret = strncmp(cp1, cp2, n);
free(cp1);
free(cp2);
cp1 = safe_malloc(strlen(s1) + 1);
cp2 = safe_malloc(strlen(s2) + 1);
return ret;
for (i = 0; i < strlen(s1) + 1; i++)
cp1[i] = tolower((int) (unsigned char) s1[i]);
for (i = 0; i < strlen(s2) + 1; i++)
cp2[i] = tolower((int) (unsigned char) s2[i]);
ret = strncmp(cp1, cp2, n);
free(cp1);
free(cp2);
return ret;
}
#endif