ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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)?
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...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.