Protocol JIURL255 Technical Reference

xiaoxiao2021-03-06  64

This is a very special way, using its communication without port, and because of its particularity, it may bring some other advantages. But this method also has a relatively large disadvantage.

It may have a name, such as JIURL255. It does not use the TCP protocol, nor does the UDP protocol, nor does ICMP protocols. What protocol is used, just like the name of the chaos, it uses 255 protocol.

This picture is an IP header without an IP option. One of these fields is 8-bit protocols, one byte length, the system is to distinguish what the upper protocol is what the upper protocol is, and the value should be handed over through the value of this byte. TCP is Tenjin 6, UDP is a decimal 17. That is to say, if this value is 6, it will be handed over to TCP processing. If it is 17, it will be handed over to UDP processing. So what if this value is a value that does not have people? For example, 222,255 (8bit, the largest 255). I think 255 is beautiful, I will take 255, and the other no one is used. So what will it? I guess it can be received, and later did some small trials, explained that I was right. (I have seen the sky in the sky, I found you have a computer's life). This thing and TCP, NDP have nothing to do, naturally there will be TCP, UDP port numbers.

Ok, I have been trying to try it, use JIURL255 to do a simple communication client program download, server-side program download. The server is RSERVER, and the client is Rclient. RServer first THSOCKET = Socket (AF_INET, SOCK_RAW, 255); establish a raw socket using JIURL255, then bound the local address, and finally blocked in Recvfrom, waiting for data from the 255 protocol. After receiving it, you will be printed out. RCLIENT first gets the server's IP address, then THSOCKET = Socket (AF_INET, SOCK_RAW, 255); create a raw socket using jiuml255, then let you enter some data from the keyboard to send input data to the server side .

In the first test, it is possible to find that it can be used to send and receive data using the protocol number that can be used. Probably this, after the system receives the IP package, see that the protocol number has the process to accept. If there is, it will be sent to that process.

Second test, run a RCLIT, run two RServer, send a data. It can be found that both RSERVER receives data sent by RCLIENT. The system will send the received data to each process to accept data on this protocol number.

Another test, when the server is created, the specified protocol number is 200, the Client side creates a socket. When populating the IP header, the protocol number is 255, and the resulting server does not receive the data sent by the Client. .

At that time: "Server Extreme Data Client Evergreen Data Server End Create a socket, the specified protocol number is 255, the Client side creates a socket, when the IP header is populated, the protocol number is 255, and the result server When the data sent by the Client side. When the Server end creates a socket, the specified protocol number is 200, the Client side creates a socket, fill the IP header, all specify the protocol number 255, and the resulting server will not receive the client. The data sent by the end. Multiple Server, use the protocol number 255, the Client side also issues data to 255 protocols, and multiple Server terminals have received data. "There is also, if the program is sent, and It is sent to this unit, then the program will receive the content you have issued. Didn't make it clear, for example, after a program, send 255 data, receive 255 data, he sent the data to the unit, then it will receive the data.

RCLIENT:

#include #include #include #include #include #pragma Comment (lib, "ws2_32.lib") typef struct ip_hdr / / Define IP header {UNSIGNED CHAR H_VERLEN; // 4 top length, 4-bit IP version number UNSigned char TOS; // 8 bit service type TOSUNSIGNED SHORT TOTAL_LEN; / / 16-bit total length (byte) unsigned short ide; // 16-bit identifier Unsigned short frag_and_flags; // 3-bit flag bit unsigned char TTL; // 8-bit survival time TTLUNSIGNED Char proto; // 8-bit protocol (TCP, UDP or other) Unsigned short checksum; // 16 ip IP First check and unsigned int sourceip; // 32 bitsource IP address unsigned int desip; // 32 bit ip address} ip_header, * pip_header; ushort checksum (ushort * buffer, int size); void rawclient (char * szserver) void main () {Wsadata WSADATA; Char ServerAddr [256]; Printf ("Server Addr:"); scanf ("% s", serveraddr); Printf ("/ n"); Wsastartup (0x0202, & wsadata); Rawclient (Serveraddr); wsacleanup ();} / usort checksum (ushort * buffer, int size) {unsigned long cksum = 0; while (size> 1) {cksum = * buffer ; size - = sizeof (ushort);} if (size) {CKSUM = * (Uchar *) Buffer;} CKSUM = (CKSUM >> 16) (CKSUM & 0xFFF); CKSUM = (Cksum >> 16); return (USHORT) (~ cksum);} // void RawClient (char * szServer) {LPHOSTENT lpHostEntry; lpHostEntry = gethostbyname (szServer); if (lpHostEntry == NULL) {printf ( "gethostbyname ( ) Error / N "); return;} Socket THSOCKET; THHESOCKET = Socket (AF_INET, SOCK_RAW, 255); if (THSOCKET == Invalid_socket) {Printf (" socket () error / n "); return;} int nret; BOOL optval; optval = TRUE; nRet = setsockopt (theSocket, IPPROTO_IP, IP_HDRINCL, (char *) & optval, sizeof (optval)); if (SOCKET_ERROR == nRet) {printf ( "! SetSockOpt Error% d / n", WSAGetLastError ());

} SOCKADDR_IN saServer; saServer.sin_family = AF_INET; saServer.sin_addr = * ((LPIN_ADDR) * lpHostEntry-> h_addr_list); // Let WinSock assign addresssaServer.sin_port = 0; // Use port passed from userchar szBuf [1024]; / / MEMSET (SZBUF, 0, SIZEOF (SZBUF)); int iphdrlen = 0; INT DATALEN = 0; IP_HEADER * PIPHDR = NULL; char * pdata = null; iphdrlen = sizeof (ip_header); piphdr = (ip_header *) szbuf; Piphdr-> h_verlen = (4 << 4) | (SizeOf (ip_header) / sizeof (unsigned long); pipHDR-> TOS = 0; piphdr-> proto = 255; piphdr-> ttl = 128; piphdr-> ident = = 0; piphdr-> checksum = 0; piphdr-> frag_and_flags = 0; piphdr-> sourceip = inet_addr ("1.1.1.1"); piphdr-> destip = (unsigned int) Saserver.sin_addr.s_addr; pdata = (SZBUF Iphdrlen; Printf ("Type A String:"); scanf ("% s", pdata); DATALEN = Strlen (PDATA); piphdr-> total_len = iphdrlen datalenten; // nret = sendto (THSOCKET, // SocketszBuf, // Data bufferIpHdrLen DataLen, // Length of data0, // Flags (LPSOCKADDR) & saServer, // Server addresssizeof (struct sockaddr));! // Length of addressif (nRet = SOCKET_ERROR) {printf ( "Client send :% s / n ", PDA TA);} getCH (); closSocket; Return;} RServer:

