Here's some extra help: Sample Winsock code!
Code:
// Port Opener v1.1
// By: Steven Merrick
// For educational use only.
// Includes
#include <winsock.h>
#include <iostream>
// Variables
int port;
// Functions
int Winsock();
// Code
int main()
{
std::cout << "Input port to open: ";
std::cin >> port;
if (port > 65535) // Sanity Check.
{
std::cout << "\nInvalid port number, quitting.\n" << std::endl;
return(0);
}
Winsock(); // Calls Winsock().
std::cout << "\nPress any key to quit listening." << std::endl; // Program waits in "listening" state here until keypress.
std::cin.ignore(2, '\n');
WSACleanup(); // Cleans up and quits using Winsock. Do NOT forget this.
return(0);
}
int Winsock() // Calls the Winsock initalization and opens the port to "listening" state.
{
WSADATA WsaDat; // Not entirely sure, but is required. Appears to just hold our connection state.
SOCKET Socket; // What do we want to call our socket?
SOCKADDR_IN SockAddr; // Holds the data for our socket: type (sin_family), port (sin_port), and address (sin_addr.s_addr).
SockAddr.sin_family = AF_INET;
SockAddr.sin_port = htons(port); // Opens the specified port.
SockAddr.sin_addr.s_addr = inet_addr("127.0.0.1"); // Statically set address to bind to, localhost.
memset(&(SockAddr.sin_zero), '\0', 8); // Sets the remainder of the SockAddr struct to 0.
if (WSAStartup(MAKEWORD(1, 1), &WsaDat) != 0) // If the Winsock v1.1 startup fails..
{
std::cout << "WSA Initialization failed." << std::endl;
}
if ((Socket = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) // If the socket cannot be opened..
{
std::cout << "Socket creation failed." << std::endl;
}
if (bind(Socket, (SOCKADDR*)(&SockAddr), sizeof(SockAddr)) == SOCKET_ERROR) // If the socket cannot be bound to the port..
{
std::cout << "Attempt to bind failed." << std::endl;
}
listen(Socket, 1); // Sets the socket to listening state on the specified port number.
return(0);
}
This should help get you started as to what you need to do. You might also want to look into send() and recv(), as well as converting the domain name to IP.
But this should help get you started.