Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Socket problem

Status
Not open for further replies.

mattias1975

Programmer
Jul 26, 2004
36
SE
I have problem with sending stuff with sockets.
There seems to something wrong when i call the sendto function.
Does anyone know what it is?
Thank you.

Mattias Westerberg

#include <winsock2.h>
#include <wininet.h>
#include <stdio.h>
#include <conio.h>
#include <iostream.h>

void main(){

WORD wVersionRequested;
WSADATA wsaData;
int err;

wVersionRequested = MAKEWORD( 2, 2 );

err = WSAStartup( wVersionRequested, &wsaData );

if ( err != 0 ) {
cout << "could not find a usable WinSock DLL\n";
}

if ( LOBYTE( wsaData.wVersion ) != 2 ||
HIBYTE( wsaData.wVersion ) != 2 ) {
WSACleanup( );
cout << "could not find a usable WinSock DLL\n";
}

int sock = socket (PF_INET, SOCK_RAW, IPPROTO_TCP);

if (sock == SOCKET_ERROR)
cout << "Socket error!\n";

struct sockaddr_in name;

name.sin_family = AF_INET;
name.sin_addr.s_addr = inet_addr("213.67.159.89");
name.sin_port = htons(25);

char test[] = "bla bla bla";
cout << sizeof(test);

int s = sendto(sock, test, sizeof(test), 0 ,(struct sockaddr *) &name, sizeof(name));

if(s < 0)
cout << "Send error!\n";

}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top