#include #include #include #include #include #pragma Comment (lib, "ws2_32.lib") Void Rawserver ); void main () {wsadata wsadata; wsaStartup (0x0202, & wsadata); Rawserver (); wsacleanup ();} // void Rawserver ()} // void Rawserver () {int NRET; SOCKET THSOCKET; THSOCKET = Socket (AF_INET, SOCK_RAW, 255); if (theSocket == INVALID_SOCKET) {printf ( "socket () error / n"); return;} SOCKADDR_IN saServer; saServer.sin_family = AF_INET; saServer.sin_addr.s_addr = INADDR_ANY; // Let WinSock assign addresssaServer.sin_port = 0 ; // Use port passed from usernRet = bind (theSocket, // Socket descriptor (LPSOCKADDR) & saServer, // address to bind tosizeof (struct sockaddr) // Size of address); if (nRet == SOCKET_ERROR) {printf ( " Bind () error / n "); CloseSocket (THSOCKET); return;} /// int Nlen; Nlen = Sizeof (SockAddr); char szbuf [1024]; nret = gethostname (SZBUF, SIZEOF (SZBUF)); IF NRET == SOCKET_ERROR) {Printf ("gethostname () error / n"); ClosSocket (THSOCKET); Return;} lphostent lphostentry; lphostentry = gethostByn AME (SZBUF); Printf ("Server NAMED% S / N / N", SZBUF, INET_NTOA (* (LPIN_ADDR) LPHOSTENTRY-> H_ADDR)); /// SockAddr_in saclient; Memset (SZBUF, 0, Sizeof szBuf)); nRet = recvfrom (theSocket, // Bound socketszBuf, // receive buffersizeof (szBuf), // Size of buffer in bytes0, // Flags (struct sockaddr *) & saClient, // Buffer to receive client address & nLen) ; // Length of Client Address Bufferif (NRET! = Socket_ERROR) {Printf ("Server Recv:% S / N", SZBUF 20);} else {printf ("Recv error:% d / n", wsagetlasterror () CLOSESOCKET (THSOCKET); RETURN;} getCH (); CloseSocket (THSOCKET); Return;}

Data transfer using JIURL255 is clearly a port without TCP and UDP, which will not be seen by a command such as NetStat -an. This is very like this and using ICMP to transfer data, but I think Jiurl255 is better than using ICMP data. It has a relatively large disadvantage that since it is directly used IP, the transmitted data is possible to lose, this is the note written after I observed: "Use the IP, IP header field to fill 255, This is a protocol number that has not been used yet. Then run the C, S program, c send IP255 packets on both hosts in the network, the content Hello N, the total 50, send one per second. S-IP255 report Wen, indeed received, in one test, 50 packets, received 49, and there is indeed IP newspaper lost. Two directions, it is feasible. "So use this method hidden port is Many of the strengths, I have written in a program, the transfer file uses some simple waiting ACK, and the mechanism for timeout retraction ensures that the data does not lose and errors, the command is transmitted, and there is no guarantee that it will not be lost. If you have time, you are ready to write a way to ensure that you are not lost, an incorrect transceiver function. Those mechanisms for transferring files, refer to the TFTP protocol that uses the UDP protocol for file reliable transmission. end

转载请注明原文地址:https://www.9cbs.com/read-85895.html

New Post(0)