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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:31:23+00:00 2026-05-20T21:31:23+00:00

I searched with my problem but with no success I do not know how

  • 0

I searched with my problem but with no success

I do not know how to implement proper function iphost().

Well I have file library.h file in which I store variables and function iphost().

There is another file called main.c where I run function iphost(...).

I really do not know how to fix my problem.

I got error adr_srvr doesn’t have element sin_addr.

/home/user/Desktop/pap_lab2/2/biblioteka.h|23|error: request for member ‘sin_addr’ in something not a structure or union|

Probably I declared wrong arguments with that stars pointers and ampersands. Can anybody help me?

library.h
void iphost(char* arg,struct sockaddr_in *adr_srvr)
{
    if(*arg>=(char)'0' && *arg<=(char)'9')
    {
        printf("Prawdopodobnie wprowadzono IP: %s\n", arg);
        inet_aton(arg, &adr_srvr.sin_addr);//here ERROR
        srvr_addr = inet_ntoa(adr_srvr.sin_addr);
    }
}
main.c
iphost(argv[2], &adr_srvr); // OK ?

Little help to undestand the code:
I cannot get to adr_srvr.sin_addr.
char* arg is arguments inputing by me, 4example: “127.0.0.1”.
adr_srvr.sin_addr store this 127.0.0.1
srvr_addr is char*

The normal code which works okay is (without functon) in main.c :

int main (int argc, char *argv[] )
{
  int z;
  int x;
  char *srvr_addr;
  struct sockaddr_in adr_srvr;
  struct sockaddr_in adr;
  struct hostent *he;
  int len_inet;
  int s;
    char dgram[512];
    struct in_addr **addr_list;
    char buf[512];

    //USTAWIENIE POLACZENIA
    //CZY WPISANO IP

    if(argv[1][0]>=(char)'0' && argv[1][0]<=(char)'9')
    {
        printf("Prawdopodobnie wprowadzono IP: %s\n", argv[1]);
        inet_aton(argv[1], &adr_srvr.sin_addr);
        srvr_addr = inet_ntoa(adr_srvr.sin_addr);
    } else {}

...
}

———

I have similar question so I edit here. How can I implement this in function?:

else
    {
         if ((he = gethostbyname(arg)) == NULL) {  // get the host info
            herror("gethostbyname");
            return 2;
        }

        // print information about this host:
        printf("Wykryty HOST: '%s' ", arg);
        printf("zamieniam na IP: ");
        addr_list = (struct in_addr **)he->h_addr_list;
        printf("%s", srvr_addr = inet_ntoa(*addr_list[0]));
        printf("\n");

    }
  • 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-20T21:31:23+00:00Added an answer on May 20, 2026 at 9:31 pm

    adr_srvr is a pointer. To access its fields, you need to use adr_srvr->sin_addr instead of adr_srvr.sin_addr.

    In general, use a.field when a is a struct, and a->field when a is a pointer to a struct.

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

Sidebar

Related Questions

I have searched thoroughly for an answer to my problem but without much success.
I have searched/Googled around but I'm struggling with the following problem. I am building
I have searched the site for this simple problem but cant find an answer.
i know im not the first with this problem, but i cant seem to
I have been trying to solve this problem for hours (searched here as well
I have searched a lot regarding my problem but no solution so i am
I have searched for hours now and haven't found a solution for my problem.
I have a problem which I cant seem to find answer to through searches
I searched and found this question but did not like the answer. Is there
I'm rather new to ClearCase but have searched through a lot of solutions to

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.