FACT++  1.0
int tcpip_open_client ( int  conn_id,
char *  node,
char *  task,
int  port 
)

Definition at line 1014 of file tcpip.c.

References NET_CONNECTION::channel, check_node_addr(), closesock, dim_tcpip_init(), NET_CONNECTION::last_used, Net_conns, NET_CONNECTION::port, Read_buffer_size, NET_CONNECTION::reading, time, NET_CONNECTION::timr_ent, ushort, Write_buffer_size, and NET_CONNECTION::write_timedout.

Referenced by dna_open_client().

1015 {
1016  /* Create connection: create and initialize socket stuff. Try
1017  * and make a connection with the server.
1018  */
1019  struct sockaddr_in sockname;
1020 #ifndef VxWorks
1021  struct hostent *host = 0;
1022 #else
1023  int host_addr;
1024 #endif
1025  int path, val, ret_code, ret;
1026  int a,b,c,d;
1027 /* Fix for gcc 4.6 "dereferencing type-punned pointer will break strict-aliasing rules"?!*/
1028  unsigned char ipaddr_buff[4];
1029  unsigned char *ipaddr = ipaddr_buff;
1030  int host_number = 0;
1031 
1032  dim_tcpip_init(0);
1033  if(isdigit(node[0]))
1034  {
1035  sscanf(node,"%d.%d.%d.%d",&a, &b, &c, &d);
1036  ipaddr[0] = (unsigned char)a;
1037  ipaddr[1] = (unsigned char)b;
1038  ipaddr[2] = (unsigned char)c;
1039  ipaddr[3] = (unsigned char)d;
1040  host_number = 1;
1041 /*
1042 #ifndef VxWorks
1043  if( gethostbyaddr(ipaddr, sizeof(ipaddr), AF_INET) == (struct hostent *)0 )
1044  {
1045 #ifndef WIN32
1046  ret = h_errno;
1047 #else
1048  ret = WSAGetLastError();
1049 #endif
1050 // if((ret == HOST_NOT_FOUND) || (ret == NO_DATA))
1051 // {
1052 // if(!check_node_addr(node, ipaddr))
1053 // return(0);
1054 // }
1055  }
1056 #endif
1057 */
1058  }
1059 #ifndef VxWorks
1060  else if( (host = gethostbyname(node)) == (struct hostent *)0 )
1061  {
1062  if(!check_node_addr(node, ipaddr))
1063  return(0);
1064  host_number = 1;
1065 /*
1066  ptr = (unsigned char *)node+(int)strlen(node)+1;
1067  ipaddr[0] = *ptr++;
1068  ipaddr[1] = *ptr++;
1069  ipaddr[2] = *ptr++;
1070  ipaddr[3] = *ptr++;
1071  host_number = 1;
1072  if( (ipaddr[0] == 0xff) &&
1073  (ipaddr[1] == 0xff) &&
1074  (ipaddr[2] == 0xff) &&
1075  (ipaddr[3] == 0xff) )
1076  {
1077  errno = ECONNREFUSED;
1078 #ifdef WIN32
1079  WSASetLastError(errno);
1080 #endif
1081  return(0);
1082  }
1083  if( gethostbyaddr(ipaddr, sizeof(ipaddr), AF_INET) == (struct hostent *)0 )
1084  {
1085  errno = ECONNREFUSED;
1086 #ifdef WIN32
1087  WSASetLastError(errno);
1088 #endif
1089  return(0);
1090  }
1091 */
1092  }
1093 #else
1094  *(strchr(node,'.')) = '\0';
1095  host_addr = hostGetByName(node);
1096  printf("node %s addr: %x\n",node, host_addr);
1097 #endif
1098 
1099  if( (path = (int)socket(AF_INET, SOCK_STREAM, 0)) == -1 )
1100  {
1101  perror("socket");
1102  return(0);
1103  }
1104 
1105  val = 1;
1106 
1107  if ((ret_code = setsockopt(path, IPPROTO_TCP, TCP_NODELAY,
1108  (char*)&val, sizeof(val))) == -1 )
1109  {
1110 #ifdef DEBUG
1111  printf("Couln't set TCP_NODELAY\n");
1112 #endif
1113  closesock(path);
1114  return(0);
1115  }
1116 
1117  val = Write_buffer_size;
1118  if ((ret_code = setsockopt(path, SOL_SOCKET, SO_SNDBUF,
1119  (char*)&val, sizeof(val))) == -1 )
1120  {
1121 #ifdef DEBUG
1122  printf("Couln't set SO_SNDBUF\n");
1123 #endif
1124  closesock(path);
1125  return(0);
1126  }
1127 
1128  val = Read_buffer_size;
1129  if ((ret_code = setsockopt(path, SOL_SOCKET, SO_RCVBUF,
1130  (char*)&val, sizeof(val))) == -1 )
1131  {
1132 #ifdef DEBUG
1133  printf("Couln't set SO_RCVBUF\n");
1134 #endif
1135  closesock(path);
1136  return(0);
1137  }
1138 
1139 #if defined(__linux__) && !defined (darwin)
1140  val = 2;
1141  if ((ret_code = setsockopt(path, IPPROTO_TCP, TCP_SYNCNT,
1142  (char*)&val, sizeof(val))) == -1 )
1143  {
1144 #ifdef DEBUG
1145  printf("Couln't set TCP_SYNCNT\n");
1146 #endif
1147  }
1148 #endif
1149 
1150  sockname.sin_family = PF_INET;
1151 #ifndef VxWorks
1152  if(host_number)
1153  sockname.sin_addr = *((struct in_addr *) ipaddr);
1154  else
1155  sockname.sin_addr = *((struct in_addr *) host->h_addr);
1156 #else
1157  if(host_number)
1158  sockname.sin_addr = *((struct in_addr *) ipaddr);
1159  else
1160  sockname.sin_addr = *((struct in_addr *) &host_addr);
1161 #endif
1162  sockname.sin_port = htons((ushort) port); /* port number to send to */
1163  while((ret = connect(path, (struct sockaddr*)&sockname, sizeof(sockname))) == -1 )
1164  {
1165  if(errno != EINTR)
1166  {
1167  closesock(path);
1168  return(0);
1169  }
1170  }
1171  strcpy( Net_conns[conn_id].node, node );
1172  strcpy( Net_conns[conn_id].task, task );
1173  Net_conns[conn_id].channel = path;
1174  Net_conns[conn_id].port = port;
1175  Net_conns[conn_id].last_used = time(NULL);
1176  Net_conns[conn_id].reading = -1;
1177  Net_conns[conn_id].timr_ent = NULL;
1178  Net_conns[conn_id].write_timedout = 0;
1179  return(1);
1180 }
Definition: dns.c:26
TIMR_ENT * timr_ent
Definition: dim.h:413
DllExp DIM_NOSHARE NET_CONNECTION * Net_conns
Definition: conn_handler.c:32
#define ushort
Definition: tcpip.c:88
int dim_tcpip_init(int thr_flag)
Definition: tcpip.c:235
int channel
Definition: dim.h:398
int port
Definition: dim.h:409
time_t last_used
Definition: dim.h:414
Warning because the service this data corrsponds to might have been last updated longer ago than Local time
Definition: smartfact.txt:92
#define closesock(s)
Definition: tcpip.c:36
static int Write_buffer_size
Definition: tcpip.c:107
static int Read_buffer_size
Definition: tcpip.c:108
int check_node_addr(char *node, unsigned char *ipaddr)
Definition: tcpip.c:973
int write_timedout
Definition: dim.h:412
int reading
Definition: dim.h:410

+ Here is the call graph for this function:

+ Here is the caller graph for this function: