LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 09-12-2005, 09:57 PM   #1
SeniorSE
LQ Newbie
 
Registered: Nov 2004
Posts: 14

Rep: Reputation: 0
Question How to compile a C program in Fedora Core 4


Hi. I am trying to compile a C program. I have a program that has already been written and am trying to make changes to it. My problem is that I have no idea how to compile a C program on Linux. I have tried running:

Code:
g++ -I. -o mdhkarma mdhkarma.c
I got the following output:

Code:
mdhkarma.c: In function ‘void on_probe_req(const unsigned char*, const at_frame_info_t*)’:
mdhkarma.c:62: error: invalid conversion from ‘void*’ to ‘char*’
mdhkarma.c:107: error: invalid conversion from ‘void*’ to ‘sta*’
mdhkarma.c:108: error: invalid conversion from ‘void*’ to ‘sta_t*’
mdhkarma.c:115: error: ‘UNKNOWN’ was not declared in this scope
mdhkarma.c:157: error: invalid conversion from ‘void*’ to ‘ssid*’
Here is a copy of the C program that I am trying to compile:

mdhkarma.c
Code:
/*
 * KARMA Attacks Radioed Machines Automatically
 *
 * Dino Dai Zovi <ddz@theta44.org>
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <assert.h>

#include <sys/types.h>

#include "airtap.h"
#include "karma.h"

struct sta* sta_list = NULL;

static void dump_sta_info(sta_t* sta)
{
    struct ssid* s;
    
    fprintf(stderr, "STA 0x%.8x %d", sta->staid, sta->state);
    
    for (s = sta->probed_networks; s; s = s->next)
        fprintf(stderr, " %s(%d)", s->ssid, s->seq);

    fprintf(stderr, "\n");
}

void on_probe_req(const unsigned char* f, const at_frame_info_t* frame_info)
{
    struct at_wifi_frame* frame =
        (struct at_wifi_frame*)f;
    const char* body = (char*)f + sizeof(struct at_wifi_frame);

    char* ssid;
    unsigned int staid;
    u_int16_t seq;

    struct ssid** s;
    struct sta** sta_iter;
    struct sta* sta_entry = NULL;
    sta_t* sta = NULL;
    int do_update = 0;
    size_t ssid_len;
    
    /*
     * Probe request is:
     * SSID, Supported rates
     */

    assert(body[0] == 0);

    ssid_len = (size_t)body[1];
    
    if (ssid_len == 32) {    /* Garbage probe requests */
	ssid = strdup("<random>");
    }
    else if (ssid_len > 0) {
        ssid = malloc(ssid_len + 1);
        strncpy(ssid, &body[2], body[1]);
        ssid[ssid_len] = '\0';
    }
    else {
        ssid = strdup("<broadcast>");
    }

    
/*********  Begin New Code by MDH   *********************/
int system (const char *command);

int ifconfig;

