Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old Apr 18th, 2006, 1:30 PM   #1
tamer1221
Newbie
 
Join Date: Apr 2006
Posts: 10
Rep Power: 0 tamer1221 is on a distinguished road
any help in sockets (i can`t enter the server)

#include <winsock.h>
#include <iostream.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#define DEST_IP "194.68.45.50"
#define DEST_PORT 6666

void main()
{
WSADATA wsaData;
char buf[2000];
int sockfd;
int len, bytes_recv;
char msg[2000] = "NICK omakhjfg";
char mss[2000] = "USER bot_lo 8 * :C IRC Hacks Robot";
len=sockfd=0;
struct sockaddr_in dest_addr;

if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0) {
cout<<"WSAStartup failed.\n";
exit(1);
}
sockfd = socket(AF_INET, SOCK_STREAM, 0);
dest_addr.sin_family = AF_INET; // host byte order
dest_addr.sin_port = htons(DEST_PORT); // short, network byte order
dest_addr.sin_addr.s_addr = inet_addr(DEST_IP);


connect(sockfd, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr));
bytes_recv = recv(sockfd, buf, 1999, 0);

buf[bytes_recv] = '\0';
cout<<buf<<"\n";

len = strlen(msg);
send(sockfd, msg, 1999, 0);
send(sockfd, "\r", 10, 0);
send(sockfd, mss, 1999, 0);
send(sockfd, "\r", 10, 0);

buf[bytes_recv] = '\0';
cout<<buf<<"\n";
closesocket(sockfd);

WSACleanup();
}
tamer1221 is offline   Reply With Quote
Old Apr 18th, 2006, 1:46 PM   #2
coldDeath
Expert Programmer
 
coldDeath's Avatar
 
Join Date: Aug 2005
Location: UK
Posts: 862
Rep Power: 4 coldDeath is on a distinguished road
Send a message via AIM to coldDeath Send a message via Yahoo to coldDeath
Oh my poor poor eyes,
A few points:
+You Need Code Tags
+Never use void main, use "int main()" and return 0 or 1.
+You are using deprecated headers. eg. iostream.h, it should be #include <iostream>

You've showed us some code, and? You haven't even asked a question.
__________________
Join us at #programmingforums @ irc.freenode.net!

My software never has bugs. It just develops random features.
coldDeath is offline   Reply With Quote
Old Apr 18th, 2006, 1:50 PM   #3
jayme
Professional Programmer
 
jayme's Avatar
 
Join Date: Nov 2005
Location: Canada
Posts: 495
Rep Power: 0 jayme is an unknown quantity at this point
Send a message via MSN to jayme
It looks like you found the oldest winsock code you could find and just strangled it. Why are you using winsock instead of winsock2?

If I was using your code, I would change it to look like so(up to the connection)...

#include <winsock2.h>
#include <iostream.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#define DEST_IP "194.68.45.50"
#define DEST_PORT 6666

int main()
{
WSADATA wsaData;
char buf[2000];
int sockfd;
int len, bytes_recv;
char msg[2000] = "NICK omakhjfg";
char mss[2000] = "USER bot_lo 8 * :C IRC Hacks Robot";
len=sockfd=0;
struct sockaddr_in dest_addr;

if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) {
cout<<"WSAStartup failed.\n";
exit(1);
}
if ((sockfd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) 
/* Make sure you have an error message so you know if this is the problem */
cout << "socket initialization failed";

dest_addr.sin_family = AF_INET; // host byte order
dest_addr.sin_port = htons(DEST_PORT); // short, network byte order
dest_addr.sin_addr.s_addr = inet_addr(DEST_IP);
memset(&(Remote_address.sin_zero), '\0', 8); // Zero out the rest of the struct


if (connect(sockfd, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr)) == -1)
/* Make sure you have an error message so you know if this is the problem */
cout << "connection failed";

EDIT: I lied, I would actually change all the code, but that's your job.
__________________

Quote:
Originally Posted by Mohamed Jihad
Durka durka!
Due to incorrect calculations during the middle ages, our calendar actually begins a few years after Jesus' birth. Thus the real 6/6/6 happened a few years back. The world already ended and you missed it.

Download Code::Blocks now!
jayme is offline   Reply With Quote
Old Apr 18th, 2006, 1:57 PM   #4
tamer1221
Newbie
 
Join Date: Apr 2006
Posts: 10
Rep Power: 0 tamer1221 is on a distinguished road
the problem that i can`t logon into irc.dal.net try it urself
tamer1221 is offline   Reply With Quote
Old Apr 18th, 2006, 2:14 PM   #5
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
Works for me.
#include <winsock.h>
#include <iostream>
#include <string>
#define DEST_IP "194.68.45.50"
#define DEST_PORT 6666

using namespace std;

int main()
{
	WSADATA wsaData;
	SOCKET sockfd;
	int len = 0, bytes_recv = 0;
	char buf[2048];
	string msg = "NICK omgrolfcopterlol";
	string mss = "USER bot_lo 8 * :C IRC Hacks Robot";
	struct sockaddr_in dest_addr;

	if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0)
	{
		cout << "WSAStartup failed." << endl;
		exit(1);
	}
	sockfd = socket(AF_INET, SOCK_STREAM, 0);
	dest_addr.sin_family = AF_INET;
	dest_addr.sin_port = htons(DEST_PORT);
	dest_addr.sin_addr.s_addr = inet_addr(DEST_IP);

	connect(sockfd, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr));
	bytes_recv = recv(sockfd, buf, 1999, 0);

	buf[bytes_recv] = '\0';
	cout << buf << endl;

	len = msg.length();
	send(sockfd, msg.c_str(), 1999, 0);
	send(sockfd, "\r", 10, 0);
	send(sockfd, mss.c_str(), 1999, 0);
	send(sockfd, "\r", 10, 0);

	buf[bytes_recv] = '\0';
	cout << buf << endl;
	closesocket(sockfd);

	WSACleanup();
	return 0;
}
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates

