//====================================================== file = rawsend.c ===== //= Program to demonstrate raw sockets for sending = //= - Appends message bytes directly following IP header = //============================================================================= //= Notes: = //= 1) This program compiles for Winsock only = //= 2) There is *no* error checking in this program. Error checking was = //= omitted to simplify the program. = //= 3) This program assumes that the destination host has its IP address = //= hardcoded into "#define IP_ADDR" = //=---------------------------------------------------------------------------= //= Build: bcc32 rawsend.c ws2_32.lib = //=---------------------------------------------------------------------------= //= History: KJC (08/17/01) - Genesis = //============================================================================= //----- Include files --------------------------------------------------------- #include // Needed for printf() #include // Needed for memcpy() and strcpy() #include // Winsock version 2 stuff //----- Defines --------------------------------------------------------------- #define IP_ADDR "131.247.2.215" // IP address of destination (HARDWIRED) //===== Main program ========================================================== void main(void) { WORD wVersionRequested = MAKEWORD(1,1); // Stuff for WSA functions WSADATA wsaData; // Stuff for WSA functions unsigned int dest_s; // Destination socket descriptor struct sockaddr_in dest_addr; // Destination Internet address int mess_len; // Message length char mess_buf[1024]; // 1024-byte buffer for message int i; // Loop counter // Initialize Winsock WSAStartup(wVersionRequested, &wsaData); // Create raw socket for destination dest_s = WSASocket(AF_INET, SOCK_RAW, IPPROTO_ICMP, 0, 0, 0); // Fill-in destination socket's address information dest_addr.sin_family = AF_INET; // Address family to use dest_addr.sin_addr.s_addr = inet_addr(IP_ADDR); // IP address to use // Assign message bytes to out_buf mess_len = 100; for (i=0; i