Find Interface name

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • chellappa

    Find Interface name

    hi all,
    i trying to find the intferface name using this coding ,but that is
    not working ,,,if anybody this pervious..pleas e help to find the
    interface name using Linux C.

    //CODE
    ioctl(sd, SIOCGIFNAME, &ifr);
    strncpy(ifname, ifr.ifr_name,IF NAMSIZ);
    printf("Interfa ce name :%s\n",ifname);

    //
    thanks all

  • Eric Sosman

    #2
    Re: Find Interface name

    chellappa wrote:[color=blue]
    > hi all,
    > i trying to find the intferface name using this coding ,but that is
    > not working ,,,if anybody this pervious..pleas e help to find the
    > interface name using Linux C.
    >
    > //CODE
    > ioctl(sd, SIOCGIFNAME, &ifr);
    > strncpy(ifname, ifr.ifr_name,IF NAMSIZ);
    > printf("Interfa ce name :%s\n",ifname);[/color]

    In Standard C, an `int' is guaranteed to be able
    to count as high as 32767. Some implementations use
    a wider `int', but 32767 is the maximum you can be
    absolutely sure of.

    If one were to write a program to count the number
    of times Chellappa has been told that Standard C has
    no networking facilities, the number of times he has
    been told to take his networking questions to newsgroups
    where networking experts hang out, the number of times
    he has been given the names of those newsgroups, and the
    number of times he has utterly failed to get the message,
    would it be wise to use a mere `int' for the counter?

    --
    Eric Sosman
    esosman@acm-dot-org.invalid

    Comment

    • Joe Estock

      #3
      [OT] Re: Find Interface name

      Eric Sosman wrote:[color=blue]
      > chellappa wrote:
      >[color=green]
      >> hi all,
      >> i trying to find the intferface name using this coding ,but that is
      >> not working ,,,if anybody this pervious..pleas e help to find the
      >> interface name using Linux C.
      >>
      >> //CODE
      >> ioctl(sd, SIOCGIFNAME, &ifr);
      >> strncpy(ifname, ifr.ifr_name,IF NAMSIZ);
      >> printf("Interfa ce name :%s\n",ifname);[/color]
      >
      >
      > In Standard C, an `int' is guaranteed to be able
      > to count as high as 32767. Some implementations use
      > a wider `int', but 32767 is the maximum you can be
      > absolutely sure of.
      >
      > If one were to write a program to count the number
      > of times Chellappa has been told that Standard C has
      > no networking facilities, the number of times he has
      > been told to take his networking questions to newsgroups
      > where networking experts hang out, the number of times
      > he has been given the names of those newsgroups, and the
      > number of times he has utterly failed to get the message,
      > would it be wise to use a mere `int' for the counter?
      >[/color]

      I'd put bets on at least an unsigned long, preferably an unsigned long
      long if the implementation supports it.

      Joe

      Comment

      • wcang79@gmail.com

        #4
        Re: Find Interface name

        Hi,

        I don't know about SIOCGIFNAME, but I assume that what you want is
        to call ioctl(sd, SIOCGIFCONF, &ifconf) to obtain all the network
        interfaces on your system.

        Regards,
        Ang Way Chuang

        Comment

        • wcang79@gmail.com

          #5
          Re: Find Interface name

          In addition, you may also want to look into these 2 functions:

          char *if_indextoname (unsigned ifindex, char *ifname);
          struct if_nameindex *if_nameindex(v oid);




          I think you should download Single Unix Specification version 3 from
          www.opengroup.org if you plan to program in Unix. Hope this answer your
          question.

          Regards,
          Ang Way Chuang

          Comment

          Working...