xref: /reactos/base/services/dhcpcsvc/dhcp/socket.c (revision 1734f297)
1 #include <rosdhcp.h>
2 
3 SOCKET ServerSocket;
4 
5 void SocketInit() {
6     ServerSocket = socket( AF_INET, SOCK_DGRAM, 0 );
7 }
8 
9 ssize_t send_packet( struct interface_info *ip,
10                      struct dhcp_packet *p,
11                      size_t size,
12                      struct in_addr addr,
13                      struct sockaddr_in *broadcast,
14                      struct hardware *hardware ) {
15     int result;
16 
17     if (size > INT_MAX)
18         return WSAEMSGSIZE;
19 
20     result =
21         sendto( ip->wfdesc, (char *)p, (int)size, 0,
22                 (struct sockaddr *)broadcast, sizeof(*broadcast) );
23 
24     if (result < 0) {
25         note ("send_packet: %x", result);
26         if (result == WSAENETUNREACH)
27             note ("send_packet: please consult README file%s",
28                   " regarding broadcast address.");
29     }
30 
31     return result;
32 }
33 
34 ssize_t receive_packet(struct interface_info *ip,
35                        unsigned char *packet_data,
36                        size_t packet_len,
37                        struct sockaddr_in *dest,
38                        struct hardware *hardware ) {
39     int recv_addr_size = sizeof(*dest);
40     int result;
41 
42     if (packet_len > INT_MAX)
43         return WSAEMSGSIZE;
44 
45     result =
46         recvfrom (ip -> rfdesc, (char *)packet_data, (int)packet_len, 0,
47                   (struct sockaddr *)dest, &recv_addr_size );
48     return result;
49 }
50