#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
#include <winsock.h>
#include <richedit.h>
#include "NanoMud.h"
Include dependency graph for nanomud-net.c:

Go to the source code of this file.
Functions | |
| void | CheckPing () |
| u_short | in_cksum (u_short *addr, int len) |
| DWORD | RecvEchoReply (SOCKET s, LPSOCKADDR_IN lpsaFrom, u_char *pTTL) |
| int | SendEchoRequest (SOCKET s, LPSOCKADDR_IN lpstToAddr) |
| int | WaitForEchoReply (SOCKET s) |
|
|
Definition at line 36 of file nanomud-net.c. References session_data::ping, session_data::rawSocket, RecvEchoReply(), session_data::saDest, session_data::saSrc, SendEchoRequest(), this_session, and WaitForEchoReply(). Referenced by check_ping(). 00037 {
00038 //return; //For some reason, this is not stable enough to include.
00039 DWORD dwTimeSent;
00040 DWORD dwElapsed;
00041 u_char cTTL;
00042
00043 int nRet;
00044
00045
00046 // rawSocket = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
00047
00048 SendEchoRequest(this_session->rawSocket, &this_session->saDest);
00049 nRet = WaitForEchoReply(this_session->rawSocket);
00050
00051
00052 if (nRet == SOCKET_ERROR)
00053 {
00054
00055 return;
00056 }
00057 if (!nRet)
00058 {
00059
00060 return;
00061
00062 }
00063 dwTimeSent = RecvEchoReply(this_session->rawSocket, &this_session->saSrc, &cTTL);
00064 dwElapsed = GetTickCount() - dwTimeSent;
00065
00066
00067
00068
00069 // nRet = closesocket(this_session->rawSocket);
00070 this_session->ping = dwElapsed;
00071 return;
00072 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 144 of file nanomud-net.c. Referenced by SendEchoRequest(). 00145 {
00146 register int nleft = len;
00147 register u_short *w = addr;
00148 register u_short answer;
00149 register int sum = 0;
00150
00151 /*
00152 * Our algorithm is simple, using a 32 bit accumulator (sum),
00153 * we add sequential 16 bit words to it, and at the end, fold
00154 * back all the carry bits from the top 16 bits into the lower
00155 * 16 bits.
00156 */
00157 while( nleft > 1 ) {
00158 sum += *w++;
00159 nleft -= 2;
00160 }
00161
00162 /* mop up an odd byte, if necessary */
00163 if( nleft == 1 ) {
00164 u_short u = 0;
00165
00166 *(u_char *)(&u) = *(u_char *)w ;
00167 sum += u;
00168 }
00169
00170 /*
00171 * add back carry outs from top 16 bits to low 16 bits
00172 */
00173 sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */
00174 sum += (sum >> 16); /* add carry */
00175 answer = ~sum; /* truncate to 16 bits */
00176 return (answer);
00177 }
|
|
||||||||||||||||
|
Definition at line 106 of file nanomud-net.c. References ECHOREPLY. Referenced by CheckPing(). 00107 {
00108 ECHOREPLY echoReply;
00109 int nRet;
00110 int nAddrLen = sizeof(struct sockaddr_in);
00111
00112
00113 nRet = recvfrom(s,(LPSTR)&echoReply,sizeof(ECHOREPLY),0,(LPSOCKADDR)lpsaFrom, &nAddrLen);
00114
00115
00116 // if (nRet == SOCKET_ERROR)
00117 // ReportError("recvfrom()");
00118
00119
00120 *pTTL = echoReply.ipHdr.TTL;
00121 return(echoReply.echoRequest.dwTime);
00122 }
|
|
||||||||||||
|
Definition at line 76 of file nanomud-net.c. References tagECHOREQUEST::cData, tagICMPHDR::Checksum, tagICMPHDR::Code, tagECHOREQUEST::dwTime, ECHOREQUEST, tagECHOREQUEST::icmpHdr, tagICMPHDR::ID, in_cksum(), tagICMPHDR::Seq, and tagICMPHDR::Type. Referenced by CheckPing(). 00077 {
00078 static ECHOREQUEST echoReq;
00079 static int nId = 1;
00080 static int nSeq = 1;
00081 int nRet;
00082
00083 echoReq.icmpHdr.Type = ICMP_ECHOREQ;
00084 echoReq.icmpHdr.Code = 0;
00085 echoReq.icmpHdr.Checksum = 0;
00086 echoReq.icmpHdr.ID = nId++;
00087 echoReq.icmpHdr.Seq = nSeq++;
00088
00089
00090 for (nRet = 0; nRet < REQ_DATASIZE; nRet++)
00091 echoReq.cData[nRet] = ' '+nRet;
00092
00093
00094 echoReq.dwTime = GetTickCount();
00095
00096
00097 echoReq.icmpHdr.Checksum = in_cksum((u_short *)&echoReq, sizeof(ECHOREQUEST));
00098
00099
00100 nRet = sendto(s,(LPSTR)&echoReq, sizeof(ECHOREQUEST), 0, (LPSOCKADDR)lpstToAddr,sizeof(SOCKADDR_IN));
00101
00102 // if (nRet == SOCKET_ERROR)
00103 // ReportError("sendto()");
00104 return (nRet);
00105 }
|
Here is the call graph for this function:

|
|
Definition at line 123 of file nanomud-net.c. Referenced by CheckPing(). 00124 {
00125 struct timeval Timeout;
00126 fd_set readfds;
00127
00128 readfds.fd_count = 1;
00129 readfds.fd_array[0] = s;
00130 Timeout.tv_sec = 5;
00131 Timeout.tv_usec = 0;
00132
00133 return(select(1, &readfds, NULL, NULL, &Timeout));
00134 }
|
1.3.9.1