Røçkåfë££ë® §kåñK's WCS

Discuss the world of file sharing, from philosophy to help with applications.

Moderator: CricketMX Forum Moderators

Røçkåfë££ë® §kåñK
Greenhorn
Greenhorn
Posts: 24
Joined: Sun Feb 15, 2009 1:26 pm

All of it is written in C.
:)
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

Røçkåfë££ë® §kåñK, no nothing is wrong. Sorry if it came across that way :oops:

I'm glad it is C because I was writing something in C the other day and hit a hurdle, maybe you have an idea. I want the program to access a URL (ie. http://example.com/page2.html) and simply output true (if the page exists) or false (if it has a 404 error). I figured I needed to open a socket and then send a request to the server... but I've never dealt with sockets before. So I have some idea of the concept behind it but no idea of the code required.

Have you got any thoughts on this? Thanks :)
CricketMX.com in 2022: Still the home of bat's, rat's and other farmyard animals!

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
Røçkåfë££ë® §kåñK
Greenhorn
Greenhorn
Posts: 24
Joined: Sun Feb 15, 2009 1:26 pm

Firstly I'll presume you writing in Windows not Linux. (commented those lines that would need changing)
Well I've not played with access to websites really but something like:

Code: Select all

#include <winsock2.h>

BOOL WebsiteValid(char* websiteaddress)
{
	struct hostent* host = gethostbyname(websiteaddress);
	if (!host)
	{
		return 0;
	}
	if (!host->h_addr_list[0])
	{
		return 0;
	}
	struct sockaddr_in SockAddr;
	SockAddr.sin_family = AF_INET;
	SockAddr.sin_port = htons(80);
	SockAddr.sin_addr.S_un.S_addr = *(DWORD*)host->h_addr_list[0];   // WINDOWS
	SOCKET sock = socket(AF_INET, SOCK_STREAM, 0);
	if (connect(sock, (struct sockaddr*)&SockAddr, sizeof(struct sockaddr)))
	{
		close(sock);
		return 0;
	}
	
	close(sock);
	return 1;
}
I think.
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

I am writing it for Unix actually (Mac, not too fussed about Linux ... but there's no reason why it wouldn't work on both). I'm guessing winsock2.h won't work on Unix?

Also, does gethostbyname() work for URL's or only for domain names? Because it might try a DNS lookup and find the site is there without actually checking that particularly URL.

Thanks for this, I do appreciate it :)
CricketMX.com in 2022: Still the home of bat's, rat's and other farmyard animals!

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
Røçkåfë££ë® §kåñK
Greenhorn
Greenhorn
Posts: 24
Joined: Sun Feb 15, 2009 1:26 pm

That is true.

In that case try:

Code: Select all

#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h> 

BOOL WebsiteValid(char* websiteaddress)
{
   struct hostent* host = gethostbyname(websiteaddress);
   if (!host)
   {
      return 0;
   }
   if (!host->h_addr_list[0])
   {
      return 0;
   }
   struct sockaddr_in SockAddr;
   SockAddr.sin_family = AF_INET;
   SockAddr.sin_port = htons(80);
   SockAddr.sin_addr.s_addr = *(DWORD*)host->h_addr_list[0];
   SOCKET sock = socket(AF_INET, SOCK_STREAM, 0);
   if (connect(sock, (struct sockaddr*)&SockAddr, sizeof(struct sockaddr)))
   {
      close(sock);
      return 0;
   }
   
   char PageRequest[1024];
   sprintf(PageRequest, "GET %s HTTP/1.0\n\n", websiteaddress);
   send(sock, PageRequest, strlen(PageRequest), 0);
   
   char* header = (char*)malloc(10);
   memset(header, 0, 10);
   int ret = recv(sock, header, 1, 0);
   close(sock);
   if (ret == 1)
   {
      return 1;
   }
   else
   {
      return 0;
   }
}
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

Thanks, I have compiled it. Only thing I changed was the function type from BOOL to int.

Code: Select all

