Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6585125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:37:21+00:00 2026-05-25T16:37:21+00:00

I know someone will give me a hard time for this, but here goes.

  • 0

I know someone will give me a hard time for this, but here goes. I am trying to convert some C code to Java and am still learning java as I go. I am having a very difficult time figuring out how to do this conversion and learning java for that matter. Any help or pointers on where to go would be greatly appreciated.

for(d=alldevs; d; d=d->next)
    {
        printf("%d. %s", ++i, d->name);
        if (d->description)
            printf(" (%s)\n", d->description);
        else
            printf(" (No description available)\n");
    }

    if(i==0)
    {
        printf("\nNo interfaces found! Make sure WinPcap is installed.\n");
        return -1;
    }

    printf("Enter the interface number (1-%d):",i);
    scanf("%d", &inum);

    if(inum < 1 || inum > i)
    {
        printf("\nInterface number out of range.\n");
        /* Free the device list */
        pcap_freealldevs(alldevs);
        return -1;
    }

    /* Jump to the selected adapter */
    for(d=alldevs, i=0; i< inum-1 ;d=d->next, i++);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T16:37:22+00:00Added an answer on May 25, 2026 at 4:37 pm

    A conversion offering:

    public class Item {
    
       private String name;
    
       private String description;
    
       public Item(String name, String description) {
         this.name = name;
         this.description = description;
       }
    
       public String getName() {
         return this.name;
       }
    
       public String getDescription() {
         return this.description;
       }
    
    }
    
     (defined elsewhere)
     List<Item> items;
    

    And now the code

    int index = 1;
    for (Item item: items) {
       System.out.print(index + ". " + item.getName());
       if (item.getDescription() != null) {
         System.out.println(" (" + item.getDescription() + ")");
       } else {
         System.out.println"( (No Description Available)");
       }
       index++;
    }    
    
    List<NetworkInterface> nets = Collections.list(NetworkInterface.getNetworkInterfaces());
    if (nets.size() == 0) {
      System.out.println();
      System.out.println("No interfaces found! Make sure WinPcap is installed.");
      return;
    }
    
    System.out.print("Enter the interface number(1-" + nets.size() + "):");
    Byte[] input = new byte[100];
    System.in.read(input);
    String inString = new String(input);
    int interfaceIndex = Integer.getInteger(inString);
    
    if (interfaceIndex < 1 || interfaceindex > nets.size()) {
       System.out.println();
       System.out.println("Interface number out of range.");
       // freeing items is done by dereferencing
       nets = null;
       return;
    } 
    
    // jump to the selected adapter
    NetworkInterface selectedInterface = nets.get(interfaceIndex);
    

    Note that you will have to do the “real” conversion of the rest of the program; that is writing a PCap solution in Java, or writing a JNI (Java) interface to call the PCap library routines.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know the code is missing (Someone will give negative numbers). But I only
Does anyone know what error message will be displayed when someone tries to run
Someone know some interesting and complete tutorial about how to create a Parent-Child dimension
Does someone know why this is not a strict quine ? _0='_0=%r;print _0%%_0';print _0%_0
I hope someone will give me an idea how to proceed, because I'm losing
Before I start explaining the code I will first give my use case so
I know the first comment will be that am duplicating previous threads, but the
I don't come here for help often but I am pretty frustrated by this
i am facing a new situation. I know someone definitely had faced these type
does someone know how to draw 3D surfaces and hide the invisible lines? I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.