Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 12th, 2006, 1:42 AM   #1
boraciner
Programmer
 
boraciner's Avatar
 
Join Date: Nov 2005
Location: Turkey
Posts: 93
Rep Power: 3 boraciner is on a distinguished road
web page - internet connection [Error] :(

I found these codes somewhere.. It takes a website adress and makes "index.html" after copied these source codes from the adress..but I can't compile it..
please help me..

#include <windows.h>
#include <winsock.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>



int main(void)
{
FILE *html;

int syc=0;

char	buf[]="GET\n\n";
unsigned char gelenveri[1000];
char adres[50];
char myadres[50];

WSADATA 	wsdata;
SOCKET s;

struct hostent *he;
struct sockaddr_in their_addr;

//#############################################################################
  HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE );
  WORD wOldColorAttrs;
  CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
  GetConsoleScreenBufferInfo(h, &csbiInfo);
  wOldColorAttrs = csbiInfo.wAttributes;

  SetConsoleTextAttribute ( h, FOREGROUND_GREEN |FOREGROUND_INTENSITY| 50);
  printf ("--------------------------------------------------------------------\n" );
  SetConsoleTextAttribute ( h, FOREGROUND_RED | FOREGROUND_INTENSITY | 50); //FOREGROUND_INTENSITY );
  printf ("--------------------------- bycodec loader -------------------------\n" );
  //SetConsoleTextAttribute ( h, wOldColorAttrs);
  SetConsoleTextAttribute ( h,  FOREGROUND_GREEN | FOREGROUND_INTENSITY | 50);
  printf ("------------------------- by-codec@hotmail.com ---------------------\n\n\n" );
  SetConsoleTextAttribute ( h, FOREGROUND_RED | FOREGROUND_INTENSITY );
//#############################################################################

WSAStartup(MAKEWORD(2,0),&wsdata);



printf(" hostname  : ");
SetConsoleTextAttribute ( h, FOREGROUND_GREEN | FOREGROUND_INTENSITY );
scanf("%s",myadres);
html = fopen("index.html","w");
if((he = gethostbyname(myadres))== NULL){
	printf("gethostbyname error !!!");
   system("pause");
   exit(-1);
   }

their_addr.sin_family	= AF_INET;
their_addr.sin_port     = htons(80);
their_addr.sin_addr 	= *((struct in_addr *)he->h_addr);
memset(&(their_addr.sin_zero),'\0',8);

s=socket(AF_INET,SOCK_STREAM,0);
if(s<0){
	printf("soket hatasi");
   system("pause");
   exit(-1);
   }

if((connect(s,(struct sockaddr *)&their_addr,sizeof(struct sockaddr))) == -1){
	printf("baglanti hatasi\n\n");
   system("pause");
   exit(-1);
   }                   //

if((send(s,buf,strlen(buf),0))== -1){
	printf("veri gönderme hatasi");
   system("pause");
   exit(-1);
   }
SetConsoleTextAttribute ( h, FOREGROUND_BLUE | FOREGROUND_INTENSITY );
printf("\n\n\n\n");
printf("###########################################################################\n\n");

for(;;){
if((recv(s,gelenveri,1000,0)) == 0){
   fclose(html);
   WSACleanup();
   printf("\n\n\n\n\n");
   SetConsoleTextAttribute ( h, FOREGROUND_RED | FOREGROUND_INTENSITY );
   printf("program basarIyLa sonlandI\nindex.html yaratILdI...\CIkmak icin bi tusa basIn ");
   SetConsoleTextAttribute ( h, FOREGROUND_BLUE | FOREGROUND_INTENSITY );
   printf("\n\n\n\n");
   printf("###########################################################################\n\n");

   getch();
   exit(-1);
   }
//-------------------------- </HTML>

//--------------------------
fputs(gelenveri,html);
SetConsoleTextAttribute ( h, FOREGROUND_GREEN | FOREGROUND_INTENSITY | 45 );
printf("%s",gelenveri);
memset(gelenveri,'\0',1000);
}





return 0;
}


DevCpp

Compiler: Default compiler
Executing  g++.exe...
g++.exe "C:\Documents and Settings\Ciner\Desktop\bycodec\bycodecserver.cpp" -o "C:\Documents and Settings\Ciner\Desktop\bycodec\bycodecserver.exe"    -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include"  -I"C:\Dev-Cpp\include\c++\3.4.2\backward"  -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32"  -I"C:\Dev-Cpp\include\c++\3.4.2"  -I"C:\Dev-Cpp\include"   -L"C:\Dev-Cpp\lib" 
C:\Documents and Settings\Ciner\Desktop\bycodec\bycodecserver.cpp: In function `int main()':
C:\Documents and Settings\Ciner\Desktop\bycodec\bycodecserver.cpp:86: error: invalid conversion from `unsigned char*' to `char*'