testUp.c: In function ‘WebsiteValid’:
testUp.c:7: warning: initialization makes pointer from integer without a cast
testUp.c:12: error: dereferencing pointer to incomplete type
testUp.c:19: error: ‘DWORD’ undeclared (first use in this function)
testUp.c:19: error: (Each undeclared identifier is reported only once
testUp.c:19: error: for each function it appears in.)
testUp.c:19: error: syntax error before ‘)’ token
testUp.c:20: error: ‘SOCKET’ undeclared (first use in this function)
testUp.c:21: error: ‘sock’ undeclared (first use in this function)
testUp.c:28: warning: incompatible implicit declaration of built-in function ‘sprintf’
testUp.c:29: warning: incompatible implicit declaration of built-in function ‘strlen’
testUp.c:31: warning: incompatible implicit declaration of built-in function ‘malloc’
testUp.c:32: warning: incompatible implicit declaration of built-in function ‘memset’
Some of these errors are a bit strange. For instance, it is looking at SOCKET and DWORD as variables and not data types.

It's mainly warnings, the only errors seem to be coming from around:

Code: Select all

  SockAddr.sin_addr.s_addr = *(DWORD*)host->h_addr_list[0];
   SOCKET sock = socket(AF_INET, SOCK_STREAM, 0);
   if (connect(sock, (struct sockaddr*)&SockAddr, sizeof(struct sockaddr)))
I am not sure what about this line is causing problems:

Code: Select all

struct hostent* host = gethostbyname(websiteaddress);
A look at the man page (http://linux.die.net/man/3/gethostbyname) suggests that the line is fine :?
CricketMX.com in 2022: Still the home of bat's, rat's and other farmyard animals!

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
Røçkåfë££ë® §kåñK
Greenhorn
Greenhorn
Posts: 24
Joined: Sun Feb 15, 2009 1:26 pm

Try using the include file

Code: Select all

#include <netdb.h>
as well as/instead of

Code: Select all

#include <netinet/in.h>
That should fix some of the errors (sorry i really only programme for Windows :/ )

As for the DWORD and SOCKET data types, again i do not know the unix includes! Try perhaps

Code: Select all

typedef unsigned long DWORD;
typedef int SOCKET;
Good luck
Røçkåfë££ë® §kåñK
Greenhorn
Greenhorn
Posts: 24
Joined: Sun Feb 15, 2009 1:26 pm

R§WCS
Release: 1.9.5:1
Release Date: 06/01/2010

Changelog
* Fixed a bug with the plugin gui implementation when loading plugins post-runtime. Previously the "Help"
menu option was overwritten by the "Plugins" menu and also the plugins were not correctly initialised.
* Corrected the server message output in the new /online /offline command.
* Fixed a bug with the plugin OnUserJoin. Previously this prevented anyone being able to enter.
* Fixed a bug with the server gui. The primary connections were not set to offline when the server was set
to offline via the task tray right click menu.
User avatar
p2p-sharing-rules
Moderator
Moderator
Posts: 8462
Joined: Mon Mar 29, 2004 6:55 pm
Location: Canada

Thanks for the update richy. :)
You can find plugins for R§WCS on The Rebellion here.
Røçkåfë££ë® §kåñK
Greenhorn
Greenhorn
Posts: 24
Joined: Sun Feb 15, 2009 1:26 pm

R§WCS
Release: 1.9.5.2
Release Date: 21/02/2010

Changelog
* Added ShowChatHistory= in the config. Should be set to a number between 0 and 10. This is the
number of lines of chat history displayed to the newly entering user. Default is 0 (i.e. off).
* Fixed ShowChatHistory= so that the history is stored all the time and only displayed when the feature is
set on. Previously history was only saved once the feature was turned on.
* Fixed a bug with the MOTD. When it was not set, the server still sent some blank newlines.
* All plugin UI has been disabled as there have been unconfirmed reports of issues arising when plugins are
loaded for any period of time. This will remain the case until I have had chance to look into these reports
and confirm and fix the issues.
* Fixed ShowChatHistory= so that text is displayed as formatted as per in channel.
Please note: word replaces and newlines are NOT replaced in this section of text.
* Added a complex time calculator to ShowChatHistory= that removes chat history if it is older than 2 hours.
This way of doing it should capture any roll over of days/months/years/decades/millennia!!!
* Changed how the version number is set to simplify it for myself!
Now only needs changing in 1 place in the source.
User avatar
p2p-sharing-rules
Moderator
Moderator
Posts: 8462
Joined: Mon Mar 29, 2004 6:55 pm
Location: Canada

