Subversion Repositories Kolibri OS

Rev

Rev 5499 | Rev 7252 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. //Network library
  2. #ifndef INCLUDE_NETWORK_H
  3. #define INCLUDE_NETWORK_H
  4.  
  5. #ifndef INCLUDE_KOLIBRI_H
  6. #include "../lib/kolibri.h"
  7. #endif
  8.  
  9. #ifndef INCLUDE_DLL_H
  10. #include "../lib/dll.h"
  11. #endif
  12. dword network_lib = #a_network_lib;
  13. char a_network_lib[21]="/sys/lib/network.obj\0";
  14.  
  15. dword network_lib_init    = #aLib_init;
  16. dword inet_addr           = #aInet_addr;  //"192.168.0.1" -> dword IP
  17. dword inet_ntoa           = #aInet_ntoa;
  18. dword getaddrinfo         = #aGetaddrinfo;
  19. dword getaddrinfo_start   = #aGetaddrinfo_start;
  20. dword getaddrinfo_process = #aGetaddrinfo_process;
  21. dword getaddrinfo_abort   = #aGetaddrinfo_abort;
  22. dword freeaddrinfo        = #aFreeaddrinfo;
  23. $DD 2 dup 0
  24.  
  25. char aLib_init[9]              = "lib_init\0";
  26. char aInet_addr[10]            = "inet_addr\0";
  27. char aInet_ntoa[10]            = "inet_ntoa\0";
  28. char aGetaddrinfo[12]          = "getaddrinfo\0";
  29. char aGetaddrinfo_start[18]    = "getaddrinfo_start\0";
  30. char aGetaddrinfo_process[20]  = "getaddrinfo_process\0";
  31. char aGetaddrinfo_abort[18]    = "getaddrinfo_abort\0";
  32. char aFreeaddrinfo[13]         = "freeaddrinfo\0";
  33.  
  34. /*
  35. addr соответствует IP 10.101.102.103
  36. itoa((addr&0xFF000000)>>24) равно 103
  37. itoa((addr&0xFF0000)>>16) —это 102
  38. itoa((addr&0xFF00)>>8) — это 101
  39. itoa(addr&0xFF) — это 10
  40. */
  41.  
  42. dword GetIPfromAdress(dword addr)
  43. {
  44.         dword lpointer, IPa;
  45.         getaddrinfo stdcall (addr, 0, 0, #lpointer);
  46.         if (EAX!=0) IPa = 0; else IPa = DSDWORD[DSDWORD[lpointer+24]+4];
  47.         freeaddrinfo stdcall (lpointer);
  48.         return IPa;
  49. }
  50.  
  51. /*
  52. //Convert the string from standard IPv4 dotted notation to integer IP addr.
  53. inet_addr stdcall ("192.168.0.1");
  54. server_IP = EAX;
  55.  
  56.  
  57. char* __stdcall inet_ntoa(struct in_addr in);
  58. Convert the Internet host address to standard IPv4 dotted notation.
  59.  
  60. getaddrinfo(__in const char* hostname, __in const char* servname,
  61.             __in const struct addrinfo* hints, __out struct addrinfo **res);    
  62. struct addrinfo {
  63.     int     ai_flags;
  64.     int     ai_family;
  65.     int     ai_socktype;
  66.     int     ai_protocol;
  67.     size_t  ai_addrlen;
  68.     struct sockaddr *ai_addr;
  69.     char   *ai_canonname;
  70.     struct addrinfo *ai_next;
  71. };
  72. */
  73.  
  74. #endif