+ if (memcmp(pcPortName, "tcp:", 4) == 0) {
+ struct addrinfo *addr = NULL, *rp;
+ char *addrstr = strdup(pcPortName + 4);
+ if (addrstr == NULL) {
+ printf("Error: strdup\n");
+ return INVALID_SERIAL_PORT;
+ }
+ char *colon = strrchr(addrstr, ':');
+ char *portstr;
+
+ // Set time-out to 300 miliseconds only for TCP port
+ timeout.tv_usec = 300000;
+
+ if (colon) {
+ portstr = colon + 1;
+ *colon = '\0';
+ } else
+ portstr = "7901";
+
+ struct addrinfo info;
+
+ memset (&info, 0, sizeof(info));
+
+ info.ai_socktype = SOCK_STREAM;
+
+ int s = getaddrinfo(addrstr, portstr, &info, &addr);
+ if (s != 0) {
+ printf("Error: getaddrinfo: %s\n", gai_strerror(s));
+ return INVALID_SERIAL_PORT;
+ }
+
+ int sfd;
+ for (rp = addr; rp != NULL; rp = rp->ai_next) {
+ sfd = socket(rp->ai_family, rp->ai_socktype,
+ rp->ai_protocol);
+ if (sfd == -1)
+ continue;
+
+ if (connect(sfd, rp->ai_addr, rp->ai_addrlen) != -1)
+ break;
+
+ close(sfd);
+ }
+
+ if (rp == NULL) { /* No address succeeded */
+ printf("Error: Could not connect\n");
+ return INVALID_SERIAL_PORT;
+ }
+
+ freeaddrinfo(addr);
+ free(addrstr);
+
+ sp->fd = sfd;
+
+ int one = 1;
+ setsockopt(sp->fd, SOL_TCP, TCP_NODELAY, &one, sizeof(one));
+ return sp;
+ }
+