Thanks for the update Richy.
Røçkåfë££ë® §kåñK
Greenhorn
Greenhorn
Posts: 24
Joined: Sun Feb 15, 2009 1:26 pm

R§WCS
Release: 1.9.5.3
Release Date: 17/12/2010

Changelog
* Fixed a visual bug with very long stay times, idle times and wpn connection times when formatted and displayed
in the /stats <username> server output. Now using the same timer counter style as the ChatHistory feature
added in 1.9.5.2 so no more issues i hope!
* Fixed the server support and handling of the Emulator Protocol Chat Extension so it now sends all users statuses
and personal messages to users who enter. Previously just sent them when they changed.
* Fixed an issue I have been looking into for a while with cycling colour codes.
If the first message sent in room by a new user contained a cycle colour code in certain conditions it may have
caused the server to crash!
* Fixed a visual bug with stay times in /ranking (and the GUI output of /ranking). Now using the same timer
counter style as the ChatHistory feature added in 1.9.5.2
* Added newline support in ChatHistory. Now shows the chat history as seen in room.
* Removed the blank lines sent before and after ChatHistory.
* Removed the #cr# code from the ChatHistory outputs.
* Fixed cloning of user names in the userlist in Password'ed rooms.
* Moved the 3.53 server packet (0x0068), the colour code definition packet (0x9904), the server menu query packet
(0x9907), the Emulator protocol extension support query packet (0x3400), the IPSend query packet (0x9900) and the
server identification (0x9905) to pre-password entry.
* Removed the built in Winamp Display option in the config loading function (test feature I forgot to remove sorry!).
* Fixed /action and /emote text to display in server the same as /me text.
* Added a timer to the ban dispay message so that ! access users are not spammed with server messages if a banned user
repeatedly attempts to enter. Timer is 1 display message every 10 seconds.
* Now cleaned up the primary socket data held in memory when the server is set to offline while it had been running
online (a hangover from WCS primary handling).
* Fixed a bug with how the server dealt with long 3.31 protocol packet action text sent to server.
* Added the hostname and countryname to join information saved in the logs.
* Added a cleanup section to all primary cache sockets, all client sockets and the server listening socket when created
to avoid any TIME_WAIT or FIN_WAIT hangs when closed.
* Changed how the reload button works to avoid having to write the command to "exec.txt" file and the read it, should now
be cleaner and work better.
* Also changed how the usermenu in the server window sends commands, now sent the same way as the Reload button (as above).
* Tidied up the random colour codes appearance in the coloured chat window.
* Fixed initial userlist sent to users on entry for normal users from 0x006F to 0x0072 for all 3.53 protocol clients entering.
* Introduced a new style of IP to Country Databases compiled by myself. This will allow new updated versions made
specifically for R§WCS to be loaded which will be timestamp (backwards compatible to allow older WCS ipdb.dat files to work)
* Changed how the server checks the host ip. Now it will automatically update the room hash and host ip if you lose connection
and continue using the server.
* Fixed a possible exploit that allowed users with the correct access to be available to make the server list every password loaded
into the server from the config, including passwords with higher access than theirs. This affected WCS up to and including 1.8.7
* Added back the plugin support with some small changes, plus some extra server call functions to access further info.
* Cleaned up the loading and unloading of plugins.
* Auto-Load of plugins on startup now happens after the server is setup (previously was during server startup and
therefore could cause some issues with the setup process)
* Tidied up the code for Windows compiled versions.
* Tidied up the code and tweaked some bits to work better in Linux.
Now compiling debugging and compiling R§WCS-Linux on Ubuntu 10.04 LTS ("Lucid Lynx"). Seems to require a charset of ISO-8859-1
in the terminal to correctly display ascii text. Still seems to not pick up certain characters correctly.
* Fixed some console outputs in R§WCS-Linux which previously displayed colour codes.
Please Note: I will now be releasing updated ipdb.dat files on a monthly cycle (if possible) from around the beginning of the month so please check regularly.

Download links R§WCS 1.9.5.3
Attachments
R§WCS 1.9.5.3.rar
(994.54 KiB) Downloaded 570 times
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

Thanks for the update Røçkåfë££ë® §kåñK, 2011 will mark 3 years of development on WCS won't it? Congratulations :D
CricketMX.com in 2022: Still the home of bat's, rat's and other farmyard animals!

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
Post Reply