18,356
社区成员
发帖
与我相关
我的任务
分享
UdpSend( ULONG host_addr, int port_no, const char *buf, int len )
{
sockaddr_in addr; memset( &addr, 0, sizeof( addr ) ); addr.sin_family = AF_INET; addr.sin_port = port_no; addr.sin_addr.s_addr = host_addr;
if( ::sendto( udp_sd, buf, len, 0, ( LPSOCKADDR )&addr, sizeof( addr ) ) == SOCKET_ERROR )
{
switch ( WSAGetLastError( ) )
{
case WSAENETDOWN: break;
case WSAEHOSTUNREACH: static BOOL done; if( done == FALSE ){ done = TRUE; } return FALSE;
default: return FALSE;
}
if( WSockReset( ) != TRUE ){ return FALSE; }
if( hAsyncWnd && AsyncSelectRegist( hAsyncWnd ) != TRUE ){ return FALSE; }
if( ::sendto( udp_sd, buf, len, 0, ( LPSOCKADDR )&addr, sizeof( addr ) ) == SOCKET_ERROR ){ return FALSE; }
}
return TRUE;
}