Find the answer to your Linux question:
Results 1 to 3 of 3
#### test.c##### #include <fcntl.h> #include <string.h> #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> #include <sys/types.h> #include <sys/socket.h> #include <sys/ioctl.h> #include <netinet/in.h> #include <net/if.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> ...
  1. #1
    Just Joined!
    Join Date
    Jun 2007
    Posts
    84

    c programing on linux help me!!

    #### test.c#####

    #include <fcntl.h>
    #include <string.h>
    #include <sys/stat.h>
    #include <sys/types.h>
    #include <unistd.h>
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <sys/ioctl.h>
    #include <netinet/in.h>
    #include <net/if.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <ctype.h>

    int main(int argc, char **argv )
    {

    if(strcmp(argv[1],"mac_arp")==0)
    {
    system("arp -en | grep $1 | awk '{print $3}'");
    }

    }

    this program for search mac address with ip address

    command to use: test mac_arp 172.168.1.200
    result: "it's show mac address of 172.168.1.200"


    it's red color i try to define to argv for receive "172.168.1.200".it's dont work.

    it not working!! how to change something for working.
    ** i don't want to use with shell script i need to use c programing only. Thank!!

  2. #2
    Just Joined!
    Join Date
    Aug 2008
    Posts
    1

    hi, please use this program

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

    #define err perror

    int main(int argc, char **argv)
    {
    char buf[1024];

    if (argc < 2)
    {
    err("argc < 2");
    return -1;
    }

    memset(buf, '\0', sizeof(buf));
    snprintf(buf, sizeof(buf), "arp -en | grep %s | awk '{print $3}'", argv[1]);
    system(buf);

    return 0;
    }

  3. #3
    Just Joined!
    Join Date
    Jun 2007
    Posts
    84
    thank!! for help. But it's dont work for me.
    you program: test 172.168.1.200
    but i want : test mac_arp 172.168.200

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...