Thread: Unable to use in_addr type with arpa/inet.h

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    30

    Unable to use in_addr type with arpa/inet.h

    Whenever I do not include arpa/inet.h, this compiles fine in g++, but I cannot use some functions. The error in g++ is:

    Code:
    tcp.cpp:117: error: conversion from ‘in_addr_t’ to non-scalar type ‘in_addr’ requested
    and line 117 is:

    Code:
    return((char *)inet_ntoa(addr.s_addr));
    addr is defined as:

    Code:
    struct in_addr addr;

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Wolf` View Post
    Whenever I do not include arpa/inet.h, this compiles fine in g++, but I cannot use some functions. The error in g++ is:

    Code:
    tcp.cpp:117: error: conversion from ‘in_addr_t’ to non-scalar type ‘in_addr’ requested
    and line 117 is:

    Code:
    return((char *)inet_ntoa(addr.s_addr));
    addr is defined as:

    Code:
    struct in_addr addr;
    Not sure if this is the answer but try aliasing your addr as (sockaddr)addr.s_addr and see if it works... in_addr and sockaddr are very similar but not always interchangeable.

  3. #3
    Registered User
    Join Date
    Jun 2009
    Posts
    30
    When I do that, I get this:

    Code:
    tcp.cpp: In member function ‘char* tcpSocket::resolve(char*)’:
    tcp.cpp:117: error: no matching function for call to ‘sockaddr::sockaddr(in_addr_t&)’
    /usr/include/bits/socket.h:175: note: candidates are: sockaddr::sockaddr()
    /usr/include/bits/socket.h:175: note:                 sockaddr::sockaddr(const sockaddr&)

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Bummer...

    I'm sure the others will have better answers than I did (as they so often do)...

  5. #5
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    inet_ntoa takes an in_addr as parameter, so you should be able to just pass "addr" without any problems.

  6. #6
    Registered User
    Join Date
    Jun 2009
    Posts
    30
    Thanks a ton!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Undefined reference to.. probably Makefile problem
    By mravenca in forum C Programming
    Replies: 11
    Last Post: 10-20-2010, 04:29 AM
  2. How to pass a matrix/array from main to a function
    By Inukami in forum C Programming
    Replies: 7
    Last Post: 12-09-2009, 09:03 PM
  3. Replies: 0
    Last Post: 03-20-2008, 07:59 AM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. Errors
    By Rhidian in forum C Programming
    Replies: 10
    Last Post: 04-04-2005, 12:22 PM