правда не до конца но по крайней мере сервера уже ищет.
может кому пригодится....
#include <winsock2.h>
#include <windows.h>
#include <ws2tcpip.h>
#include <stdio.h>
#include <stdlib.h>
int startWinsock(void)
{
WSADATA wsa;
return WSAStartup(MAKEWORD(2,0),&wsa);
}
int main(int argc, char *argv[])
{
long rc;
SOCKET s;
SOCKADDR_IN addr;
SOCKADDR_IN remoteAddr;
int remoteAddrLen = sizeof(remoteAddr);
char buf[256];
char info[]="\xff\xff\xff\xff"
"infostring\n\0";
memset(buf,0,strlen(buf));
rc=startWinsock();
if(rc!=0)
{
printf("Error : startWinsock, error code: %d\n",rc);
return 1;
}
s=socket(AF_INET,SOCK_DGRAM,0);
if(s==INVALID_SOCKET)
{
printf("Error: couldn't create the socket , error code: %d\n",WSAGetLastError());
closesocket(s);
WSACleanup;
exit(1);
}
int i = 27015;
int n=1;
rc = setsockopt(s,SOL_SOCKET,SO_BROADCAST,&n,sizeof(BOOL));
if (rc==SOCKET_ERROR)
{
printf("Error setting options %d\n",WSAGetLastError());
closesocket(s);
WSACleanup;
exit(1);
}
addr.sin_family=AF_INET;
addr.sin_addr.s_addr = INADDR_BROADCAST;
addr.sin_port=htons(i);
rc=sendto(s,info,strlen(info),0,(SOCKADDR*)&addr,sizeof(SOCKADDR_IN));
if(rc==SOCKET_ERROR)
{
printf("Error send, error code: %d\n",WSAGetLastError());
closesocket(s);
WSACleanup;
exit(1);
}
rc=recvfrom(s,buf,256,0,(SOCKADDR*)&remoteAddr,&remoteAddrLen);
if (rc=SOCKET_ERROR)
{
printf("Error receive data, code is %d\n",WSAGetLastError());
closesocket(s);
WSACleanup;
exit(1);
}
printf("Server : %s at port %d\n",inet_ntoa(remoteAddr.sin_addr),ntohs(remoteAddr.sin_port));
closesocket(s);
WSACleanup;
exit(0);
}