Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
15 years ago

Argument passing to C Main using Nios II IDE

Hi,

It would be very helpful if any of you can tell me If I can pass arguments to Main function in a C program using Nios II IDE, either using GUI or shell. I know how to run without arguments using both GUI and shell but I need help passing arguments.

Thanks,

Amjad

3 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I haven't done this myself, but in alt_main.c the arguments to main.c are passed.

    
    024: /*
    025:  * Standard arguments for main. By default, no arguments are passed to main.
    026:  * However a device driver may choose to configure these arguments by calling
    027:  * alt_set_args(). The expectation is that this facility will only be used by
    028:  * the iclient/ihost utility.
    029: */
    030: 
    031: int    alt_argc = 0;
    032: char** alt_argv = {NULL};
    033: char** alt_envp = {NULL};
    ...
    116:   main (alt_argc, alt_argv, alt_envp);
    

    What exactly are you trying to accomplish? If you're looking for input arguments, why not keep it simple and use scanf()?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi, Thanks for the prompt reply. I will try it out.

    I actually need to demonstrate buffer overflow attacks in embedded systems, which happens when you pass arguments with size more than the allotted memory.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I'm no security guru, but would a RPC suffice? Lots of embedded systems have TCP/IP stacks. I imagine RPCs are a simple way to control an embedded device.