Добавил:
Upload
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лабы по 2 RKG с нета / ПО сетей ЭВМ / Лаб_1 / Finger
.cpp#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;
}