PageRenderTime 27ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llmessage/net.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 71 lines | 25 code | 15 blank | 31 comment | 0 complexity | d32920d9eca9d26eca99f04b7bfc98f1 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file net.h
  3. * @brief Cross platform UDP network code.
  4. *
  5. * $LicenseInfo:firstyear=2000&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_NET_H
  27. #define LL_NET_H
  28. class LLTimer;
  29. class LLHost;
  30. #define NET_BUFFER_SIZE (0x2000)
  31. // Request a free local port from the operating system
  32. #define NET_USE_OS_ASSIGNED_PORT 0
  33. // Returns 0 on success, non-zero on error.
  34. // Sets socket handler/descriptor, changes nPort if port requested is unavailable.
  35. S32 start_net(S32& socket_out, int& nPort);
  36. void end_net(S32& socket_out);
  37. // returns size of packet or -1 in case of error
  38. S32 receive_packet(int hSocket, char * receiveBuffer);
  39. BOOL send_packet(int hSocket, const char *sendBuffer, int size, U32 recipient, int nPort); // Returns TRUE on success.
  40. //void get_sender(char * tmp);
  41. LLHost get_sender();
  42. U32 get_sender_port();
  43. U32 get_sender_ip(void);
  44. LLHost get_receiving_interface();
  45. U32 get_receiving_interface_ip(void);
  46. const char* u32_to_ip_string(U32 ip); // Returns pointer to internal string buffer, "(bad IP addr)" on failure, cannot nest calls
  47. char* u32_to_ip_string(U32 ip, char *ip_string); // NULL on failure, ip_string on success, you must allocate at least MAXADDRSTR chars
  48. U32 ip_string_to_u32(const char* ip_string); // Wrapper for inet_addr()
  49. extern const char* LOOPBACK_ADDRESS_STRING;
  50. extern const char* BROADCAST_ADDRESS_STRING;
  51. // useful MTU consts
  52. const S32 MTUBYTES = 1200; // 1500 = standard Ethernet MTU
  53. const S32 ETHERNET_MTU_BYTES = 1500;
  54. const S32 MTUBITS = MTUBYTES*8;
  55. const S32 MTUU32S = MTUBITS/32;
  56. #endif