diff options
author | IOhannes m zmölnig <zmoelnig@users.sourceforge.net> | 2015-09-04 20:25:36 +0000 |
---|---|---|
committer | IOhannes m zmölnig <zmoelnig@users.sourceforge.net> | 2015-09-04 20:25:36 +0000 |
commit | 252afc9aa22d922fed7caa5c7c39ce2e8d9d7927 (patch) | |
tree | 9d4652a6317329727e253becc057ae65058960d5 /tcpsend.c | |
parent | 3383ee9e68a2226794cc923f853585b256eccdf5 (diff) |
resolve hostname before opening a socket.
so we can do an early return, without having to care about closing
sockets...
CID:27769
also fix comments (we don't have a "command line")
svn path=/trunk/externals/iem/iemnet/; revision=17550
Diffstat (limited to 'tcpsend.c')
-rw-r--r-- | tcpsend.c | 17 |
1 files changed, 10 insertions, 7 deletions
@@ -69,6 +69,14 @@ static void tcpsend_connect(t_tcpsend *x, t_symbol *hostname, return; } + /* resolve hostname provided as argument */ + server.sin_family = AF_INET; + hp = gethostbyname(hostname->s_name); + if (hp == 0) { + iemnet_log(x, IEMNET_ERROR, "bad host '%s'?", hostname->s_name); + return; + } + /* create a socket */ sockfd = socket(AF_INET, SOCK_STREAM, 0); DEBUG("send socket %d\n", sockfd); @@ -77,13 +85,7 @@ static void tcpsend_connect(t_tcpsend *x, t_symbol *hostname, sys_sockerror("socket"); return; } - /* connect socket using hostname provided in command line */ - server.sin_family = AF_INET; - hp = gethostbyname(hostname->s_name); - if (hp == 0) { - iemnet_log(x, IEMNET_ERROR, "bad host '%s'?", hostname->s_name); - return; - } + /* for stream (TCP) sockets, specify "nodelay" */ intarg = 1; if (setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, @@ -92,6 +94,7 @@ static void tcpsend_connect(t_tcpsend *x, t_symbol *hostname, sys_sockerror("setsockopt"); } + /* connect socket using hostname provided as argument */ memcpy((char *)&server.sin_addr, (char *)hp->h_addr, hp->h_length); /* assign client port number */ |