Thread: run time error

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    245
    Rep Power
    11

    run time error


    /* THE CODE BELOW CAUSES A RUN TIME ERROR */
    system ("ifconfig eth1 \"$ETH1\" netmask 255.255.255.0");

    ==================================
    root:~# ./test-small-network-sh-2
    aaaaa
    No address associated with name
    ifconfig: `--help' gives usage information.
    ==================================

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

    /*******************************************/

    int main()
    {
    FILE *f, *panic_file, *fopen();
    FILE *file_pointer;

    file_pointer = popen("ifconfig eth0 up", "r");
    file_pointer = popen("echo -e \"aaaaa\"", "w");

    f = popen ("ETH0=DHCP", "r");
    f = popen ("ETH1=10.0.1.1", "r");
    f = popen ("NETMASK=", "r");
    f = popen ("BROADCAST=", "r");
    f = popen ("GATEWAY=127.0.0.1", "r");

    f = popen ("source /etc/yellowbox/network-config", "r");

    panic_file = fopen ("/proc/sys/kernel/panic", "w");
    putc ('5', panic_file);

    f = popen ("ifconfig lo 127.0.0.1", "r");
    f = popen ("ifconfig eth0 up", "r");

    /* THE CODE BELOW CAUSES A RUN TIME ERROR */
    system ("ifconfig eth1 \"$ETH1\" netmask 255.255.255.0");

    pclose (f);
    pclose (file_pointer);
    fclose (panic_file);
    }
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,086
    Rep Power
    2222
    Looks like it's the old shell game again.

    When you open a new shell and create shell variables, those variables only exist within that shell's environment. When you close the shell, they go away. It's somewhat like creating local variables within a C function; they only exist within that function and cease to exist when you exit the function.

    popen opens a new shell, as does system. You'll need to find a more persistent way to make those variable values available to your shell commands.
  4. #3
  5. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,592
    Rep Power
    4207
    Instead of using system() to shell out commands, why not look at the source code for ifconfig and grab the relevant lines to set your IP address.

    A redhat distro comes with sources. If you don't have the CDs, you can try downloading the sources from the websites.

    http://www.redhat.com/download/mirror.html
    ftp://ftp.debian.org/debian/dists/woody/main/source/

IMN logo majestic logo threadwatch logo seochat tools logo