ifconfig = system("ifconfig wlan0 down");


    /*
     * addr2 is STA address
     */

    memcpy(&seq, &frame->sequence_control, sizeof(seq));
    seq = (seq & 0xfff0) >> 4;
    
    staid =
        (frame->address2[2] << 24) |
        (frame->address2[3] << 16) |
        (frame->address2[4] << 8) |
        (frame->address2[5]);

    /*
     * Find station entry in list
     */
    for (sta_iter = &sta_list; *sta_iter; sta_iter = &((*sta_iter)->next)) {
        if (((*sta_iter)->sta)->staid == staid) {
            sta_entry = *sta_iter;
            *sta_iter = (*sta_iter)->next;
            break;
        }
    }

    /*
     * Allocate a new one if it wasn't found
     */
    if (!sta_entry) {
        sta_entry = malloc(sizeof(struct sta));
        sta_entry->sta = malloc(sizeof(sta_t));

        sta_entry->sta->staid = staid;
        memcpy(&(sta_entry->sta->mac), &(frame->address2), 6);
        
        sta_entry->sta->last_seq = sta_entry->sta->signal = 0;
        
        sta_entry->sta->state = UNKNOWN;
        sta_entry->sta->probed_networks = NULL;

        do_update = 1;
    }
    
    /*
     * Update station information
     */
    sta = sta_entry->sta;
    sta->last_seq = seq;
    if (frame_info) {
        sta->signal = frame_info->signal;
    }
    

    /*
     * Find SSID in this station's probed networks list and add it if
     * it wasn't found.
     */
    for (s = &(sta->probed_networks); *s; s = &(*s)->next) {
	fprintf(stdout, "SSID: %s\n", (*s)->ssid);
	fflush(stdout);

        if (strcmp((*s)->ssid, ssid) == 0) {
            /*
             * Move to front
             */
            struct ssid* s2 = *s;

            (*s) = (*s)->next;
            s2->next = sta->probed_networks;
            sta->probed_networks = s2;
            s = &(sta->probed_networks);
            
            break;
        }
    }

    if (*s == NULL) {
        struct ssid* s2;
        
        if ((s2 = malloc(sizeof(struct ssid))) == NULL) {
            perror("on_probe_req: malloc");
        }
        
        s2->next = sta->probed_networks;
        s2->ssid = strdup(ssid);
        s2->seq = seq;

        sta->probed_networks = s2;
        
        s = &(sta->probed_networks);

        do_update = 1;
    }
    else {
        (*s)->seq = seq;
    }

    /*
     * Put station entry back in list
     */
    sta_entry->next = sta_list;
    sta_list = sta_entry;
    
    free(ssid);
    
    /* dump_sta_info(sta); */

    /*
     * When there is no network around and a room full of laptops,
     * there is a Probe Request storm and we want to be conservative
     * about when we do screen updates.
     */
    
    /* if (do_update) */
}

int main(int argc, char* argv[])
{
    airtap_open(argv[1]);
    
    /*
     * Install hooks
     */
    airtap_add_hook(AT_TYPE_MGMT,
                    AT_MGMT_SUBTYPE_PROBE_REQ,
                    AT_DIR_NODS,
                    on_probe_req);

    /*
     * Deliver justice.
     */
    return airtap_loop();
}
There are a couple of other .c files and .o files as well. I don't know what to do with them. I can see where they are called in the above program, but I don't know what to do to make it all compile.

Any help you can give would be greatly appreciated. As you can tell, I am a newbie to Linux. Thanks.

Mark
 
Old 09-12-2005, 10:06 PM   #2
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
For starters take a look here:

http://www.linuxquestions.org/questi...ticle&artid=33


The g++ command is used for c++ programs. Use 'gcc' instead.

All the .c files will have to be compiled into .o files. Then the .o files lined together to form an executable. Either put all the .c files on the compile line or compile with the -c option then call the compiler (linker) again and pass all the .o files on the same line.
Code:
gcc file1.c file2.c file3.c

or 

gcc -c file1.c
gcc -c file2.c
gcc -c file3.c
gcc -o file file1.o file2.o file3.o
 
Old 09-13-2005, 03:05 AM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
easiest way,


assuming you have make

do:
make mdhkarma
and it will compile it into a file called mdhkarma

the errors you are getting are due to problems with your source file
 
Old 09-13-2005, 09:20 PM   #4
SeniorSE
LQ Newbie
 
Registered: Nov 2004
Posts: 14

Original Poster
Rep: Reputation: 0
Thanks. I got that working. Now I just have to get the program to do what I want it to. :-)

I made a Makefile that allows me to quickly compile and build the program.

Thanks again for you help!

Mark
 
  


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
Fedora Core 4, source compile kernel 2.6 (jane) fr0zen Fedora 2 11-08-2005 06:45 PM
GCC 2.95.3 won't compile, Fedora Core 4 x86_64 slantoflight Linux - Software 3 08-31-2005 07:21 PM
compile( gcc-g77) fortran with fedora core 3 gambato79 Programming 1 05-06-2005 12:49 PM
How to compile and run C codes in Fedora Core? hoper Programming 1 11-03-2004 01:53 PM
Trying to compile libgda-1.1.4.. Fedora Core 2 j3di3 Linux - Software 0 06-16-2004 11:17 AM

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

All times are GMT -5. The time now is 03:18 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