This is the age because I have worked with C ++, so this is probably a basic issue, but I know this Not a solution found.
I have to write a small + socket class that can see the IP address for a given host / port. Everything works fine inside the classroom, although I'm not sure how to return a single idyro structure (I mark the line below) from the array of structures to the calling function. I have tried memcopy, pointers etc. Anything seems to work.
Getaddrinfo addresses an array of address structures (m_addList) when compiled / run, returns the results returned inside the class completely. Please note that for simplicity I have simplified the example.
./ lookup www.stackoverflow.com 80 = & gt; 2 = & gt; 1 - & gt; 32767 - & gt; 4197087
The values marked with "=>" are correct and can be used to generate sockets, although the "->" values are incorrect, causing a socket error.
Code:
#include & lt; Netdb.h & gt; # Include & lt; Arpa / inet.h & gt; #include & lt; String.h & gt; # Include & lt; Iostream & gt; using namespace std; Get the Classroom Account {Private: Straight addrinfo * m_addList; // List of addressed information publications: public: int getAddressInfo (four * host, four * port, straight addrinfo singleAddress); }; Int getAddress :: getAddressInfo (four * hosts, four * port, structure addrinfo single address) {int rate; Straight addrinfo addCriteria; Memes (and advertitia, 0, size (adressrea)); AddCriteria.ai_family = AF_UNSPEC; AddCriteria.ai_socktype = SOCK_STREAM; AddCriteria.ai_protocol = IPPROTO_TCP; Ret = getaddrinfo (host, port, and adritoria, & amp; m_addlist); If (rate! = 0) return -1; // Just the first address foundAudress = * M_Adlist; // & lt; ---- This is my problem cout & lt; & Lt; "= & Gt;" & Lt; & Lt; Single address.aai_family & lt; & Lt; Endl; Cout & lt; & Lt; "= & Gt;" & Lt; & Lt; Single address.ai_sock type & lt; & Lt; Endl; Return 0; } Int main (int argc, char * argv []) {int res; Structure Adirino Inwal; If (argc & lt; 3) cout & lt; & Lt; "Usage: main [domain] [port]" & lt; & Lt; Endl; GetAddress adObj; Res = adObj.getAddressInfo (argv [1], argv [2], inVal); If (res == 0) {cout & lt; & Lt; "- & gt;" & Lt; & Lt; InVal.ai_family & lt; & Lt; Endl; Cout & lt; & Lt; "- & gt;" & Lt; & Lt; InVal.ai_socktype & lt; & Lt; Endl; }} Thanks a lot for help!
Change
int getAddress :: getAddressInfo (four * hosts, As it is now, you are only modifying the local copy of the single address
, and the port, straight addrinfo and single adapter)
Nothing with code> inVal
Comments
Post a Comment