Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
2
Добавлен:
13.02.2016
Размер:
1.14 Кб
Скачать
#include <winsock2.h>
#include <iostream.h>
#include <time.h>
#include <stdio.h>
#include <conio.h>
int Finger(char * strHost, char * strCmd)
{
	int s, res;
	sockaddr_in clnt_sin;
	char buf[1000];

	WSADATA wsaData;

	if (WSAStartup(MAKEWORD(1,1), &wsaData))
	{
		cout << "WSAStartup failed";
		return 1;
	}

	if ((s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == INVALID_SOCKET)
	{
		cout << "Socket failed" << endl;
		return 2;
	}

	memset((char *)&clnt_sin, NULL, sizeof(clnt_sin));
	clnt_sin.sin_family = AF_INET;
	clnt_sin.sin_addr.s_addr = inet_addr(strHost);
	clnt_sin.sin_port = htons(79);

	res = connect(s,(sockaddr *)&clnt_sin, sizeof(clnt_sin));
	if (res == SOCKET_ERROR)
	{
		cout << "Connect failed" << endl;
		return 4;
	}

	if (send(s, strCmd, strlen(strCmd), 0) == SOCKET_ERROR)
	{
		cout << "Send failed" << endl;
		return 5;
	}

	int bufl = sizeof(buf);
	if ((bufl = recv(s, buf, bufl, 0)) == SOCKET_ERROR)
	{
		cout << "Recv failed" << endl;
		return 6;
	}

	buf[bufl] = NULL;
	cout << buf << endl;

	closesocket(s);
	WSACleanup();
    getch();
	return 0;
}
Соседние файлы в папке Лаб_1
  • #
    13.02.20161.14 Кб2Finger.cpp
  • #
    13.02.2016416 б2lab1_1.cpp
  • #
    13.02.20164.3 Кб2lab1_1.dsp
  • #
    13.02.2016537 б2lab1_1.dsw
  • #
    13.02.201625.6 Кб2lab1_1.ncb
  • #
    13.02.201653.76 Кб2lab1_1.opt