C:\Documents and Settings\Ciner\Desktop\bycodec\bycodecserver.cpp:86: error:   initializing argument 2 of `int recv(SOCKET, char*, int, int)'
C:\Documents and Settings\Ciner\Desktop\bycodec\bycodecserver.cpp:91:11: warning: unknown escape sequence '\C'
C:\Documents and Settings\Ciner\Desktop\bycodec\bycodecserver.cpp:102: error: invalid conversion from `unsigned char*' to `const char*'
C:\Documents and Settings\Ciner\Desktop\bycodec\bycodecserver.cpp:102: error:   initializing argument 1 of `int fputs(const char*, FILE*)'

Execution terminated

Borland Shows more than that...


boraciner is offline   Reply With Quote
Old Sep 12th, 2006, 3:15 AM   #2
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 825
Rep Power: 4 The Dark is on a distinguished road
Those errors seem pretty straightforward.
Delete the red bit in this code:
unsigned char gelenveri[1000];

Fix up the \C to a proper escape sequence in this code (did you mean \nC ?):
   printf("program basarIyLa sonlandI\nindex.html yaratILdI...\CIkmak icin bi tusa basIn ");
The Dark is offline   Reply With Quote
Old Sep 12th, 2006, 8:48 AM   #3
boraciner
Programmer
 
boraciner's Avatar
 
Join Date: Nov 2005
Location: Turkey
Posts: 93
Rep Power: 3 boraciner is on a distinguished road
I fixed these errors but it didn't work again...
Compiler: Default compiler
Executing  g++.exe...
g++.exe "C:\Documents and Settings\Ciner\Desktop\bycodec\bycodecserver.cpp" -o "C:\Documents and Settings\Ciner\Desktop\bycodec\bycodecserver.exe"    -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include"  -I"C:\Dev-Cpp\include\c++\3.4.2\backward"  -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32"  -I"C:\Dev-Cpp\include\c++\3.4.2"  -I"C:\Dev-Cpp\include"   -L"C:\Dev-Cpp\lib" 
C:\DOCUME~1\Ciner\LOCALS~1\Temp/ccEBaaaa.o(.text+0x124):bycodecserver.cpp: undefined reference to `WSAStartup@8'
C:\DOCUME~1\Ciner\LOCALS~1\Temp/ccEBaaaa.o(.text+0x187):bycodecserver.cpp: undefined reference to `gethostbyname@4'
C:\DOCUME~1\Ciner\LOCALS~1\Temp/ccEBaaaa.o(.text+0x1d2):bycodecserver.cpp: undefined reference to `htons@4'
C:\DOCUME~1\Ciner\LOCALS~1\Temp/ccEBaaaa.o(.text+0x22c):bycodecserver.cpp: undefined reference to `socket@12'
C:\DOCUME~1\Ciner\LOCALS~1\Temp/ccEBaaaa.o(.text+0x255):bycodecserver.cpp: undefined reference to `connect@12'
C:\DOCUME~1\Ciner\LOCALS~1\Temp/ccEBaaaa.o(.text+0x2ad):bycodecserver.cpp: undefined reference to `send@16'
C:\DOCUME~1\Ciner\LOCALS~1\Temp/ccEBaaaa.o(.text+0x332):bycodecserver.cpp: undefined reference to `recv@16'
C:\DOCUME~1\Ciner\LOCALS~1\Temp/ccEBaaaa.o(.text+0x34d):bycodecserver.cpp: undefined reference to `WSACleanup@0'
collect2: ld returned 1 exit status

Execution terminated


will it work ???
boraciner is offline   Reply With Quote
Old Sep 12th, 2006, 7:57 PM   #4
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 825
Rep Power: 4 The Dark is on a distinguished road
You need to link with the library that has those functions in it. In this case you need to link with wsock32.lib
The Dark is offline   Reply With Quote
Old Sep 13th, 2006, 12:49 AM   #5
boraciner
Programmer
 
boraciner's Avatar
 
Join Date: Nov 2005
Location: Turkey
Posts: 93
Rep Power: 3 boraciner is on a distinguished road
ok .. I'm trying to find this library..

thank you again.
If I have a question ,I'll write there ...

thanks a lot
boraciner is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB 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
PHP sessions/ page refresh??? ktsirig PHP 2 Jun 1st, 2006 4:16 PM
PySite - Web Development Framework Sane Python 15 Mar 27th, 2006 7:39 PM
Internet Connection Sharing problem(FC3) InfoGeek Coder's Corner Lounge 4 Mar 5th, 2006 7:43 AM
Internet connection Writlaus Python 20 Feb 27th, 2006 4:13 AM
Page Replacement Program (C++) redhatter Existing Project Development 1 Nov 20th, 2005 10:38 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:03 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC