Thread: how to cast a char *mystring to a structure pointer ??

  1. #1
    Registered User
    Join Date
    Mar 2004

    how to cast a char *mystring to a structure pointer ??

    hey guys, how do you Cast a char *mystring to a structure pointer, namely "hostent" ??

    looking at ,

    it says
    "On successful completion, the buffer specified to the original function call contains a hostent structure. To access the elements of this structure, the original buffer address should be cast to a hostent structure pointer and accessed as appropriate."
    like this??

    char *hostEntry2 ;
    hostent *abc= (HOSTENT)*hostEntry2;
    nope it doesnt work
    i ultimately want to use WSAAsyncGetHostByName to get the IP address of a computer. ( i use WSA version because the GetHostByName version blocks)

    any help?

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    You have to be carefull when posting MSDN links because the address bar rarely contains the URL of what you're looking at.
    I think you meant to post the URL for WSAAsyncGetHostByName()

    From MDSN, WSAAsyncGetHostByName() parameters:
    [out] Pointer to the data area to receive the hostent data. The data area must be larger than the size of a hostent structure because the specified data area is used by Windows Sockets to contain a hostent structure and all of the data referenced by members of the hostent structure. A buffer of MAXGETHOSTSTRUCT bytes is recommended.
    char hostentBuff[MAXGETHOSTSTRUCT];
    hostent *abc = (hostent*)hostentBuff;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem referencing structure elements by pointer
    By trillianjedi in forum C Programming
    Replies: 19
    Last Post: 06-13-2008, 05:46 PM
  2. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  3. Obtaining source & destination IP,details of ICMP Header & each of field of it ???
    By cromologic in forum Networking/Device Communication
    Replies: 1
    Last Post: 04-29-2006, 02:49 PM
  4. How do you search & sort an array?
    By sketchit in forum C Programming
    Replies: 30
    Last Post: 11-03-2001, 05:26 PM