Commit defacd42 authored by Elemer Lelik's avatar Elemer Lelik
Browse files

The actual listen port can be queried with ASP_Get_portnum

parent fd720df7
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2014 Ericsson
Copyright (c) 2016 Ericsson
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
......@@ -10,25 +10,16 @@
File: TELNETasp_CNL113320.tpd
Description: tpd project file
Rev: R8E
Rev: R9A
Prodnr: CNL 113 320
Updated: 2014-09-05
Contact: http://ttcn.ericsson.se
-->
<TITAN_Project_File_Information version="1.0">
<ProjectName>TELNETasp_CNL113320</ProjectName>
<ReferencedProjects>
<ReferencedProject name="Abstract_Socket_CNL113384" projectLocationURI="../Common_Components/Abstract_Socket_CNL113384/Abstract_Socket_CNL113384.tpd"/>
</ReferencedProjects>
<Folders>
<FolderResource projectRelativePath="doc" relativeURI="doc"/>
<FolderResource projectRelativePath="src" relativeURI="src"/>
</Folders>
<Files>
<FileResource projectRelativePath="doc/TELNETasp_CNL113320_FS.pdf" relativeURI="doc/TELNETasp_CNL113320_FS.pdf"/>
<FileResource projectRelativePath="doc/TELNETasp_CNL113320_PRI.pdf" relativeURI="doc/TELNETasp_CNL113320_PRI.pdf"/>
<FileResource projectRelativePath="doc/TELNETasp_CNL113320_UG.pdf" relativeURI="doc/TELNETasp_CNL113320_UG.pdf"/>
<FileResource projectRelativePath="src/TELNETasp_PT.cc" relativeURI="src/TELNETasp_PT.cc"/>
<FileResource projectRelativePath="src/TELNETasp_PT.hh" relativeURI="src/TELNETasp_PT.hh"/>
<FileResource projectRelativePath="src/TELNETasp_PortType.ttcn" relativeURI="src/TELNETasp_PortType.ttcn"/>
......@@ -52,14 +43,6 @@
<formalParameter>.*</formalParameter>
</NamingCoventions>
</ProjectProperties>
<FolderProperties>
<FolderResource>
<FolderPath>doc</FolderPath>
<FolderProperties>
<ExcludeFromBuild>true</ExcludeFromBuild>
</FolderProperties>
</FolderResource>
</FolderProperties>
</Configuration>
</Configurations>
</TITAN_Project_File_Information>
File mode changed from 100755 to 100644
......@@ -21,7 +21,7 @@
//
// File: TELNETasp_PT.cc
// Description: TELNET testport source file
// Rev: R8H
// Rev: R9A
// Prodnr: CNL 113 320
//
......@@ -584,13 +584,14 @@ set_asp_params();
config_finished = true;
suppressed = false;
if(ctrl_portnum == 0)
TTCN_error("Missing mandatory parameter: CTRL_PORTNUM");
if (!server_mode_def){
TTCN_warning("Mode is not defined. Test Port will operate in client mode operation.");
server_mode = false;
}
if((!server_mode) && (ctrl_portnum == 0)) // The portnum can be zero in server mode. The actual listen port is printed out in WARNING
TTCN_error("Missing mandatory parameter: CTRL_PORTNUM");
struct sockaddr_in address;
int enabled = 1;
......@@ -634,9 +635,20 @@ if (server_mode){
memset(&(address.sin_zero), '\0', 8);
if ( bind(fd_server, (struct sockaddr*)&address, sizeof(address)) < 0 )
TTCN_error("Error bindig socket to port %d", ctrl_portnum);
TTCN_error("%s: Error bindig socket to port %d. Reason: %d %s",port_name ,ctrl_portnum,errno,strerror(errno));
if (listen(fd_server,1) < 0 )
TTCN_error("Error listening on port %d", ctrl_portnum);
TTCN_error("%s: Error listening on port %d",port_name ,ctrl_portnum);
if(ctrl_portnum==0){ // ephemeral port, get the used one
struct sockaddr_in sin;
socklen_t len = sizeof(sin);
if (getsockname(fd_server, (struct sockaddr *)&sin, &len) == -1){
TTCN_warning("%s : Can not get the listen port number errno:%d %s",port_name,errno,strerror(errno));
} else {
ctrl_portnum=ntohs(sin.sin_port);
TTCN_warning("%s : The TELNET listen port: %d",port_name,ctrl_portnum);
}
}
// FD_ZERO(&readfds);
// FD_SET(fd_server, &readfds);
......@@ -1014,6 +1026,13 @@ void TELNETasp__PT::outgoing_send(const ASP__TelnetPortParameters& send_par)
asp_params = new ASP__TelnetPortParameters(send_par);
}
void TELNETasp__PT::outgoing_send(const ASP__Get__portnum& /*send_par*/)
{
ASP__Portnum msg;
msg.local__port__num()=ctrl_portnum;
incoming_message(msg);
}
void TELNETasp__PT::outgoing_send(const ASP__TelnetDynamicConfig& send_par)
{
switch(send_par.get_selection()) {
......
......@@ -21,7 +21,7 @@
//
// File: TELNETasp_PT.hh
// Description: TELNET testport header file
// Rev: R8H
// Rev: R9A
// Prodnr: CNL 113 320
//
......@@ -156,8 +156,8 @@ protected:
void outgoing_send(const ASP__TelnetPortParameters& send_par);
void outgoing_send(const ASP__TelnetDynamicConfig& send_par);
void outgoing_send(const ASP__TelnetConnection& send_par);
void outgoing_send(const ASP__TelnetClose& send_par);
void outgoing_send(const ASP__TelnetClose& send_par);
void outgoing_send(const ASP__Get__portnum&);
void InitStrPar(char *&par, const char *name, const char *val);
int ProcessCmd(unsigned char * buf, int buflen);
int ProcessNoCmd(unsigned char * buf, int buflen);
......
......@@ -21,7 +21,7 @@
//
// File: TELNETasp_PortType.ttcn
// Description: TELNET testport port definition file
// Rev: R8H
// Rev: R9A
// Prodnr: CNL 113 320
//
......@@ -86,14 +86,20 @@ module TELNETasp_PortType
type record ASP_TelnetClose {}
type port TELNETasp_PT message
type record ASP_Get_portnum {} // Querries the local port number
type record ASP_Portnum{
integer local_port_num // The listening port number.
}
type port TELNETasp_PT message
{
inout charstring;
in integer;
in ASP_Portnum;
out ASP_TelnetPortParameters,
ASP_TelnetDynamicConfig,
ASP_TelnetConnection,
ASP_TelnetClose;
ASP_TelnetClose,
ASP_Get_portnum;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment