ReactOS  0.4.15-dev-1150-g593bcce
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 
12 int 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 }
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
static int argc
Definition: ServiceArgs.c:12
SOCKET WSAAPI socket(IN INT af, IN INT type, IN INT protocol)
Definition: socklife.c:143
u_short sin_port
Definition: winsock.h:511
#define MAKEWORD(a, b)
Definition: typedefs.h:248
INT WSAAPI bind(IN SOCKET s, IN CONST struct sockaddr *name, IN INT namelen)
Definition: socklife.c:36
INT WSAAPI WSACleanup(VOID)
Definition: startup.c:60
#define INADDR_ANY
Definition: StrAddr.c:4
#define argv
Definition: mplay32.c:18
int init_leases_list()
Definition: leases.c:8
int display_dhcp_packet(DHCPMESSAGE *dhcpm, DHCPOPTIONS *dhcpo)
Definition: display.c:6
_CRTIMP void __cdecl perror(_In_opt_z_ const char *_ErrMsg)
INT WINAPI WSAStartup(IN WORD wVersionRequested, OUT LPWSADATA lpWSAData)
Definition: startup.c:113
int process_dhcp_packet(DHCPMESSAGE *, DHCPOPTIONS *)
Definition: parser.c:193
#define MYPORT
Definition: main.c:8
int parse_dhcp_options(DHCPMESSAGE *, DHCPOPTIONS *)
Definition: parser.c:8
int main(int argc, const char *argv[])
Definition: main.c:122
char sin_zero[8]
Definition: winsock.h:513
#define close
Definition: acwin.h:98
struct in_addr sin_addr
Definition: winsock.h:512
#define AF_INET
Definition: tcpip.h:117
void exit(int exitcode)
Definition: _exit.c:33
#define htons(x)
Definition: module.h:213
#define SOCK_DGRAM
Definition: winsock.h:336
#define memset(x, y, z)
Definition: compat.h:39
short sin_family
Definition: winsock.h:510
DHCPLIST * list
Definition: main.c:9