Exemplo n.º 1
0
/*
 * This function checks the number of the arguments
 * as well as user's permission on the target file.
 * The connectability to the specified server will be checked later.
 */
int preCheckArgs(int argc, char *argv[]) {
	struct in_addr ipAddr;
	// check the number of arguments
	if(argc != 4) {
		fprintf(stderr, "ftpc: ERROR: Wrong usage of ftpc.\n");
		fprintf(stderr, "             Please use the following pattern to launch the ftpc program.\n");
		fprintf(stderr, "             $ ftpc <host-ip> <remote-port> <local-file-to-transfer>\n");
		return -1;
	}
	
	// check the IP address
	ipAddr.s_addr = inet_addr(argv[1]);
	if(gethostbyaddr((char *)&ipAddr, sizeof(ipAddr), AF_INET)  == NULL) {
		fprintf(stderr, "ftpc: ERROR: Invalid IP address %s.\n", argv[1]);
		return -1;
	}

	// check the port
	if(checkPort(argv[2]) == -1) {
		fprintf(stderr, "ftpc: ERROR: Invalid port number %s.\n", argv[2]);
		return -1;
	}

	// check the length of the file name
	if(strlen(argv[3]) > 20) {
		fprintf(stderr, "ftpc: ERROR: File name is longer than 20 Bytes.\n");
		return -1;
	}

	// check the permission of the local file
	if(access(argv[3], R_OK) == -1) {
		fprintf(stderr, "ftpc: ERROR: Can't open the target file %s to read.\n", argv[3]);
		return -1;
	}
}
SerialPort::SerialPort(QWidget *parent) : QDialog(parent)
{
	setupUi(this);
	serial=new QextSerialPort();
	timer=new QTimer(this);
	connect(timer, SIGNAL(timeout()), this, SLOT(checkPort()));
}
Exemplo n.º 3
0
int ObjectBinding::index( lua_State* L )
{
	co::IObject** ud = reinterpret_cast<co::IObject**>( lua_touserdata( L, 1 ) );
	assert( ud );
	assert( lua_isstring( L, 2 ) );

	__BEGIN_EXCEPTIONS_BARRIER__

	co::IObject* object = *ud;

	if( isStringComponent( L, 2 ) )
	{
		LuaState::push( L, object->getComponent() );
		return 1;
	}

	if( pushMember( L, object->getComponent() ) )
	{
		assert( lua_islightuserdata( L, -1 ) );
		co::IPort* port = checkPort( L, -1 );
		co::IService* service = object->getServiceAt( port );
		LuaState::push( L, service );

		// notify interceptors
		for( co::Range<IInterceptor* const> r( sm_interceptors ); r; r.popFirst() )
			r.getFirst()->postGetService( object, port, service );
	}

	return 1;

	__END_EXCEPTIONS_BARRIER__
}
Exemplo n.º 4
0
SettingsDialog::SettingsDialog(QWidget * parent) :
	QDialog(parent),
	m_allowCheckPort(false)
{
	if(!QFileInfo("G:\\profily\\").isDir())
	{
		m_settings =  new QSettings(this);
	}
	else
	{
		m_settings = new QSettings("G:\\profily\\RD2prog\\settings.ini", QSettings::IniFormat, this);
	}

	ui.setupUi(this);

	ui.comboBoxPort->addItems(SerialPortInterface::getPorts());

	connect(this, SIGNAL(accepted()), this, SLOT(saveSettings()));
	connect(ui.lineEditPath, SIGNAL(textEdited(QString)), this, SLOT(checkAssemblerPath(QString)));

	loadSettings();

	checkAssemblerPath(ui.lineEditPath->text());

	m_allowCheckPort = true;
	checkPort();
}
Exemplo n.º 5
0
NetworkAddress::NetworkAddress(int port) :
    m_address(nullptr),
    m_port(port)
{
    checkPort();
    m_address = ARCH->newAnyAddr(IArchNetwork::kINET);
    ARCH->setAddrPort(m_address, m_port);
}
Exemplo n.º 6
0
CNetworkAddress::CNetworkAddress(int port) :
	m_address(NULL),
	m_hostname(),
	m_port(port)
{
	checkPort();
	m_address = ARCH->newAnyAddr(IArchNetwork::kINET);
	ARCH->setAddrPort(m_address, m_port);
}
Exemplo n.º 7
0
/*--------------------------------------------------------------------------------------
 * Purpose: Sets port for the login listener
 * Input: char * - the address
 * Kevin Burnett @ January 26, 2009
 * -------------------------------------------------------------------------------------*/
