GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 15-Jan-2005, 14:07
shell6 shell6 is offline
New Member
 
Join Date: Jan 2005
Posts: 1
shell6 is on a distinguished road

In need of C++ sockets help


Ok, I checked my code, included the winsock lib in the build params, but it crashes on run. Can someone help me out with this?

CPP / C++ / C Code:
#include <winsock2.h>
#include <stdio.h>
#include <iostream.h>
#include <string.h>
int mirror(int s, char *input, int se)
{
	se = send(s, input, sizeof(input), 0);
	if(send != 0)
		return -1;
	else
		return 0;
}
struct rcon_strings { //remote command strings (not mirrored)
	char *shutdown;  // /admin/<password>/shutdown (kills server)
	char *flush;     // /admin/<password>/flush    (flushes *buffer)
};
int server()
{
	int sstart; // WSAStartup
	WORD ver; // version
	ver = MAKEWORD (2,2); // version number
	WSADATA wsaData;
	sstart = WSAStartup(ver, &wsaData);
	if(sstart != 0)
	{
		cout << "PANIC!: Could not run WSAStartup (00).\n";
		return 0;
	}
	rcon_strings rcon;
	struct sockaddr_in serv;
	int s; // socket
	int bi, list; // bind and listen
	int se, re; // send/recv vars
	int acce; // accept
        int mir; // mirror
	int i; // iterations
	char *buffer, *admin; // input buffer and admin password plus comparison
	serv.sin_family = AF_INET;
	serv.sin_port = htons(8060); // The server runs on 8060
	serv.sin_addr.s_addr = htonl(INADDR_ANY);
	cout << "Admin password: ";
	cin >> admin;
	rcon.shutdown = "/admin/";
	strcat(rcon.shutdown, admin);
	strcpy(rcon.shutdown, "/shutdown");
	rcon.flush = "/admin/";
	strcat(rcon.flush, admin);
	strcpy(rcon.flush, "/flush");
	s = socket(AF_INET, SOCK_STREAM, 0);
	if(s != 0)
	{
		cout << "PANIC!: Socket call failed (01).\n";
		return -1;
	}
	bi = bind(s, (struct sockaddr *)&serv, sizeof(serv));
	if(bi != 0)
	{
		cout << "PANIC!: Bind failed (02).\n";
		return -2;
	}
	list = listen(s, 6);
	if(list != 0)
	{
		cout << "PANIC!: Listen call failed (03).\n";
		return -3;
	}
	acce = accept(s, NULL, NULL);
	if(acce != 0)
	{
		cout << "PANIC!: Accept call failed (04).\n";
		return -4;
	}
	while(i == 0)
	{
		re = recv(s, buffer, sizeof(buffer), 0);
		if(buffer == rcon.shutdown)
		{
			cout << "rcon::shutdown has been used. Shutting down...\n";
			return 1;
		}
		if(buffer == rcon.flush)
		{
			cout << "rcon::flush has been used, buffer being flushed.\n";
			buffer = "";
		}
		else
			mirror(s, buffer, se);
	}
	// this will probably never happen
	return 2;
}
Last edited by dsmith : 17-Jan-2005 at 08:56. Reason: Please use [c] & [/c] for posting C code.
 
 

Recent GIDBlogDeveloping GUIs with wxPython (Part 3) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[PROGRAM] Winsock Programming Max Payne MS Visual C++ / MFC Forum 1 08-Mar-2007 23:38
Help on Sockets Lord_Kain MS Visual C++ / MFC Forum 4 13-Oct-2004 00:14
UDP Sockets between .NET and VS6 MikeZ MS Visual C++ / MFC Forum 2 19-Feb-2004 10:55

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 07:02.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.