diff --git a/libipm/scp.c b/libipm/scp.c index 149eccf9..de0028d7 100644 --- a/libipm/scp.c +++ b/libipm/scp.c @@ -195,7 +195,38 @@ scp_init_trans(struct trans *trans) } /*****************************************************************************/ +struct trans * +scp_init_trans_from_fd(int fd, int trans_type, int (*term_func)(void)) +{ + struct trans *result; + if ((result = trans_create(TRANS_MODE_UNIX, 128, 128)) == NULL) + { + LOG(LOG_LEVEL_ERROR, "Can't create SCP transport [%s]", + g_get_strerror()); + } + else + { + result->sck = fd; + result->type1 = trans_type; + result->status = TRANS_STATUS_UP; + result->is_term = term_func; + // Make sure child processes don't inherit our FD + (void)g_file_set_cloexec(result->sck, 1); + + if (scp_init_trans(result) != 0) + { + LOG(LOG_LEVEL_ERROR, "scp_init_trans() call failed"); + trans_delete(result); + result = NULL; + } + } + + return result; +} + + +/*****************************************************************************/ int scp_msg_in_check_available(struct trans *trans, int *available) { diff --git a/libipm/scp.h b/libipm/scp.h index edb51536..eec86c4f 100644 --- a/libipm/scp.h +++ b/libipm/scp.h @@ -125,7 +125,7 @@ scp_connect(const char *port, * Converts a standard trans connected to an SCP endpoint to an SCP transport * * If you are running on a client, you may wish to use - * scp_send_set_peername_request() after the commnect to inform the + * scp_send_set_peername_request() after the connect to inform the * server who you are. * * @param trans connected endpoint @@ -134,6 +134,22 @@ scp_connect(const char *port, int scp_init_trans(struct trans *trans); +/** + * Creates an SCP transport from a file descriptor + * + * If you are running on a client, you may wish to use + * scp_send_set_peername_request() after the connect to inform the + * server who you are. + * + * @param fd file descriptor + * @param trans_type TRANS_TYPE_SERVER or TRANS_TYPE_CLIENT + * @param term_func Function to poll during connection for program + * termination, or NULL for none. + * @return SCP transport, or NULL + */ +struct trans * +scp_init_trans_from_fd(int fd, int trans_type, int (*term_func)(void)); + /** * Checks an SCP transport to see if a complete message is * available for parsing