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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:28:41+00:00 2026-05-19T02:28:41+00:00

printf( Dst Address:\n); for(i = 0;i < 4;i++) printf( %d ,((ip->ip_dst.s_addr)&(0x0FF<<(i*8)))>>(i*8)); by this i

  • 0
printf(" Dst Address:\n");
for(i = 0;i < 4;i++)
printf(" %d ",((ip->ip_dst.s_addr)&(0x0FF<<(i*8)))>>(i*8));

by this i am able to print the destination ip address as 192.28.2.11 but i want just want the first two numbers 192 and 28 how can i get this two value.?

  • 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-19T02:28:42+00:00Added an answer on May 19, 2026 at 2:28 am

    What’s wrong with just modifying the code you have:

    int a[4];
    for (i = 0; i < 4; i++)
        a[i] = ((ip->ip_dst.s_addr)&(0x0FF<<(i*8)))>>(i*8);
    

    That should give them to you in a[0] and a[1].


    The following code shows one way to do it. The IP address is reversed (0x0b0280c0) due to the x86 little-endian format:

    #include <stdio.h>
    int main (void) {
        int i;
        unsigned int addr = 0x0b0280c0;
        int a[4];
        for (i = 0; i < 4; i++)
            a[i] = ((addr)&(0x0FF<<(i*8)))>>(i*8);
        printf ("%d %d %d %d\n", a[0], a[1], a[2], a[3]);
        return 0;
    }
    

    It outputs:

    192 128 2 11
    

    and you can see that the components are placed in the individual array elements.

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

Sidebar

Related Questions

I want to use printf in driver code (DDK), therefore I've included stdio.h. But
Printf got added to Java with the 1.5 release but I can't seem to
sub do_printf { printf @_ } sub do_sprintf { print sprintf @_ } do_printf(%s\n,
Given this line of code in C: printf(%3.0f\t%6.1f\n, fahr, ( (5.0/9.0) * (fahr-32) )
I have some data that won't printf.... echo works, but not printf There is
In general I know why you get this error, but I'm a little confused
printf(pointer: %d\n, sizeof(*void)); This line results in a syntax error because of the *.
printf function in c doesn't always print the output on screen. For example if
def move_file(dirs,src,dst): src = src+.jpg dst = item[1]+/+src print src # Moves the file
By man I find printf(%*d, width, num); and printf(%2$*1$d, width, num); are equivalent. But

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.