Last edited by nnxion; Apr 18th, 2006 at 2:29 PM. Reason: Using C++ strings
nnxion is offline   Reply With Quote
Old Apr 18th, 2006, 2:30 PM   #6
tamer1221
Newbie
 
Join Date: Apr 2006
Posts: 10
Rep Power: 0 tamer1221 is on a distinguished road
but it gives first two lines only which is 1) cheking identify 2)found your hostname
i want to send back my nickname but i can`t
tamer1221 is offline   Reply With Quote
Old Apr 18th, 2006, 2:35 PM   #7
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
You are quiting, it doesn't do much more than that. I didn't look very closely at what it was supposed to do. Rather fixed a bit of your deprecated code.
You do work according to this right?

Edit: you might also want to check this.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates
nnxion is offline   Reply With Quote
Old Apr 18th, 2006, 2:44 PM   #8
tamer1221
Newbie
 
Join Date: Apr 2006
Posts: 10
Rep Power: 0 tamer1221 is on a distinguished road
i know some of the irc rfc how can i send enter to the socket
tamer1221 is offline   Reply With Quote
Old Apr 18th, 2006, 6:02 PM   #9
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
Quote:
Originally Posted by tamer1221
i know some of the irc rfc
Before you begin you should probably most of it, or at least in the process.
Quote:
Originally Posted by tamer1221
how can i send enter to the socket
What does this mean? Read the rfc what you have to do to enter the server, and to change the nick.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates
nnxion is offline   Reply With Quote
Old Apr 19th, 2006, 1:33 AM   #10
tamer1221
Newbie
 
Join Date: Apr 2006
Posts: 10
Rep Power: 0 tamer1221 is on a distinguished road
i mean send return to the server
tamer1221 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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:48 AM.

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