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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:11:30+00:00 2026-05-29T08:11:30+00:00

Following example code from the libpcap documentation yields the following code which should report

  • 0

Following example code from the libpcap documentation yields the following code which should report the IP address of the given interface (eth0 in this case) [Error checking omitted for brevity]

#include <stdio.h>
#include <pcap.h>
#include <arpa/inet.h>

int main(int argc, char *argv[])
{
  char errbuf[PCAP_ERRBUF_SIZE]; 
  bpf_u_int32 mask;   
  bpf_u_int32 ip;    
  struct in_addr ip_addr;

  /* Find the properties for the device */
  pcap_lookupnet("eth0", &ip, &mask, errbuf);

  ip_addr.s_addr = ip;

  printf("IP Address: %s\n", inet_ntoa(ip_addr));

  return 0;
}

However, this results in 192.168.1.0, rather than the correct 192.168.1.100. Running this on a different machine on a different subnet yields 10.0.0.0 rather than the correct 10.0.0.107 which leads me to believe libpcap is not copying the last octet correctly. I’ve manually converted the integer returned by pcap_lookupnet to ensure it’s not an issue with the use of inet_ntoa (I’ve also tried inet_ntop, with identical results). Following the code from this question:
Get IP address of an interface on Linux
reports the correct IP address. Is this a bug in libpcap or am I doing something wrong?

  • 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-29T08:11:31+00:00Added an answer on May 29, 2026 at 8:11 am

    Your statement “which should report the IP address of the given interface” is incorrect.

    From the manpage:

    pcap_lookupnet() is used to determine the IPv4 network number and
    mask
    associated with the network device device. Both netp and maskp are
    bpf_u_int32 pointers.

    are you sure you have a network number of 10.0.0.107 or 192.168.1.100 respectively? Sounds rather unusual.

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

Sidebar

Related Questions

This following code example is borrowed from MSDN here . I am not getting
I'm trying to compile the following simple DL library example code from Program-Library-HOWTO with
Ive got the following code which I hacked together from website examples. It works
I'm running the following example code from Apple - NSString *requestURL = [[NSString alloc]
I have copied the code from the following example on the Apple Developer site.
I try to compile the following code example from C++ Templates - The Complete
I have this piece of code (from the Nokia PC connectivity 3.2 example code,
I'm completely newbie in PHP. I have tried example code from this site .
I want to try out the example code from this article: Load Recovery.gov Grant
I have the following code example taken from the code of a Form :

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.