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 548563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:05:33+00:00 2026-05-13T11:05:33+00:00

In my program I’m sending out UDP broadcasts and reacting to them. I need

  • 0

In my program I’m sending out UDP broadcasts and reacting to them. I need a way to ignore the UDP broadcasts that I send out, but react to ones that aren’t from my machine.

I did try using:
if (NetworkInterface.getByInetAddress(packet.getAddress()) != null)
but this generated IOExceptions in some cases (java.net.SocketException: no network interface is bound to such an IP address)

Anyone any ideas?

Also:
getInetAddress() on my socket throws a NullPointerException

  • 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-13T11:05:33+00:00Added an answer on May 13, 2026 at 11:05 am

    I think there’s a little discrepancy between the javadoc and the actual implementation of NetworkInterface getByInetAddress(). The javadoc seems to suggest that getByInetAddress would return null if no match was found, yet the implementation either returns a match, either throws a SocketException.

    JavaDoc

    public static NetworkInterface getByInetAddress(InetAddress addr)
                                                   throws SocketException
    

    Returns: A NetworkInterface or null if there is no network interface with the specified IP address.

    Implementation

      public static NetworkInterface getByInetAddress (InetAddress addr)
        throws SocketException
      {
        if (networkInterfaces == null)
          networkInterfaces = getRealNetworkInterfaces ();
    
        for (Enumeration interfaces = networkInterfaces.elements ();
             interfaces.hasMoreElements (); )
          {
            NetworkInterface tmp = (NetworkInterface) interfaces.nextElement ();
    
            for (Enumeration addresses = tmp.inetAddresses.elements ();
                 addresses.hasMoreElements (); )
              {
                if (addr.equals ((InetAddress) addresses.nextElement ()))
                  return tmp;
              }
          }
    
        throw new SocketException (
          "no network interface is bound to such an IP address");
      }
    

    I suggest to either catch the exception and treat it as an answer from a 3rd party, either re-implement it using the getNetworkInterfaces() method.

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

Sidebar

Related Questions

My program opens a socket on port 80, but if I don't run it
My program is a game that uses RMI to allow users to connect to
My program generates two strings and I want them compared by the external diff
The program that I am working on takes a file and parses it line
My program receives an executable binary file through a TCP socket. I need to
My program needs to receive strings through the serialport. Problem is that the program
I program on Eclipse for Android. But I have a problem with the Android
Program A, is a c program that endlessly, receives input in stdin, process it
/* Program that reads a sequence of words from keyboard and prints the list
my program throws a std::bad_alloc. After debugging it, I found out it is thrown

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.