PDA

View Full Version : Need this compiled properly.


Mr.EoniX
31-08-2005, 20:08
I have made this code to have my router ident with my nick in all situations - The code is fine - i just need it compiled for the Asus WL500G deluxe.

Please someone do this for me.


#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdio.h>
#include <unistd.h> /* close */
#include <signal.h>

#define SUCCESS 0
#define ERROR 1

#define SERVER_PORT 113


int sock;

void dead (void) {
printf("We died.\n");
close(sock);
exit(1);
}

int main (int argc, char *argv[]) {

int sd, cliLen, i, pid;

struct sockaddr_in cliAddr, servAddr;
char buf[128];
char request[32];

fork();

signal(SIGTERM,(void *)dead);
signal(SIGINT, (void *)dead);
signal(SIGSEGV,(void *)dead);
signal(SIGALRM,(void *)dead);

/* create socket */
sd = socket(AF_INET, SOCK_STREAM, 0);
if(sd<0) {
perror("Cannot open socket");
return ERROR;
}

/* bind server port */
servAddr.sin_family = AF_INET;
servAddr.sin_addr.s_addr = htonl(INADDR_ANY);
servAddr.sin_port = htons(SERVER_PORT);

if(bind(sd, (struct sockaddr *) &servAddr, sizeof(servAddr))<0) {
perror("Cannot bind port");
return ERROR;
}

listen(sd,5);

while(1) {

printf("%s: waiting for data on port TCP %u\n",argv[0],SERVER_PORT);

cliLen = sizeof(cliAddr);
sock = accept(sd, (struct sockaddr *) &cliAddr, &cliLen);
if(sock<0) {
perror("Cannot accept connection");
return ERROR;
}

memset(buf,0x00,128);
if(read(sock, buf, 30) == ERROR) {
perror("Error reading from socket");
return ERROR;
}

for (i=0;i<=30;i++)
if (buf[i] == '\n' || buf[i] == '\r') {
buf[i] = '\0';
break;
}

printf("Received from %s: %s\n", inet_ntoa(cliAddr.sin_addr), buf);

sprintf(buf,"%s%s", buf ," : USERID : UNIX : eonix\r\n");
write(sock,buf,strlen(buf));
close(sock);

}

}



Hope you guys with the right compiling environment will help me out here.

Thank you in advance

EoniX

Jean-Fabrice
31-08-2005, 21:53
I think you should install your own env, using coolinux, it's really easy.
Anyway, here is your binary ;)

JF

Mr.EoniX
04-09-2005, 09:08
Thank you VERY much!

Ill get back to making my own env later on - no time right now

And btw - the ident works perfectly! - Thank you.