[Javanetsim-cvs] IceScan/icesockets crawsocket.h, 1.13, 1.14 csocket.h, 1.19, 1.20 sock_types.h, 1.
Status: Beta
Brought to you by:
darkkey
From: Alexander B. <da...@us...> - 2006-12-17 11:00:24
|
Update of /cvsroot/javanetsim/IceScan/icesockets In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv14929/icesockets Modified Files: crawsocket.h csocket.h sock_types.h Log Message: no message Index: sock_types.h =================================================================== RCS file: /cvsroot/javanetsim/IceScan/icesockets/sock_types.h,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** sock_types.h 17 Dec 2006 09:59:40 -0000 1.17 --- sock_types.h 17 Dec 2006 11:00:20 -0000 1.18 *************** *** 68,71 **** --- 68,72 ---- #define SOCKET_ERROR -1 typedef int SOCKET; + //#define SOCKET int typedef uint16_t my_uint16_t; Index: crawsocket.h =================================================================== RCS file: /cvsroot/javanetsim/IceScan/icesockets/crawsocket.h,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** crawsocket.h 17 Dec 2006 09:59:40 -0000 1.13 --- crawsocket.h 17 Dec 2006 11:00:20 -0000 1.14 *************** *** 81,85 **** int rc = 0; ! if( rc = ::setsockopt(sid, level, opname, (sockbuf_type) optval, optlen) > 0 ) sockerror("setsockopt"); --- 81,85 ---- int rc = 0; ! if( rc = ::setsockopt(sid, level, opname, optval, optlen) > 0 ) sockerror("setsockopt"); *************** *** 92,96 **** int recvfrom(void *buf, int len, unsigned int flags, char *srchostname){ ! return csocket::recvfrom((sockbuf_type) buf, len, flags, srchostname, NULL); } --- 92,96 ---- int recvfrom(void *buf, int len, unsigned int flags, char *srchostname){ ! return csocket::recvfrom(buf, len, flags, srchostname, NULL); } Index: csocket.h =================================================================== RCS file: /cvsroot/javanetsim/IceScan/icesockets/csocket.h,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** csocket.h 17 Dec 2006 09:59:40 -0000 1.19 --- csocket.h 17 Dec 2006 11:00:20 -0000 1.20 *************** *** 10,19 **** #ifdef WIN32 ! typedef char* sockbuf_type; #else ! typedef void* sockbuf_type; #endif ! ! #define MIN_MAGIC_PORT 20000 #define MAX_MAGIC_PORT 65535 --- 10,19 ---- #ifdef WIN32 ! typedef char* sockbuf_type; #else ! typedef void* sockbuf_type; #endif ! ! #define MIN_MAGIC_PORT 30000 #define MAX_MAGIC_PORT 65535 *************** *** 88,97 **** void close(){ ! #ifndef WIN32 ! ::close(sid); ! #else ! ::closesocket(sid); ! #endif ! } ~csocket(){ /*std::cout << "CSCOCKET destroyed." << (cs_id) << std::endl; */ } --- 88,97 ---- void close(){ ! #ifndef WIN32 ! ::close(sid); ! #else ! ::closesocket(sid); ! #endif ! } ~csocket(){ /*std::cout << "CSCOCKET destroyed." << (cs_id) << std::endl; */ } *************** *** 102,105 **** --- 102,106 ---- struct sockaddr_in saddress; int len; + int sopt, soptlen; if(!(len = make_sockname(saddress, hostname, port, domain))) *************** *** 108,118 **** if(!timeout){ if(block){ - if(::connect(sid, (struct sockaddr *) &saddress, sizeof(struct sockaddr)) == SOCKET_ERROR) ! #ifndef WIN32 //UGLY!!!! ! return sockerror("connect"); ! #else ! ; ! #endif }else{ if(::connect(sid, (struct sockaddr *) &saddress, sizeof(struct sockaddr)) != SOCKET_ERROR) --- 109,118 ---- if(!timeout){ if(block){ if(::connect(sid, (struct sockaddr *) &saddress, sizeof(struct sockaddr)) == SOCKET_ERROR) ! #ifndef WIN32 ! return sockerror("connect"); ! #else ! ; ! #endif }else{ if(::connect(sid, (struct sockaddr *) &saddress, sizeof(struct sockaddr)) != SOCKET_ERROR) *************** *** 121,162 **** } }else{ ! fd_set sset; ! struct timeval tv; ! ! nonblock(true); ! ! ::connect(sid, (struct sockaddr *) &saddress, sizeof(struct sockaddr)); ! ! FD_ZERO(&sset); ! FD_SET(sid, &sset); ! tv.tv_sec = timeout; ! tv.tv_usec = 0; ! SOCKET ndfs = sid + 1; ! ! #ifdef WIN32 ! int res = select(0, NULL, &sset, NULL, &tv); ! #else ! int res = select(ndfs, NULL, &sset, NULL, &tv); ! #endif ! nonblock(false); ! if (res == SOCKET_ERROR && errno != EINTR){ ! return ICESOCK_ERRNO; ! } else if (res == 0){ ! int sopt, soptlen; ! getsockopt(SOL_SOCKET, SO_ERROR, (char *) &sopt, (socklen_t *) &soptlen); ! DBGOUTPUT(sopt); ! if(sopt == ECONNREFUSED) ! return ICESOCK_CONNREF; ! else ! return ICESOCK_TIMEOUT; ! } } ! return 0; } --- 121,161 ---- } }else{ ! fd_set sset; ! struct timeval tv; ! ! nonblock(true); ! ! ::connect(sid, (struct sockaddr *) &saddress, sizeof(struct sockaddr)); ! FD_ZERO(&sset); ! FD_SET(sid, &sset); ! tv.tv_sec = timeout; ! tv.tv_usec = 0; ! int ndfs = sid + 1; ! ! #ifdef WIN32 ! int res = select(0, NULL, &sset, NULL, &tv); ! #else ! int res = select(ndfs, NULL, &sset, NULL, &tv); ! #endif ! ! nonblock(false); ! ! if (res == SOCKET_ERROR && errno != EINTR){ ! return ICESOCK_ERRNO; ! } else if (res == 0){ ! getsockopt(SOL_SOCKET, SO_ERROR, (char *) &sopt, (socklen_t *) &soptlen); ! if(sopt == ECONNREFUSED) ! return ICESOCK_CONNREF; ! else ! return ICESOCK_TIMEOUT; ! } } ! return 0; } *************** *** 205,209 **** int rc = 0; ! if( rc = ::getsockopt(sid, level, opname, (sockbuf_type) optval, optlen) > 0 ) sockerror("getsockopt"); --- 204,208 ---- int rc = 0; ! if( rc = ::getsockopt(sid, level, opname, optval, optlen) > 0 ) sockerror("getsockopt"); *************** *** 211,215 **** } ! int recvfrom(sockbuf_type buf, int len, int flags, char *srchostname, int *srchostport){ int rsize; struct sockaddr_in from; --- 210,214 ---- } ! int recvfrom(void *buf, int len, int flags, char *srchostname, int *srchostport){ int rsize; struct sockaddr_in from; *************** *** 226,230 **** } ! int sendto(const char *hostname, int port, const char* msg, int len, unsigned int flags){ struct sockaddr_in saddress; int slen; --- 225,230 ---- } ! int sendto(const char *hostname, int port, const void *msg, int len, unsigned int flags){ ! struct sockaddr_in saddress; int slen; *************** *** 244,248 **** } ! SOCKET get_socketid(){ return sid; } --- 244,248 ---- } ! int get_socketid(){ return sid; } *************** *** 257,316 **** void nonblock(bool lck){ ! #ifndef WIN32 ! int arg = fcntl(sid, F_GETFL, NULL); ! ! if(arg < 0){ perror("Error in fcntl(.., F_GETFL, ...)."); throw "Error in fcntl(.., F_GETFL, ...)."; } ! ! if(lck){ ! arg |= O_NONBLOCK; ! block = false; ! }else{ ! arg ^= O_NONBLOCK; ! block = true; ! } ! ! if( fcntl(sid, F_SETFL, arg) < 0 ){ perror("Error in fcntl(.., F_GETFL, ...)."); throw "Error in fcntl(.., F_SETFL, ...)."; } ! #else ! ULONG NonBlock; ! if(lck) ! NonBlock = 1; ! else ! NonBlock = 0; ! if (ioctlsocket(sid, FIONBIO, &NonBlock) == SOCKET_ERROR) ! { ! perror("ioctlsocket() failed"); ! exit(-1); ! } ! #endif } ! static int getMagicPort(int type, int tries){ ! int mp; ! int i; ! bool p; ! csocket s(PF_INET, type); ! char hostname[80]; ! ! if(gethostname(hostname,79)){ ! printf("\ngethostname() returned error!\n"); ! exit(-1); ! } ! if(tries <= 0){ ! tries = MAX_MAGIC_PORT - MIN_MAGIC_PORT + 1; ! } ! ! for(i = 0, p = false; i < tries && !p; i++){ ! mp = (unsigned)rand() % (MAX_MAGIC_PORT - MIN_MAGIC_PORT + 1) + MIN_MAGIC_PORT; ! p = s.bind(hostname, mp, 0) == 0; ! if(p){ ! s.shutdown(); ! s.close(); ! } ! } ! ! return (p==false ? 0 : mp); } - }; --- 257,319 ---- void nonblock(bool lck){ ! #ifndef WIN32 ! int arg = fcntl(sid, F_GETFL, NULL); ! if(arg < 0){ perror("Error in fcntl(.., F_GETFL, ...)."); throw "Error in fcntl(.., F_GETFL, ...)."; } ! ! if(lck){ ! arg |= O_NONBLOCK; ! block = false; ! }else{ ! arg ^= O_NONBLOCK; ! block = true; ! } ! ! if( fcntl(sid, F_SETFL, arg) < 0 ){ perror("Error in fcntl(.., F_GETFL, ...)."); throw "Error in fcntl(.., F_SETFL, ...)."; } ! #else ! ULONG NonBlock; ! if(lck) ! NonBlock = 1; ! else ! NonBlock = 0; ! ! if (ioctlsocket(sid, FIONBIO, &NonBlock) == SOCKET_ERROR) ! { ! perror("ioctlsocket() failed"); ! exit(-1); ! } ! #endif } ! static int getMagicPort(int type, int tries){ ! int mp; ! int i; ! bool p; ! csocket s(PF_INET, type); ! char hostname[80]; ! ! if(gethostname(hostname,79)){ ! printf("\ngethostname() returned error!\n"); ! exit(-1); ! } ! if(tries <= 0){ ! tries = MAX_MAGIC_PORT - MIN_MAGIC_PORT + 1; ! } ! ! for(i = 0, p = false; i < tries && !p; i++){ ! mp = (unsigned)rand() % (MAX_MAGIC_PORT - MIN_MAGIC_PORT + 1) + MIN_MAGIC_PORT; ! p = s.bind(hostname, mp, 0) == 0; ! if(p){ ! s.shutdown(); ! s.close(); ! } ! } ! ! return (p==false ? 0 : mp); ! } ! ! static int getMagicPort(){ ! return 33333; } }; |