int setListenPort(int port) {
	if(checkPort(port)) {
		return 1;
	}
	else {
		LoginSettings.listenPort = port;
		return 0;
	}
}
Exemplo n.º 8
0
mocca::net::TCPNetworkAddress::TCPNetworkAddress(const std::string& address) {
    auto parts = mocca::splitString<std::string>(address, ':');
    if (parts.size() != 2) {
        throw Error("TCP connection string is malformed, must have the format 'ip:port'", __FILE__, __LINE__);
    }
    auto ip = parts.front();
    auto port = parsePort(parts.back());
    checkIp(ip);
    checkPort(port);
    ip_ = ip;
    port_ = port;
}
Exemplo n.º 9
0
CNetworkAddress::CNetworkAddress(const CString& hostname, int port) :
	m_address(NULL),
	m_hostname(hostname),
	m_port(port)
{
	// check for port suffix
	CString::size_type i = m_hostname.rfind(':');
	if (i != CString::npos && i + 1 < m_hostname.size()) {
		// found a colon.  see if it looks like an IPv6 address.
		bool colonNotation = false;
		bool dotNotation   = false;
		bool doubleColon   = false;
		for (CString::size_type j = 0; j < i; ++j) {
			if (m_hostname[j] == ':') {
				colonNotation = true;
				dotNotation   = false;
				if (m_hostname[j + 1] == ':') {
					doubleColon = true;
				}
			}
			else if (m_hostname[j] == '.' && colonNotation) {
				dotNotation = true;
			}
		}

		// port suffix is ambiguous with IPv6 notation if there's
		// a double colon and the end of the address is not in dot
		// notation.  in that case we assume it's not a port suffix.
		// the user can replace the double colon with zeros to
		// disambiguate.
		if ((!doubleColon || dotNotation) || !colonNotation) {
			// parse port from hostname
			char* end;
			const char* chostname = m_hostname.c_str();
			long suffixPort = strtol(chostname + i + 1, &end, 10);
			if (end == chostname + i + 1 || *end != '\0') {
				throw XSocketAddress(XSocketAddress::kBadPort,
											m_hostname, m_port);
			}

			// trim port from hostname
			m_hostname.erase(i);

			// save port
			m_port = static_cast<int>(suffixPort);
		}
	}

	// check port number
	checkPort();
}
Exemplo n.º 10
0
int ObjectBinding::newIndex( lua_State* L )
{
	co::IObject** ud = reinterpret_cast<co::IObject**>( lua_touserdata( L, 1 ) );
	assert( ud );
	assert( lua_isstring( L, 2 ) );

	__BEGIN_EXCEPTIONS_BARRIER__

	if( isStringComponent( L, 2 ) )
		throw co::IllegalArgumentException( "'component' is a facet and cannot be set" );

	co::IObject* object = *ud;
	pushMember( L, object->getComponent(), true );
	if( lua_islightuserdata( L, -1 ) )
	{
		co::IPort* port = checkPort( L, -1 );
		if( port->getIsFacet() )
		{
			lua_pushliteral( L, "'" );
			lua_pushvalue( L, 2 );
			lua_pushliteral( L, "' is a facet and cannot be set" );
			lua_concat( L, 3 );
			throw lua::MsgOnStackException();
		}
		co::IService* service;
		co::Any any;
		any.setVariable( port->getType(), co::Any::VarIsPointer|co::Any::VarIsReference, &service );
		LuaState::getValue( L, 3, any );
		object->setServiceAt( port, service );

		// notify interceptors
		for( co::Range<IInterceptor* const> r( sm_interceptors ); r; r.popFirst() )
			r.getFirst()->postSetService( object, port, service );
	}

	return 0;

	__END_EXCEPTIONS_BARRIER__
}
Exemplo n.º 11
0
void SettingsDialog::on_pushButton_clicked()
{
	m_allowCheckPort = false;

	QString name = ui.comboBoxPort->currentText();
	ui.comboBoxPort->clear();
	ui.comboBoxPort->addItems(SerialPortInterface::getPorts());

	if(ui.comboBoxPort->currentText() != name)
	{
		for(int i = 0; i < ui.comboBoxPort->count(); ++i)
		{
			if(ui.comboBoxPort->itemText(i) == name)
			{
				ui.comboBoxPort->setCurrentIndex(i);
				break;
			}
		}
	}

	m_allowCheckPort = true;
	checkPort();
}
Exemplo n.º 12
0
WaterCycle::WaterCycle(QObject *parent) : QObject(parent)
{
    m_time = new QTime;
    m_timer = new QTimer;

    QSerialPort *serialPort = checkPort();

    if (serialPort)
    {
        m_serialPort = serialPort;
        if (!m_serialPort->isOpen())
            m_serialPort->open(QIODevice::ReadWrite);
        //connect(m_serialPort,SIGNAL(error(QSerialPort::SerialPortError)),SLOT(handleError(QSerialPort::SerialPortError)));
    }
    else
    {
        qDebug() << "Open serial port failed !";
    }

    m_bytesRead = "";
    m_queryOrder = 1;

    connect(m_timer, SIGNAL(timeout()), this, SLOT(timerSlot()));
}
Exemplo n.º 13
0
TCPNetworkAddress::TCPNetworkAddress(const std::string& ip, int port) {
    checkIp(ip);
    checkPort(port);
    ip_ = ip;
    port_ = port;
}
Exemplo n.º 14
0
/**
 * main
 */
