LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-15-2006, 10:56 AM   #1
live_dont_exist
Member
 
Registered: Aug 2004
Location: India
Distribution: Redhat 9.0,FC3,FC5,FC10
Posts: 257

Rep: Reputation: 30
Wargame n/w programming problem


Hi All,
Was playing a war game...to improve my coding n stuff...heres the problem...

Code:
Your goal is to connect to port 5842 on
vortex.labs.pulltheplug.org and read in 4 unsigned integers. Add these integers together and send back the results to get a username and password for level 1. Note that vortex is on an x86 machine (meaning, a little endian architecture).
And here's my code.....but it isnt working...anything thats obviously wrong???...I didnt try the little endian stuff...coz Im using an X86 as well...

If Im in the wrong forum..can someone point me to a placve where I can discuss C Network programming..

Thnx
Arvind

Code:
#include <sys/socket.h>
#include <netinet/in.h>
#include <strings.h>
#include <stdlib.h>

int main()
{
  int sockfd=3;
  int n=0;int i=0;
  struct sockaddr_in servaddr;
  char str[14]="69.55.233.82";
  uint32_t buffer[500];
  uint32_t final=0;

  for (i=0; i<499; i++){
	buffer[i]=8888;
  }

  if ((sockfd=socket(AF_INET,SOCK_STREAM,0))<=0){
	 perror("Error creating socket");
	}
  bzero(&servaddr,sizeof(servaddr));
  servaddr.sin_family=AF_INET;
  servaddr.sin_port=htons(5842);

  if ((inet_pton(AF_INET,str,&servaddr.sin_addr))!=1){
	 perror("Error in inet_pton");
	 exit(0);
	}
  
  if (connect(sockfd,(struct sockaddr_in *)&servaddr,sizeof(servaddr))<0){
	 perror("Error in connect");
	 exit(0);
	}

  while ((n=read(sockfd,buffer,16)>0)){
	printf("Getting data %d\n",n);
	if (n==16){
		   printf("%d",n);
		   break;		
		}
	}

  final = buffer[0]+buffer[1]+buffer[2]+buffer[3]; 
  printf("FINAL %d" , final);
  n=0;
  /*while ((n=write(sockfd,&final,4)>0)){
	 if (n<0){
		 perror("Error in write function call");
//		 exit(0);
         }
	 if (n==4){
		printf("Successfully written data\n");
	 }
	 else{
		printf("%d\n",n);
	 }
	}
  /*for (i=0; i<12; i++){
	printf("%d\n",buffer[i]);
  } */
  return 0;
}

Last edited by live_dont_exist; 03-15-2006 at 10:58 AM.
 
Old 03-16-2006, 08:43 PM   #2
burntfuse
Member
 
Registered: Sep 2005
Location: Laurel, MD, USA
Distribution: Slackware 10.1, FC5
Posts: 164

Rep: Reputation: 30
I'm not an expert at socket programming (only done it a few times), but you could try a packet sniffer like Ethereal to see what's actually being received from the server and transmitted from your program.

BTW, what site is that from (the wargame, that is)?
 
Old 03-16-2006, 10:19 PM   #3
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
> BTW, what site is that from (the wargame, that is)?
http://pulltheplug.org
 
Old 03-16-2006, 11:14 PM   #4
live_dont_exist
Member
 
Registered: Aug 2004
Location: India
Distribution: Redhat 9.0,FC3,FC5,FC10
Posts: 257

Original Poster
Rep: Reputation: 30
Hi ,
Got a bit of help from the guys at (Yeah..pulltheplug) ..the forum...seems Id put in one loop too many(bad oversight)...n the code ws crashing....is fixed now...just post here ...incase U'd like 2 c the code...n how twas fixed...

Thnx
On to L1...
p.s...Burntfuse: ethereal wouldnt hav been helpful here..as I ws printing out the recv buffer n cud see it ws null...
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Qt Programming Problem chanwing Programming 7 04-20-2005 04:18 AM
Wargame Hints? the_p0et Linux - Security 3 10-19-2003 11:04 PM
another c programming problem Randall Programming 8 01-29-2003 04:45 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration