socket: Move host:port parsing to socket function

This commit is contained in:
Kim Woelders
2023-02-12 22:12:59 +01:00
parent a49f95a300
commit a978e86c82
3 changed files with 23 additions and 38 deletions
+6 -25
View File
@@ -46,8 +46,6 @@ static struct ttynvt_param {
int logstd;
const char *close_delay;
/* Derived */
char host[64];
unsigned int port;
unsigned int close_delay_us;
/* Picked up */
int foreground;
@@ -416,8 +414,7 @@ static void ttynvt_open(fuse_req_t req, struct fuse_file_info *info)
pthread_mutex_lock(&access_lock);
nvt_log(LOG_INFO, "Connecting to server: %s:%d\n",
ttynvt_param.host, ttynvt_param.port);
nvt_log(LOG_INFO, "Connecting to server: %s\n", ttynvt_param.server);
tty = _ttynvt_ctx_create();
if (!tty)
@@ -426,7 +423,7 @@ static void ttynvt_open(fuse_req_t req, struct fuse_file_info *info)
return;
}
fd = socket_create_client(ttynvt_param.host, ttynvt_param.port);
fd = socket_create_client(ttynvt_param.server);
if (fd < 0)
{
errno = EHOSTUNREACH;
@@ -488,8 +485,7 @@ static void ttynvt_open(fuse_req_t req, struct fuse_file_info *info)
info->nonseekable = 1;
info->direct_io = 1;
nvt_log(LOG_INFO, "Connected to server: %s:%d\n",
ttynvt_param.host, ttynvt_param.port);
nvt_log(LOG_INFO, "Connected to server: %s\n", ttynvt_param.server);
fuse_reply_open(req, info);
return;
@@ -502,8 +498,8 @@ static void ttynvt_open(fuse_req_t req, struct fuse_file_info *info)
fuse_reply_err(req, errno);
nvt_log(LOG_ERR, "Connection to server: %s:%d failed: %m\n",
ttynvt_param.host, ttynvt_param.port);
nvt_log(LOG_ERR, "Connection to server: %s failed: %m\n",
ttynvt_param.server);
pthread_mutex_unlock(&access_lock);
}
@@ -1117,8 +1113,7 @@ static void ttynvt_release(fuse_req_t req, struct fuse_file_info *info)
fuse_reply_err(req, 0);
nvt_log(LOG_INFO, "Disconnected from server: %s:%d\n",
ttynvt_param.host, ttynvt_param.port);
nvt_log(LOG_INFO, "Disconnected from server: %s\n", ttynvt_param.server);
pthread_mutex_unlock(&access_lock);
}
@@ -1214,20 +1209,6 @@ int main(int argc, char *argv[])
return 1;
}
rc = sscanf(ttynvt_param.server, "%63[^:]:%u", ttynvt_param.host,
&ttynvt_param.port);
if (rc <= 1)
{
fprintf(stderr, "Bad server specification: '%s'\n",
ttynvt_param.server);
return 1;
}
if (ttynvt_param.port == 0)
{
fprintf(stderr, "Bad server port: %u\n", ttynvt_param.port);
return 1;
}
snprintf(dev_name, sizeof(dev_name), "DEVNAME=%s", ttynvt_param.dev_name);
if (ttynvt_param.close_delay)