UdpSocket: writing does not crash anymore if the target is not defined.
[GB.NET] * BUG: UdpSocket: writing does not crash anymore if the target is not defined.
This commit is contained in:
parent
e072bdd11f
commit
ae21ed7f77
1 changed files with 19 additions and 29 deletions
|
@ -41,6 +41,9 @@
|
|||
|
||||
#include "CUdpSocket.h"
|
||||
|
||||
DECLARE_EVENT (EVENT_Read);
|
||||
DECLARE_EVENT (EVENT_SocketError);
|
||||
|
||||
GB_STREAM_DESC UdpSocketStream = {
|
||||
.open = CUdpSocket_stream_open,
|
||||
.close = CUdpSocket_stream_close,
|
||||
|
@ -54,9 +57,18 @@ GB_STREAM_DESC UdpSocketStream = {
|
|||
.handle = CUdpSocket_stream_handle
|
||||
};
|
||||
|
||||
|
||||
DECLARE_EVENT (EVENT_Read);
|
||||
DECLARE_EVENT (EVENT_SocketError);
|
||||
static bool fill_in_addr(struct in_addr *addr, const char *str)
|
||||
{
|
||||
if (!str || !*str)
|
||||
addr->s_addr = htonl(INADDR_ANY);
|
||||
else if (inet_aton(str, addr) == 0)
|
||||
{
|
||||
GB.Error("Incorrect address");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void CUdpSocket_post_data(intptr_t Param)
|
||||
{
|
||||
|
@ -236,7 +248,7 @@ int CUdpSocket_stream_write(GB_STREAM *stream, char *buffer, int len)
|
|||
{
|
||||
void *_object = stream->tag;
|
||||
int retval;
|
||||
struct in_addr dest_ip;
|
||||
//struct in_addr dest_ip;
|
||||
NET_ADDRESS dest;
|
||||
size_t size;
|
||||
struct sockaddr *addr;
|
||||
|
@ -254,18 +266,9 @@ int CUdpSocket_stream_write(GB_STREAM *stream, char *buffer, int len)
|
|||
}
|
||||
else
|
||||
{
|
||||
/*if (THIS->broadcast)
|
||||
{
|
||||
fprintf(stderr, "broadcast\n");
|
||||
dest.in.sin_addr.s_addr = INADDR_BROADCAST;
|
||||
}
|
||||
else*/
|
||||
{
|
||||
if (!inet_aton((const char*)THIS->thost, &dest_ip))
|
||||
return -1;
|
||||
dest.in.sin_addr.s_addr = dest_ip.s_addr;
|
||||
}
|
||||
|
||||
if (fill_in_addr(&dest.in.sin_addr, THIS->thost))
|
||||
return -1;
|
||||
//dest.in.sin_addr.s_addr = dest_ip.s_addr;
|
||||
dest.in.sin_family = PF_INET;
|
||||
dest.in.sin_port = htons(THIS->tport);
|
||||
size = sizeof(struct sockaddr);
|
||||
|
@ -332,19 +335,6 @@ static bool update_multicast_ttl(CUDPSOCKET *_object)
|
|||
"Cannot set multicast ttl socket option: &1");
|
||||
}
|
||||
|
||||
static bool fill_in_addr(struct in_addr *addr, const char *str)
|
||||
{
|
||||
if (!str || !*str)
|
||||
addr->s_addr = htonl(INADDR_ANY);
|
||||
else if (inet_aton(str, addr) == 0)
|
||||
{
|
||||
GB.Error("Incorrect address");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void dgram_start(CUDPSOCKET *_object)
|
||||
{
|
||||
sa_family_t domain;
|
||||
|
|
Loading…
Reference in a new issue