From 05ef3f431a03c0ec855945b5c04fe43e3c3dfaad Mon Sep 17 00:00:00 2001 From: pfelt Date: Sat, 8 Aug 2009 03:16:33 +0000 Subject: [PATCH] -- fix: make connio compile cleanly. --- include/connio.h | 20 +++-- include/msgapi.h | 2 +- src/libs/connio/CMakeLists.txt | 4 +- src/libs/connio/connio.c | 140 +++++++++++++++++++-------------- src/libs/connio/sockets.c | 134 ++++++++++++------------------- src/libs/connio/unix-ip.c | 85 -------------------- src/libs/msgapi/msgapi.c | 6 +- src/libs/nmap/nmap.c | 7 +- 8 files changed, 155 insertions(+), 243 deletions(-) diff --git a/include/connio.h b/include/connio.h index e5e86c4..c7a006e 100644 --- a/include/connio.h +++ b/include/connio.h @@ -80,8 +80,11 @@ typedef struct { #define SSL_DISABLE_EMPTY_FRAGMENTS (1 << 4) #define SSL_DONT_INSERT_EMPTY_FRAGMENTS (1 << 5) -void CHOP_NEWLINE(unsigned char *s); -void SET_POINTER_TO_VALUE(unsigned char *p, unsigned char *s); // FIXME: Unused? +void CHOP_NEWLINE(char *s); +#if 0 +//TODO: do we need this? +void SET_POINTER_TO_VALUE(unsigned char *p, unsigned char *s); +#endif #if defined (UNIX) || defined(S390RH) || defined(SOLARIS) @@ -138,12 +141,12 @@ typedef struct _ConnSSLConfiguration { struct { long type; - const unsigned char *file; + const char *file; } certificate; struct { long type; - const unsigned char *file; + const char *file; } key; } ConnSSLConfiguration; @@ -227,9 +230,9 @@ typedef struct { #include -void ConnTcpWrite(Connection *c, char *b, size_t l, int *r); -void ConnTcpRead(Connection *c, char *b, size_t l, int *r); -void ConnTcpFlush(Connection *c, const char *b, const char *e, int *r); +int ConnTcpWrite(Connection *c, char *b, size_t l, size_t *r); +int ConnTcpRead(Connection *c, char *b, size_t l, size_t *r); +int ConnTcpFlush(Connection *c, const char *b, const char *e, size_t *r); void ConnTcpClose(Connection *c); void ConnAddressPoolStartup(AddressPool *pool, unsigned long errorThreshold, unsigned long errorTimeThreshold); @@ -304,10 +307,13 @@ BOOL XplIsLocalIPAddress(unsigned long Address); int XplGetInterfaceList(void); int XplDestroyInterfaceList(void); +#if 0 +//TODO: Do we need these? They aren't used anywhere but connmgr */ int XplIPRead(void *sktCtx, unsigned char *Buf, int Len, int socketTimeout); int XplIPReadSSL(void *sktCtx, unsigned char *Buf, int Len, int socketTimeout); int XplIPWrite(void *sktCtx, unsigned char *Buf, int Len); int XplIPWriteSSL(void *sktCtx, unsigned char *Buf, int Len); +#endif int XplIPConnectWithTimeout(IPSOCKET soc, struct sockaddr *addr, long addrSize, long timeout); #endif /* _BONGO_CONNIO_H */ diff --git a/include/msgapi.h b/include/msgapi.h index be92e94..52395dc 100644 --- a/include/msgapi.h +++ b/include/msgapi.h @@ -107,7 +107,7 @@ typedef enum { MSGAPI_FILE_END } MsgApiFile; -EXPORT const unsigned char * +EXPORT const char * MsgGetFile(MsgApiFile file, char *buffer, size_t buffer_size); EXPORT const char * MsgGetDir(MsgApiDirectory directory, char *buffer, size_t buffer_size); diff --git a/src/libs/connio/CMakeLists.txt b/src/libs/connio/CMakeLists.txt index 93b1995..c56f821 100644 --- a/src/libs/connio/CMakeLists.txt +++ b/src/libs/connio/CMakeLists.txt @@ -1,10 +1,10 @@ -#StrictCompile() +StrictCompile() add_library(bongoconnio SHARED + sockets.c connio.c trace.c addrpool.c - sockets.c unix-ip.c ) diff --git a/src/libs/connio/connio.c b/src/libs/connio/connio.c index 866af42..b8fe5d9 100644 --- a/src/libs/connio/connio.c +++ b/src/libs/connio/connio.c @@ -114,7 +114,7 @@ ConnStartup(unsigned long TimeOut) gnutls_dh_params_init(&dh_params); genparams = fopen(XPL_DEFAULT_DHPARAMS_PATH, "r"); if (genparams) { - char tmpdata[2048]; + unsigned char tmpdata[2048]; gnutls_datum dh_parameters; dh_parameters.size = fread(tmpdata, 1, sizeof(tmpdata)-1, genparams); @@ -137,7 +137,7 @@ ConnStartup(unsigned long TimeOut) gnutls_rsa_params_init(&rsa_params); genparams = fopen(XPL_DEFAULT_RSAPARAMS_PATH, "r"); if (genparams) { - char tmpdata[2048]; + unsigned char tmpdata[2048]; gnutls_datum rsa_parameters; rsa_parameters.size = fread(tmpdata, 1, sizeof(tmpdata)-1, genparams); @@ -285,8 +285,8 @@ ConnServerSocket(Connection *conn, int backlog) } if (ccode != -1) { - ccode = sizeof(conn->socketAddress); - IPgetsockname(conn->socket, (struct sockaddr *)&(conn->socketAddress), &ccode); + socklen_t len = sizeof(conn->socketAddress); + IPgetsockname(conn->socket, (struct sockaddr *)&(conn->socketAddress), &len); } else { IPclose(conn->socket); conn->socket = -1; @@ -316,15 +316,6 @@ ConnServerSocketUnix(Connection *conn, const char *path, int backlog) IPclose(conn->socket); conn->socket = -1; } -#if 0 - if (ccode != -1) { - ccode = sizeof(conn->socketAddress); - IPgetsockname(conn->socket, (struct sockaddr *)&(conn->socketAddress), &ccode); - } else { - IPclose(conn->socket); - conn->socket = -1; - } -#endif } return(conn->socket); @@ -335,6 +326,8 @@ ConnConnectInternal(Connection *conn, struct sockaddr *saddr, socklen_t slen, bo { int ccode; + UNUSED_PARAMETER(destination); + conn->socket = IPsocket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if (conn->socket != -1) { if (!saddr) { @@ -583,7 +576,7 @@ ConnShutdown(void) int ConnAccept(Connection *Server, Connection **Client) { - int length; + socklen_t length; Connection *c = ConnAlloc(TRUE); if (c) { @@ -609,7 +602,7 @@ int ConnAccept(Connection *Server, Connection **Client) int ConnSend(Connection *Conn, char *Buffer, unsigned int Length) { - int count; + size_t count; ConnTcpWrite(Conn, Buffer, Length, &count); @@ -619,7 +612,7 @@ ConnSend(Connection *Conn, char *Buffer, unsigned int Length) int ConnReceive(Connection *Conn, char *Buffer, unsigned int Length) { - int count; + size_t count; ConnTcpRead(Conn, Buffer, Length, &count); @@ -639,13 +632,23 @@ ConnReceive(Connection *Conn, char *Buffer, unsigned int Length) int ConnRead(Connection *Conn, char *Dest, int Length) { - int read; + size_t read; + size_t uLength; + int err; + Connection *c = Conn; + if (Length <= 0) { + return 0; + } + + /* since i know Length is greater than 0 i should be able to safely cast here */ + uLength = Length; + read = c->receive.write - c->receive.read; do { if (read > 0) { - if (read <= Length) { + if (read <= uLength) { memcpy(Dest, c->receive.read, read); c->receive.read = c->receive.write = c->receive.buffer; @@ -655,14 +658,14 @@ ConnRead(Connection *Conn, char *Dest, int Length) return(read); } - memcpy(Dest, c->receive.read, Length); + memcpy(Dest, c->receive.read, uLength); - c->receive.read += Length; + c->receive.read += uLength; - return(Length); + return(uLength); } - ConnTcpRead(c, c->receive.buffer, CONN_TCP_MTU, &read); + err = ConnTcpRead(c, c->receive.buffer, CONN_TCP_MTU, &read); if (read > 0) { c->receive.read = c->receive.buffer; c->receive.write = c->receive.buffer + read; @@ -689,6 +692,7 @@ ConnReadCount(Connection *Conn, char *Dest, int Count) { size_t buffered; size_t remaining = Count; + int err; char *d = Dest; Connection *c = Conn; @@ -721,7 +725,7 @@ ConnReadCount(Connection *Conn, char *Dest, int Count) } if (remaining < CONN_TCP_MTU) { - ConnTcpRead(c, c->receive.write, c->receive.remaining, &buffered); + err = ConnTcpRead(c, c->receive.write, c->receive.remaining, &buffered); if (buffered > 0) { c->receive.write += buffered; @@ -732,7 +736,7 @@ ConnReadCount(Connection *Conn, char *Dest, int Count) } } else { do { - ConnTcpRead(c, d, remaining, &buffered); + err = ConnTcpRead(c, d, remaining, &buffered); if (buffered > 0) { d += buffered; remaining -= buffered; @@ -756,7 +760,8 @@ ConnReadCount(Connection *Conn, char *Dest, int Count) int ConnReadLine(Connection *Conn, char *Line, int Length) { - int count; + size_t count; + int err; char *cur; char *limit; char *dest; @@ -844,7 +849,7 @@ ConnReadLine(Connection *Conn, char *Line, int Length) } } - ConnTcpRead(c, c->receive.buffer, CONN_TCP_MTU, &count); + err = ConnTcpRead(c, c->receive.buffer, CONN_TCP_MTU, &count); if (count > 0) { cur = c->receive.read = c->receive.buffer; limit = c->receive.write = cur + count; @@ -860,11 +865,11 @@ ConnReadLine(Connection *Conn, char *Line, int Length) return(dest - Line); } - int ConnReadAnswer(Connection *Conn, char *Line, int Length) { - int count; + size_t count; + int err; char *cur; char *limit; char *dest; @@ -974,7 +979,7 @@ ConnReadAnswer(Connection *Conn, char *Line, int Length) } } - ConnTcpRead(c, c->receive.buffer, CONN_TCP_MTU, &count); + err = ConnTcpRead(c, c->receive.buffer, CONN_TCP_MTU, &count); if (count > 0) { cur = c->receive.read = c->receive.buffer; limit = c->receive.write = cur + count; @@ -1068,10 +1073,11 @@ ConnReadToAllocatedBuffer(Connection *c, char **buffer, unsigned long *bufferSiz while (found_end_of_line == FALSE) { if (c->receive.read == c->receive.write) { // we need to fetch more data since the buffers are empty - this blocks - int count; + size_t count; + int err; - ConnTcpRead(c, c->receive.buffer, CONN_TCP_MTU, &count); - if (count <= 0) { + err = ConnTcpRead(c, c->receive.buffer, CONN_TCP_MTU, &count); + if ((err < 0) || (count == 0)) { c->send.remaining = CONN_TCP_MTU; c->send.read = c->send.write; return(CONN_ERROR_NETWORK); @@ -1097,7 +1103,7 @@ ConnReadToAllocatedBuffer(Connection *c, char **buffer, unsigned long *bufferSiz long BytesCopied = ConnAppendToAllocatedBuffer(c->receive.read, (c->receive.write - c->receive.read), buffer, data_consumed, bufferSize); c->receive.read += BytesCopied; - data_consumed += BytesCopied; + data_consumed += BytesCopied; } } @@ -1128,6 +1134,7 @@ ConnReadToFile(Connection *Conn, FILE *Dest, int Count) { size_t buffered; size_t remaining; + int err; Connection *c = Conn; remaining = Count; @@ -1164,7 +1171,7 @@ ConnReadToFile(Connection *Conn, FILE *Dest, int Count) } } - ConnTcpRead(c, c->receive.write, c->receive.remaining, &buffered); + err = ConnTcpRead(c, c->receive.write, c->receive.remaining, &buffered); if (buffered > 0) { c->receive.write += buffered; c->receive.remaining -= buffered; @@ -1184,6 +1191,7 @@ ConnReadToFileUntilEOS(Connection *Src, FILE *Dest) { int written = 0; size_t count; + int err; char *cur; char *limit; BOOL finished = FALSE; @@ -1274,7 +1282,7 @@ ConnReadToFileUntilEOS(Connection *Src, FILE *Dest) Src->receive.write[0] = '\0'; } - ConnTcpRead(Src, Src->receive.write, Src->receive.remaining, &count); + err = ConnTcpRead(Src, Src->receive.write, Src->receive.remaining, &count); if (count > 0) { Src->receive.read = Src->receive.buffer; Src->receive.write += count; @@ -1293,15 +1301,17 @@ ConnReadToFileUntilEOS(Connection *Src, FILE *Dest) int ConnReadToConn(Connection *Src, Connection *Dest, int Count) { - unsigned int sent; + size_t sent; size_t buffered; size_t remaining; + int err; + Connection *s = Src; Connection *d = Dest; if ((remaining = Count) > 0) { - ConnTcpFlush(d, d->send.read, d->send.write, &sent); - if (sent >= 0) { + err = ConnTcpFlush(d, d->send.read, d->send.write, &sent); + if (err == 0) { d->send.read = d->send.write = d->send.buffer; d->send.remaining = CONN_TCP_MTU; @@ -1317,7 +1327,7 @@ ConnReadToConn(Connection *Src, Connection *Dest, int Count) buffered = s->receive.write - s->receive.read; if (buffered > 0) { if (remaining <= buffered) { - ConnTcpWrite(d, s->receive.read, remaining, &sent); + err = ConnTcpWrite(d, s->receive.read, remaining, &sent); if (sent == remaining) { s->receive.read += sent; if (s->receive.read == s->receive.write) { @@ -1334,7 +1344,7 @@ ConnReadToConn(Connection *Src, Connection *Dest, int Count) } if ((remaining > s->receive.remaining) && (s->receive.remaining < CONN_TCP_THRESHOLD)) { - ConnTcpWrite(d, s->receive.read, buffered, &sent); + err = ConnTcpWrite(d, s->receive.read, buffered, &sent); if (sent == buffered) { remaining -= sent; @@ -1348,7 +1358,7 @@ ConnReadToConn(Connection *Src, Connection *Dest, int Count) } } - ConnTcpRead(s, s->receive.write, s->receive.remaining, &buffered); + err = ConnTcpRead(s, s->receive.write, s->receive.remaining, &buffered); if (buffered > 0) { s->receive.write += buffered; s->receive.remaining -= buffered; @@ -1367,13 +1377,14 @@ int ConnReadToConnUntilEOS(Connection *Src, Connection *Dest) { int written = 0; - int count; + size_t count; + int err; char *cur; char *limit; BOOL finished = FALSE; - ConnTcpFlush(Dest, Dest->send.read, Dest->send.write, &count); - if (count >= 0) { + err = ConnTcpFlush(Dest, Dest->send.read, Dest->send.write, &count); + if (err == 0) { Dest->send.read = Dest->send.write = Dest->send.buffer; Dest->send.remaining = CONN_TCP_MTU; @@ -1410,10 +1421,13 @@ ConnReadToConnUntilEOS(Connection *Src, Connection *Dest) *cur++ = ' '; continue; } - + if (Src->receive.read < cur) { - ConnTcpFlush(Dest, Src->receive.read, cur, &count); - if ((cur - Src->receive.read) == count) { + int distance; + + err = ConnTcpFlush(Dest, Src->receive.read, cur, &count); + distance = cur - Src->receive.read; + if ((distance > 0) && ((size_t)distance == count)) { written += count; if (!finished) { @@ -1444,7 +1458,7 @@ ConnReadToConnUntilEOS(Connection *Src, Connection *Dest) } } - ConnTcpRead(Src, Src->receive.write, Src->receive.remaining, &count); + err = ConnTcpRead(Src, Src->receive.write, Src->receive.remaining, &count); if (count > 0) { Src->receive.read = Src->receive.buffer; Src->receive.write += count; @@ -1464,7 +1478,8 @@ int ConnWrite(Connection *Conn, const char *Buffer, int Length) { const char *b; - int i; + size_t i; + int err; size_t r; Connection *c = Conn; @@ -1488,7 +1503,7 @@ ConnWrite(Connection *Conn, const char *Buffer, int Length) c->send.write += c->send.remaining; - ConnTcpFlush(c, c->send.read, c->send.write, &i); + err = ConnTcpFlush(c, c->send.read, c->send.write, &i); if (i > 0) { c->send.read = c->send.write = c->send.buffer; c->send.remaining = CONN_TCP_MTU; @@ -1503,7 +1518,7 @@ ConnWrite(Connection *Conn, const char *Buffer, int Length) } do { - ConnTcpFlush(c, b, b + r, &i); + err = ConnTcpFlush(c, b, b + r, &i); if (i > 0) { b += r; r -= r; @@ -1523,7 +1538,8 @@ ConnWrite(Connection *Conn, const char *Buffer, int Length) int ConnWriteFromFile(Connection *Conn, FILE *Source, int Count) { - int i; + size_t i; + int err; size_t n; size_t r; Connection *c = Conn; @@ -1547,7 +1563,7 @@ ConnWriteFromFile(Connection *Conn, FILE *Source, int Count) return(-1); } - ConnTcpFlush(c, c->send.read, c->send.write, &i); + err = ConnTcpFlush(c, c->send.read, c->send.write, &i); if (i > 0) { c->send.read = c->send.write = c->send.buffer; c->send.remaining = CONN_TCP_MTU; @@ -1565,7 +1581,8 @@ ConnWriteFromFile(Connection *Conn, FILE *Source, int Count) int ConnWriteFile(Connection *Conn, FILE *Source) { - int i; + size_t i; + int err; size_t n; size_t r; Connection *c = Conn; @@ -1586,7 +1603,7 @@ ConnWriteFile(Connection *Conn, FILE *Source) n += c->send.write - c->send.read; - ConnTcpFlush(c, c->send.read, c->send.write, &i); + err = ConnTcpFlush(c, c->send.read, c->send.write, &i); if (i > 0) { c->send.read = c->send.write = c->send.buffer; c->send.remaining = r = CONN_TCP_MTU; @@ -1605,6 +1622,8 @@ int ConnWriteVF(Connection *c, const char *format, va_list ap) { int i; + size_t unused; + int err; do { if (CONN_BUFSIZE < c->send.remaining) { @@ -1641,8 +1660,8 @@ ConnWriteVF(Connection *c, const char *format, va_list ap) va_end(ap2); } - ConnTcpFlush(c, c->send.read, c->send.write, &i); - if (i > 0) { + err = ConnTcpFlush(c, c->send.read, c->send.write, &unused); + if (unused > 0) { c->send.read = c->send.write = c->send.buffer; c->send.remaining = CONN_TCP_MTU; @@ -1670,12 +1689,13 @@ ConnWriteF(Connection *conn, const char *Format, ...) int ConnFlush(Connection *Conn) { - int count; + size_t count; + int err; Connection *c = Conn; - ConnTcpFlush(c, c->send.read, c->send.write, &count); + err = ConnTcpFlush(c, c->send.read, c->send.write, &count); - if (count >= 0) { + if (err == 0) { c->send.read += count; if (c->send.read == c->send.write) { c->send.read = c->send.write = c->send.buffer; diff --git a/src/libs/connio/sockets.c b/src/libs/connio/sockets.c index 96f7269..7675e89 100644 --- a/src/libs/connio/sockets.c +++ b/src/libs/connio/sockets.c @@ -7,9 +7,9 @@ #include "config.h" void -CHOP_NEWLINE(unsigned char *s) +CHOP_NEWLINE(char *s) { - unsigned char *p; + char *p; p = strchr(s, 0x0A); if (p) { *p = '\0'; @@ -20,31 +20,17 @@ CHOP_NEWLINE(unsigned char *s) } } -void -SET_POINTER_TO_VALUE(unsigned char *p, unsigned char *s) +int +ConnTcpFlush(Connection *c, const char *b, const char *e, size_t *r) { - // FIXME: Unused? - p = s; - while(isspace(*p)) { - p++; - } - if ((*p == '=') || (*p == ':')) { - p++; - } - while(isspace(*p)) { - p++; - } -} + int Result=0; -void -ConnTcpFlush(Connection *c, const char *b, const char *e, int *r) -{ if (b < e) { char *curPTR = (char *)b; while (curPTR < e) { - ConnTcpWrite(c, curPTR, e - curPTR, r); + Result = ConnTcpWrite(c, curPTR, e - curPTR, r); if (*r > 0) { - curPTR = curPTR + (int)*r; + curPTR = curPTR + *r; continue; } break; @@ -52,11 +38,14 @@ ConnTcpFlush(Connection *c, const char *b, const char *e, int *r) if (curPTR == e) { *r = e - b; } else { - *r = -1; + *r = 0; + Result = -1; } } else { *r = 0; } + + return Result; } void @@ -88,104 +77,85 @@ ConnTcpClose(Connection *c) } } -//#if defined(S390RH) || defined(SOLARIS) - -// TODO: is this correct for Solaris? - -void -ConnTcpRead(Connection *c, char *b, size_t l, int *r) +int +ConnTcpRead(Connection *c, char *b, size_t l, size_t *r) { + int Result=0; + struct pollfd pfd; do { pfd.fd = (int)c->socket; pfd.events = POLLIN; - *r = poll(&pfd, 1, c->receive.timeOut * 1000); - if (*r > 0) { + Result = poll(&pfd, 1, c->receive.timeOut * 1000); + if (Result > 0) { if ((pfd.revents & (POLLIN | POLLPRI))) { do { if (!c->ssl.enable) { - *r = IPrecv((c)->socket, b, l, 0); + Result = IPrecv((c)->socket, b, l, 0); } else { - *r = gnutls_record_recv(c->ssl.context, (void *)b, l); - if (*r < 0) { - CONN_TRACE_ERROR(c, "RECV", *r); - break; - } + Result = gnutls_record_recv(c->ssl.context, (void *)b, l); } - if (*r >= 0) { - CONN_TRACE_DATA(c, CONN_TRACE_EVENT_READ, b, *r); + if (Result >= 0) { + CONN_TRACE_DATA(c, CONN_TRACE_EVENT_READ, b, Result); + /* we actually worked. reset Result to 0 indicating that */ + /* Result is > 0 so i should be able to safely cast it here */ + *r = (size_t)Result; + Result = 0; break; } else if (errno == EINTR) { continue; } - CONN_TRACE_ERROR(c, "RECV", *r); + /* we failed with something other than eintr... we'll reset Result below */ + CONN_TRACE_ERROR(c, "RECV", Result); break; } while (TRUE); break; } else if ((pfd.revents & (POLLERR | POLLHUP | POLLNVAL))) { - CONN_TRACE_ERROR(c, "POLL EVENT", *r); - *r = -2; + CONN_TRACE_ERROR(c, "POLL EVENT", Result); + *r = 0; + Result = -2; break; } } if (errno == EINTR) { continue; } - CONN_TRACE_ERROR(c, "POLL", *r); - *r = -3; + CONN_TRACE_ERROR(c, "POLL", Result); + Result = -3; + *r = 0; break; } while (TRUE); + + return Result; } -void -ConnTcpWrite(Connection *c, char *b, size_t l, int *r) +int +ConnTcpWrite(Connection *c, char *b, size_t l, size_t *r) { + int Result=0; + do { if (!c->ssl.enable) { - *r = IPsend(c->socket, b, l, MSG_NOSIGNAL); + Result = IPsend(c->socket, b, l, MSG_NOSIGNAL); } else { - *r = gnutls_record_send(c->ssl.context, (void *)b, l); + Result = gnutls_record_send(c->ssl.context, (void *)b, l); } - if (*r >= 0) { - CONN_TRACE_DATA(c, CONN_TRACE_EVENT_WRITE, b, *r); + if (Result >= 0) { + CONN_TRACE_DATA(c, CONN_TRACE_EVENT_WRITE, b, Result); + /* we actually worked. reset Result to 0 indicating that */ + /* Result is > 0 so i should be able to safely cast here */ + *r = Result; + Result = 0; break; } else if (errno == EINTR) { continue; } - CONN_TRACE_ERROR(c, "POLL", *r); - *r = -1; + CONN_TRACE_ERROR(c, "POLL", Result); + Result = -1; + *r = 0; break; } while (TRUE); + + return Result; } -//#else -#if 0 - -void -ConnTcpRead(Connection *c, char *b, size_t l, int *r) -{ - fd_set rfds; - struct timeval timeout; - FD_ZERO(&rfds); - FD_SET(c->socket, &rfds); - timeout.tv_usec = 0; - timeout.tv_sec = c->receive.timeOut; - *r = select(FD_SETSIZE, &rfds, NULL, NULL, &timeout); - if (*r > 0) { - *r = recv(c->socket, b, l, 0); - CONN_TRACE_DATA_AND_ERROR(c, CONN_TRACE_EVENT_READ, b, *r, "RECV"); - } else { - CONN_TRACE_ERROR(c, "SELECT", *r); - *r = -1; - } -} - -void -ConnTcpWrite(Connection *c, char *b, size_t l, int *r) -{ - *r = IPsend(c->socket, b, l, 0); - CONN_TRACE_DATA_AND_ERROR(c, CONN_TRACE_EVENT_WRITE, b, *r, "SEND"); -} - - -#endif diff --git a/src/libs/connio/unix-ip.c b/src/libs/connio/unix-ip.c index 06ed5c2..9e8702b 100644 --- a/src/libs/connio/unix-ip.c +++ b/src/libs/connio/unix-ip.c @@ -340,91 +340,6 @@ XplIsLocalIPAddress(unsigned long Address) return(FALSE); } -#if 0 -//FIXME: this appears unused -static int -IPshouldretry(int i) -{ - int err; - - if ((i == 0) || (i == -1)) { - err = IPerror(); - - switch (err) { - case EINTR: - case EINPROGRESS: { - return(1); - /* break; */ - } - - default: { - return(0); - } - } - } - return(0); -} -#endif - -int -XplIPRead(void *socket, unsigned char *Buf, int Len, int readTimeout) -{ - int rc; - struct pollfd pfd; - - /* All sockets are closed when exiting. */ - /* Closed socket will error on read. */ - pfd.fd = (int)(socket); - pfd.events = POLLIN; - rc = poll(&pfd, 1, readTimeout * 1000); - if (rc > 0) { - /*success */ - /* see if an error ocurred on this socket */ - if (!(pfd.revents & (POLLERR | POLLHUP | POLLNVAL))) { - -XPLIPRead_Again: - - rc = recv((int)(socket), Buf, Len, 0); - if (rc >= 0) { - /* success */ - return(rc); - } else if (errno == EINTR) { - goto XPLIPRead_Again; - } - - /* read error(-1) or end of connection (0) */ - return(rc); - } - - /* pfd.revents error received */ - return(-1); - } else if (rc == 0) { - /* poll timeout */ - return(-1); - } - - return(-1); -} - - -int -XplIPWrite(void * socket, unsigned char *Buf, int Len) -{ - int rc; - -XPLIPWrite_Again: - - rc = send((int)(socket), Buf, Len, 0); - if (rc >= 0) { - /* common predicted path */ - return(rc); - } else if (errno == EINTR) { - goto XPLIPWrite_Again; - } - - return(-1); -} - __inline static BOOL MakeSocketNonBlocking(int soc) { diff --git a/src/libs/msgapi/msgapi.c b/src/libs/msgapi/msgapi.c index 4cba622..d0dc15e 100644 --- a/src/libs/msgapi/msgapi.c +++ b/src/libs/msgapi/msgapi.c @@ -125,10 +125,10 @@ MsgNmapChallenge(const unsigned char *response, unsigned char *reply, size_t len { unsigned char *ptr; unsigned char *salt; - static unsigned char access[NMAP_HASH_SIZE] = { '\0' }; + static char access[NMAP_HASH_SIZE] = { '\0' }; xpl_hash_context ctx; - MsgGetServerCredential(&access); + MsgGetServerCredential(access); if (access[0] && reply && (length > 32) && ((ptr = strchr(response, '<')) != NULL)) { salt = ++ptr; @@ -291,7 +291,7 @@ MsgGetDir(MsgApiDirectory directory, char *buffer, size_t buffer_size) return path; } -EXPORT const unsigned char * +EXPORT const char * MsgGetFile(MsgApiFile file, char *buffer, size_t buffer_size) { const unsigned char *path; diff --git a/src/libs/nmap/nmap.c b/src/libs/nmap/nmap.c index 10b5bc5..04e32eb 100644 --- a/src/libs/nmap/nmap.c +++ b/src/libs/nmap/nmap.c @@ -112,7 +112,8 @@ FindNewLineChar(unsigned char *Buffer, unsigned char *EndPtr) { __inline static unsigned char * FindEndOfLine(Connection *conn) { - int count; + size_t count; + int err; char *newLine; Connection *c = conn; @@ -126,7 +127,7 @@ FindEndOfLine(Connection *conn) if (count < CONN_TCP_MTU) { if (count == 0) { - ConnTcpRead(c, c->receive.buffer, CONN_TCP_MTU, &count); + err = ConnTcpRead(c, c->receive.buffer, CONN_TCP_MTU, &count); if (count > 0) { c->receive.read = c->receive.buffer; c->receive.write = c->receive.buffer + count; @@ -143,7 +144,7 @@ FindEndOfLine(Connection *conn) c->receive.read = c->receive.buffer; c->receive.write = c->receive.buffer + count; c->receive.remaining = CONN_TCP_MTU - count; - ConnTcpRead(c, c->receive.write, c->receive.remaining, &count); + err = ConnTcpRead(c, c->receive.write, c->receive.remaining, &count); if (count > 0) { c->receive.write += count; c->receive.remaining -= count;