When you try to display ip, instead of the specified, incomprehensible numbers are displayed.

char* ipvar; ipvar = (char*)(void*)Marshal::StringToHGlobalAnsi(ip->Text); client(ipvar); void client(char* ipvar){ int error(0); WSADATA ws; WSAStartup (MAKEWORD(2,2), &ws); SOCKET s = socket(PF_INET,SOCK_STREAM,0); struct sockaddr_in addr; addr.sin_family = AF_INET; addr.sin_port = htons(21); addr.sin_addr.s_addr = inet_addr(ipvar); messageLB->Items->Add(addr.sin_addr.s_addr); connect( s, ( struct sockaddr* )&addr, sizeof(addr)); } 

I enter into ip for example - 1, it is displayed - 16777216

  • I have never worked with this in my life, but my intuition suggests that something is wrong here: (char*)(void*)Marshal::StringToHGlobalAnsi(ip->Text); - yrHeTaTeJlb
  • msdn claims to do this: (char*)Marshal::StringToHGlobalAnsi(managedString).ToPointer(); - yrHeTaTeJlb
  • Did not help .... - Nexsus
  • everything is clear there if you want IP then here string ipaddr = inet_ntoa (* (struct in_addr *) & ip.daddr); in your post it is already packed into the network order. - Alex.B

1 answer 1

when you submit your Ip to addr.sin_addr.s_addr = inet_addr(ipvar); then inet_addr - packs it into a network order . If you want to see it in that form in Ktori, it is passed over, then you need to call it inet_ntoa(*(struct in_addr *)&ip.saddr); where ip is struct iphdr .