ReactOS 0.4.16-dev-125-g798ea90
main.c
Go to the documentation of this file.
1#include <headers.h>
2#include <datatypes.h>
3#include <options.h>
4#include <display.h>
5#include <leases.h>
6#include <parser.h>
7
8#define MYPORT 67
10/*DHCPLIST *leased_list;*/
11
12int main( int argc, char *argv[] )
13{
14#ifdef __MINGW32__
15 WSADATA wsaData;
16 int nCode;
17#endif
18 int sockfd;
19 struct sockaddr_in my_addr;
20 struct sockaddr_in their_addr;
21 int addr_len, numbytes;
22 DHCPMESSAGE dhcpm;
23 DHCPOPTIONS dhcpo;
24
25#ifdef __MINGW32__
26 if ((nCode = WSAStartup(MAKEWORD(1, 1), &wsaData)) != 0)
27 {
28 perror("WSAStartup");
29 return 0;
30 }
31#endif
32
33 if ((sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
34 perror("socket");
35 exit(1);
36 }
37
39
40 my_addr.sin_family = AF_INET;
41 my_addr.sin_port = htons(MYPORT);
42 my_addr.sin_addr.s_addr = INADDR_ANY;
43 memset(&(my_addr.sin_zero), '\0', 8);
44
45 if (bind(sockfd, (struct sockaddr *)&my_addr,
46 sizeof(struct sockaddr)) == -1) {
47 perror("bind");
48 exit(1);
49 }
50
51 addr_len = sizeof(struct sockaddr);
52 while((numbytes=recvfrom(sockfd,&dhcpm, sizeof( DHCPMESSAGE ), 0,
53 (struct sockaddr *)&their_addr, &addr_len)) != -1) {
54 /* Parse DHCP */
55 display_dhcp_packet( &dhcpm, &dhcpo );
56 if( parse_dhcp_options( &dhcpm, &dhcpo ) < 0 )
57 continue;
58 if( display_dhcp_packet( &dhcpm, &dhcpo ) < 0 )
59 continue;
60 if( process_dhcp_packet( &dhcpm, &dhcpo ) < 0 )
61 continue;
62 }
63
64 close(sockfd);
65
66#ifdef __MINGW32__
67 WSACleanup();
68#endif
69
70 return 0;
71
72}
static int argc
Definition: ServiceArgs.c:12
#define close
Definition: acwin.h:98
INT WSAAPI recvfrom(IN SOCKET s, OUT CHAR FAR *buf, IN INT len, IN INT flags, OUT LPSOCKADDR from, IN OUT INT FAR *fromlen)
Definition: recv.c:87
INT WINAPI WSAStartup(IN WORD wVersionRequested, OUT LPWSADATA lpWSAData)
Definition: startup.c:113
int main()
Definition: test.c:6
#define IPPROTO_UDP
Definition: ip.h:197
#define AF_INET
Definition: tcpip.h:117
_CRTIMP void __cdecl perror(_In_opt_z_ const char *_ErrMsg)
#define INADDR_ANY
Definition: inet.h:53
int init_leases_list()
Definition: leases.c:8
#define htons(x)
Definition: module.h:215
int display_dhcp_packet(DHCPMESSAGE *dhcpm, DHCPOPTIONS *dhcpo)
Definition: display.c:6
int parse_dhcp_options(DHCPMESSAGE *, DHCPOPTIONS *)
Definition: parser.c:8
int process_dhcp_packet(DHCPMESSAGE *, DHCPOPTIONS *)
Definition: parser.c:193
#define MYPORT
Definition: main.c:8
DHCPLIST * list
Definition: main.c:9
#define argv
Definition: mplay32.c:18
#define exit(n)
Definition: config.h:202
#define memset(x, y, z)
Definition: compat.h:39
INT WSAAPI bind(IN SOCKET s, IN CONST struct sockaddr *name, IN INT namelen)
Definition: socklife.c:36
SOCKET WSAAPI socket(IN INT af, IN INT type, IN INT protocol)
Definition: socklife.c:143
char sin_zero[8]
Definition: winsock.h:513
struct in_addr sin_addr
Definition: winsock.h:512
short sin_family
Definition: winsock.h:510
u_short sin_port
Definition: winsock.h:511
#define MAKEWORD(a, b)
Definition: typedefs.h:248
int PASCAL FAR WSACleanup(void)
Definition: startup.c:60
#define SOCK_DGRAM
Definition: winsock.h:336