ReactOS  0.4.15-dev-985-gd905dd5
main.c File Reference
#include <headers.h>
#include <datatypes.h>
#include <options.h>
#include <display.h>
#include <leases.h>
#include <parser.h>
Include dependency graph for main.c:

Go to the source code of this file.

Macros

#define MYPORT   67
 

Functions

int main (int argc, char *argv[])
 

Variables

DHCPLISTlist
 

Macro Definition Documentation

◆ MYPORT

#define MYPORT   67

Definition at line 8 of file main.c.

Function Documentation

◆ main()

int main ( int argc  ,
char argv[] 
)

hosttype.c Copyright (C) 2002 by Brian Palmer brian.nosp@m.p@sg.nosp@m.inet..nosp@m.com

Definition at line 12 of file main.c.

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
SOCKET WSAAPI socket(IN INT af, IN INT type, IN INT protocol)
Definition: socklife.c:143
#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
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
#define close
Definition: acwin.h:98
#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

Variable Documentation

◆ list

Definition at line 9 of file main.c.

Referenced by testQuery().