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

  • SEARCH
  • Home
  • 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 4545772
In Process

The Archive Base Latest Questions

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

Below is a code where I want to display the ip address of the

  • 0

Below is a code where I want to display the ip address of the address entered by the user but it gives me STATUS_ACCESS_VIOLATION and I am not understanding the reason for it.

It compiles fine. Here is it

#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif

// Link to ws2_32.lib
#include <winsock2.h>
#include <stdio.h>
#include <stdlib.h>
struct protoent *proto=NULL;
int main(int count, char *strings[])
{   
  int pid;
  struct hostent *host;
  struct sockaddr_in addr;
  if ( count != 3 )
  {
     printf("usage: %s <addr> < Adressflag = 0 for name and 1 for IP  > /n", strings[0] );
     exit(0);
  }
 if ( count == 3 )
 {
     int flag = atoi(strings[2]);
     printf("flag is %d",flag);
     if ( flag == 0)
     {
         pid = getpid();
         proto = getprotobyname("ICMP");
         host = gethostbyname(strings[1]);
         bzero(&addr, sizeof(addr));
         addr.sin_family = host->h_addrtype;
         addr.sin_port = 0;
         addr.sin_addr.s_addr = *(long*)host->h_addr;
         //traceroute(&addr);
         printf("IP of %s is %s",host->h_name , host-> h_addr);
     }
     else
     {

     }
 }
 return 0;
}

I am running this in cygwin. Is anyone aware of the error and can anyone tell what am I doing 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-21T15:51:37+00:00Added an answer on May 21, 2026 at 3:51 pm

    Do you really need the * on the front?

    addr.sin_addr.s_addr = *(long*)host->h_addr
    

    That means you are de-referencing some random address.

    You are also not checking host for null.

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

Sidebar

Related Questions

Below is my code snippet , I want to display only 10 records from
I want to open an xlsx file, I have tried the below code,but neither
I want to display a 404 (Not found) message, when the user tries to
The code below will display the city, state chosen by user from previous page
This is my below code and I want to catch the exception if any
See code below: I want Page 1 to alert #testing... This works in C
I want to know if the below code: <?php printf (%s, $some_variable); ?> is
I want to know is below code correct ? I have following code which
Issue In the below code , say if i want to change the color
I want to send data through URL.I've tried the below code: Intent browserIntent =

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.