int main(int argc, char** argv)
{
firstEntry = lastEntry = NULL;

if (argc != 3)
{
	usage();
	exit(1);
}

int opt;
while ((opt = getopt(argc, argv, "p:")) != -1)
{
	switch (opt)
	{
	case 'p':
		serverPort = checkPort(optarg);
		break;
	default:
		usage();
		exit(1);
	}
}

uint16_t currentPort = serverPort + 1;
fd_set fds;
clientLength = sizeof(client);
char* clientMessage = (char*) malloc(256 * sizeof(char));

if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
	printf("Error creating socket.\n");

server.sin_family = AF_INET;
server.sin_port = htons(serverPort);
server.sin_addr.s_addr = htonl(INADDR_ANY);

if (bind(fd, (struct sockaddr*) &server, sizeof(server)) == -1)
	printf("Error binding socket.\n");
else
	printf("Server set up and ready to use.\n");

// main loop for receiving new user requests.
while (1)
{
	FD_ZERO(&fds);
	FD_SET(fd, &fds);

	if (select(fd + 1, &fds, 0, 0, 0) < 0)
		printf("Error in select.\n");

	if (FD_ISSET(fd, &fds))
	{
		if (recvfrom(fd, clientMessage, sizeof(char) * 256, 0,
				(struct sockaddr*) &client, &clientLength) == -1)
			printf("Error receiving message from new user.\n");
		else
		{
			//receive CL_CON_REQ
			if (clientMessage[0] == CL_CON_REQ)
			{
				addUser(clientMessage, client, currentPort, fd);
				if (currentPort++ == 65535)
					currentPort = 1025;
			}
		}
	}
}
return 0;
}
Exemplo n.º 15
0
void PortInfo::run()
{
    QTimer::singleShot(0, this, SLOT(checkPort()));
    exec();
}
Exemplo n.º 16
0
void SettingsDialog::on_comboBoxPort_currentIndexChanged(const QString & port)
{
	m_portSettings.m_name = port;

	checkPort();
}
Exemplo n.º 17
0
void SettingsDialog::on_comboBoxBaudrate_currentIndexChanged(const QString & speed)
{
	m_portSettings.m_baudrate = speed.toInt();

	checkPort();
}