MCPcopy Create free account
hub / github.com/defold/defold / SendTo

Function SendTo

engine/dlib/src/dlib/socket_win32.cpp:520–551  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

518 }
519
520 Result SendTo(Socket socket, const void* buffer, int length, int* sent_bytes, Address to_addr, uint16_t to_port)
521 {
522 int result = 0;
523 if (IsSocketIPv4(socket))
524 {
525 assert(to_addr.m_family == DOMAIN_IPV4);
526
527 struct sockaddr_in sock_addr = { 0 };
528 sock_addr.sin_family = AF_INET;
529 sock_addr.sin_addr.s_addr = *IPv4(&to_addr);
530 sock_addr.sin_port = htons(to_port);
531
532 result = (int)sendto(socket, (const char*)buffer, length, 0, (const sockaddr*)&sock_addr, sizeof(sock_addr));
533 }
534#if !defined(DM_IPV6_UNSUPPORTED)
535 else if (IsSocketIPv6(socket))
536 {
537 assert(to_addr.m_family == DOMAIN_IPV6);
538
539 struct sockaddr_in6 sock_addr = { 0 };
540 sock_addr.sin6_family = AF_INET6;
541 memcpy(&sock_addr.sin6_addr, IPv6(&to_addr), sizeof(struct in6_addr));
542 sock_addr.sin6_port = htons(to_port);
543
544 result = (int)sendto(socket, (const char*)buffer, length, 0, (const sockaddr*)&sock_addr, sizeof(sock_addr));
545 }
546#endif // no ipv6
547 else
548 {
549 dmLogError("Failed to send to remote host, unsupported address family!");
550 return RESULT_AFNOSUPPORT;
551 }
552
553 *sent_bytes = result >= 0 ? result : 0;
554 return result >= 0 ? RESULT_OK : NativeToResultCompat(DM_SOCKET_ERRNO);

Callers 3

SendPacketFunction · 0.70
SendPacketToAddressFunction · 0.50
SendQueryAndCaptureFunction · 0.50

Calls 3

IPv4Function · 0.85
IsSocketIPv4Function · 0.70
assertFunction · 0.50

Tested by 2

SendPacketToAddressFunction · 0.40
SendQueryAndCaptureFunction · 0.40