Howdy, Stranger!

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

Categories

ping command in c

wacuqwacuq Member Posts: 2
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

  • Null and VoidNull and Void Member Posts: 1,202
    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.
  • zeronezerone Member Posts: 24
    : 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.

  • Null and VoidNull and Void Member Posts: 1,202
    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
  • Andre YoungAndre Young USAMember Posts: 0

    ________ \ http://forcoder.org \ free ebooks and video tutorials about / C, MATLAB, Ruby, Delphi, Visual Basic .NET, R, Perl, C#, Assembly, PHP, Go, C++, Swift, JavaScript, Visual Basic, PL/SQL, Objective-C, Python, Scratch, Java Rust, Scala, Hack, D, Kotlin, ABAP, ML, VBScript, Crystal, SAS, Ada, Bash, Fortran, Alice, Logo, Dart, F#, Lisp, LabVIEW, Prolog, Transact-SQL, Julia, Erlang, FoxPro, COBOL, Apex, Awk, Clojure, Lua, Scheme / ____

Sign In or Register to comment.