networkhandler.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*******************************************************************************
  2. * Copyright (c) 2009, Rockwell Automation, Inc.
  3. * All rights reserved.
  4. *
  5. ******************************************************************************/
  6. #include "networkhandler.h"
  7. #include <fcntl.h>
  8. #include "opener_error.h"
  9. #include "trace.h"
  10. #include "encap.h"
  11. #include "opener_user_conf.h"
  12. MilliSeconds GetMilliSeconds(void) {
  13. return rt_tick_get_millisecond();
  14. }
  15. EipStatus NetworkHandlerInitializePlatform(void) {
  16. /* Add platform dependent code here if necessary */
  17. return kEipStatusOk;
  18. }
  19. void ShutdownSocketPlatform(int socket_handle) {
  20. if (0 != shutdown(socket_handle, SHUT_RDWR)) {
  21. int error_code = GetSocketErrorNumber();
  22. char *error_message = GetErrorMessage(error_code);
  23. OPENER_TRACE_ERR("Failed shutdown() socket %d - Error Code: %d - %s\n",
  24. socket_handle,
  25. error_code,
  26. error_message);
  27. FreeErrorMessage(error_message);
  28. }
  29. }
  30. void CloseSocketPlatform(int socket_handle) {
  31. closesocket(socket_handle);
  32. }
  33. int SetSocketToNonBlocking(int socket_handle) {
  34. return fcntl(socket_handle, F_SETFL, fcntl(socket_handle,
  35. F_GETFL,
  36. 0) | O_NONBLOCK);
  37. }
  38. int SetQosOnSocket(const int socket,
  39. CipUsint qos_value) {
  40. /* Quote from Vol. 2, Section 5-7.4.2 DSCP Value Attributes:
  41. * Note that the DSCP value, if placed directly in the ToS field
  42. * in the IP header, must be shifted left 2 bits. */
  43. int set_tos = qos_value << 2;
  44. return setsockopt(socket, IPPROTO_IP, IP_TOS, &set_tos, sizeof(set_tos));
  45. }