Mercurial > repos > rhope
diff runtime/net.c @ 152:e9a8269384bb
Add support for opening a new TCP connection and fix bug in Read Delim
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 05 Dec 2010 18:04:54 -0500 |
parents | 7bbdc034e347 |
children | 47ab97730865 |
line wrap: on
line diff
--- a/runtime/net.c Sun Dec 05 18:04:19 2010 -0500 +++ b/runtime/net.c Sun Dec 05 18:04:54 2010 -0500 @@ -37,7 +37,7 @@ int sockfd,flag=1; struct addrinfo hints, *localaddr; - snprintf(portstr, 6, "%d", port & 0XFFFF); + snprintf(portstr, 6, "%d", port & 0xFFFF); memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_UNSPEC; @@ -63,3 +63,28 @@ return sockfd; } +int _internal_connectnewsocket(char * addr, int32_t port) +{ + char portstr[6]; + struct addrinfo hints, *res; + int sock; + + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + + snprintf(portstr, 6, "%d", port & 0xFFFF); + if(getaddrinfo(addr, portstr, &hints, &res)) + return -1; + if(-1 == (sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol))) + return -1; + + if(connect(sock, res->ai_addr, res->ai_addrlen)) + { + close(sock); + sock = -1; + } + freeaddrinfo(res); + return sock; +} +