FreeNOS
lib
libposix
sys
socket
sendto.cpp
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2015 Niek Linnenbank
3
*
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation, either version 3 of the License, or
7
* (at your option) any later version.
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
*/
17
18
#include <
NetworkClient.h
>
19
#include <
stdlib.h
>
20
#include <
unistd.h
>
21
#include <
string.h
>
22
#include <
sys/socket.h
>
23
#include <
errno.h
>
24
25
extern
C
int
sendto
(
int
sockfd,
const
void
*buf,
size_t
len,
int
flags
,
26
const
struct
sockaddr
*
addr
,
socklen_t
addrlen)
27
{
28
char
packet[2048];
29
NetworkClient::SocketInfo
info;
30
31
if
(len >
sizeof
(packet) - addrlen)
32
return
ERANGE
;
33
34
info.
address
=
addr
->addr;
35
info.
port
=
addr
->port;
36
info.
action
=
NetworkClient::SendSingle
;
37
38
memcpy
(packet, &info,
sizeof
(info));
39
memcpy
(packet +
sizeof
(info), buf, len);
40
41
return ::write
(sockfd, packet, len +
sizeof
(info));
42
}
write
ssize_t write(int fildes, const void *buf, size_t nbyte)
Write on a file.
Definition:
write.cpp:22
socklen_t
Size socklen_t
Definition:
socket.h:50
string.h
flags
u32 flags
Definition:
IntelACPI.h:66
NetworkClient::SocketInfo::address
IPV4::Address address
Definition:
NetworkClient.h:67
NetworkClient::SocketInfo::port
u16 port
Definition:
NetworkClient.h:68
sockaddr
Defines a socket address and port pair.
Definition:
socket.h:35
C
#define C
Used to define external C functions.
Definition:
Macros.h:134
sendto
C int sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *addr, socklen_t addrlen)
Send a single datagram to a remote host.
Definition:
sendto.cpp:25
NetworkClient::SendSingle
@ SendSingle
Definition:
NetworkClient.h:55
sockaddr::addr
u32 addr
Definition:
socket.h:37
unistd.h
NetworkClient::SocketInfo
Socket information.
Definition:
NetworkClient.h:65
socket.h
ERANGE
#define ERANGE
Result too large.
Definition:
errno.h:259
stdlib.h
memcpy
void * memcpy(void *dest, const void *src, size_t count)
Copy memory from one place to another.
Definition:
memcpy.cpp:20
NetworkClient.h
NetworkClient::SocketInfo::action
u16 action
Definition:
NetworkClient.h:69
errno.h
Generated by
1.8.17