ping command in c

Hi everybody!


I'm trying to make a "ping hostip" in c via system("ping 192.168.0.1")...
I'd like the following:

char ip[16]="192.168.0.1";
system("ping %s", &ip);

It doesn't work!

Please help!

Comments

  • Did you actually expect that to work?
    [code]
    #include
    #include

    int main(void) {
    char buffer[256];
    char ip[16] = "127.0.0.1";

    snprintf(buffer,256,"ping %s
    ",ip);
    system(buffer);

    return 0;
    }
    [/code]
    It's much funner to write your own ping program (instead of accessing it through system), but that's your answer.
  • : Did you actually expect that to work?
    : [code]
    : #include
    : #include
    :
    : int main(void) {
    : char buffer[256];
    : char ip[16] = "127.0.0.1";
    :
    : snprintf(buffer,256,"ping %s
    ",ip);
    : system(buffer);
    :
    : return 0;
    : }
    : [/code]
    : It's much funner to write your own ping program (instead of accessing it through system), but that's your answer.

    Question:

    How do you write you own ping program?
    Where do you start? Do you need embedded assembly to talk to your networkcard?

    CHeers,



    [italic]"We must work in team, or we die"[/italic]
    - The single dead guy WWII.

  • See this for a library that handles the basics of 'ping' for your program. It's also open source, so you can learn how they did it on your own if you'd like: http://www.gnu.org/directory/libping.html
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories