Originally Posted by
anduril462
You didn't show very much code. You left out critical definitions of variables so I don't know their type, among other things. Where does addr come from? How does it get the value 1677830336? What does that value represent? What is the process of converting 1677830336 to 3232235876 and back? Is it just changing the endianness? You are not being very clear.
First off I'm very sorry for my unclearness.
Variables:
Code:
struct sockaddr_storage their_addr;
struct addrinfo hints, *servinfo;
struct in_addr addr;
socklen_t addr_size;
int len, bytes_sent, bytes_received, fdmax, new_fd, nbytes, j, i;
int countSentBytes=0,sockfd ,bindfd , listenfd;
//char *sendToUser = (char*)inputUser, *fileName = (char*)inputFileName, *fileLoc = (char*)inputFileLoc;
char strSizeFile[50], buffer[1024], hostip[30], read[500], sendDCC[500], decResult[50], hostname[80], *pch;
char buf[500], remoteIP[INET6_ADDRSTRLEN], MYPORT[6] = "49153";
Code:
--> I get my hostname from my current host.
if (gethostname(hostname, sizeof(hostname)) == SOCKET_ERROR) {
printf("%s","host not found");
}
--> I give the value from hostname to phe
struct hostent *phe = gethostbyname(hostname);
-->I get the ip address from my current hostname (the name from ipconfig)
memcpy(&addr, phe->h_addr_list[0], sizeof(struct in_addr));
//Convert IP to Decimal notation
-->I convert my IP to 1677830336 wich represents: 100.1.168.192
sprintf(decResult,"%u", addr);
-->I flip it around and get as result: 3232235876 the decimal notation of the IP address
sprintf(decResult,"\n%u", htonl(atoi(decResult)));
The reason I don't give the value straight away to htonl is because of this thing:
Code:
'ntohl' : cannot convert parameter 1 from 'in_addr' to 'u_long'
'No suitable conversion exists'
I'm working with DCC now wich is a part of the IRC Protocol. When sending files DCC requires the IP to be converted to the decimal notation before sending a packet out.
On receiving a message to create a connection with DCC I need to convert this decimal notation back to Dotted Decimal Notation. So the only thing I get when setting up a new Connection is the "3232235876".
I hope i cleared things up a lil bit.
If you have any further questions, feel free to ask.