ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

util.c
Go to the documentation of this file.
00001 #include "rosdhcp.h"
00002 
00003 #define NDEBUG
00004 #include <reactos/debug.h>
00005 
00006 char *piaddr( struct iaddr addr ) {
00007     struct sockaddr_in sa;
00008     memcpy(&sa.sin_addr,addr.iabuf,sizeof(sa.sin_addr));
00009     return inet_ntoa( sa.sin_addr );
00010 }
00011 
00012 int note( char *format, ... ) {
00013     char buf[0x100];
00014     int ret;
00015     va_list arg_begin;
00016     va_start( arg_begin, format );
00017 
00018     ret = _vsnprintf( buf, sizeof(buf), format, arg_begin );
00019 
00020     DPRINT("NOTE: %s\n", buf);
00021 
00022     return ret;
00023 }
00024 
00025 int debug( char *format, ... ) {
00026     char buf[0x100];
00027     int ret;
00028     va_list arg_begin;
00029     va_start( arg_begin, format );
00030 
00031     ret = _vsnprintf( buf, sizeof(buf), format, arg_begin );
00032 
00033     DPRINT("DEBUG: %s\n", buf);
00034 
00035     return ret;
00036 }
00037 
00038 int warn( char *format, ... ) {
00039     char buf[0x100];
00040     int ret;
00041     va_list arg_begin;
00042     va_start( arg_begin, format );
00043 
00044     ret = _vsnprintf( buf, sizeof(buf), format, arg_begin );
00045 
00046     DPRINT("WARN: %s\n", buf);
00047 
00048     return ret;
00049 }
00050 
00051 int warning( char *format, ... ) {
00052     char buf[0x100];
00053     int ret;
00054     va_list arg_begin;
00055     va_start( arg_begin, format );
00056 
00057     ret = _vsnprintf( buf, sizeof(buf), format, arg_begin );
00058 
00059     DPRINT("WARNING: %s\n", buf);
00060 
00061     return ret;
00062 }
00063 
00064 void error( char *format, ... ) {
00065     char buf[0x100];
00066     va_list arg_begin;
00067     va_start( arg_begin, format );
00068 
00069     _vsnprintf( buf, sizeof(buf), format, arg_begin );
00070 
00071     DPRINT1("ERROR: %s\n", buf);
00072 }
00073 
00074 int16_t getShort( unsigned char *data ) {
00075     return (int16_t) ntohs(*(int16_t*) data);
00076 }
00077 
00078 u_int16_t getUShort( unsigned char *data ) {
00079     return (u_int16_t) ntohs(*(u_int16_t*) data);
00080 }
00081 
00082 int32_t getLong( unsigned char *data ) {
00083        return (int32_t) ntohl(*(u_int32_t*) data);
00084 }
00085 
00086 u_int32_t getULong( unsigned char *data ) {
00087        return ntohl(*(u_int32_t*)data);
00088 }
00089 
00090 int addr_eq( struct iaddr a, struct iaddr b ) {
00091     return a.len == b.len && !memcmp( a.iabuf, b.iabuf, a.len );
00092 }
00093 
00094 void *dmalloc( int size, char *name ) { return malloc( size ); }
00095 
00096 int read_client_conf(struct interface_info *ifi) {
00097        /* What a strange dance */
00098        struct client_config *config;
00099        char ComputerName [MAX_COMPUTERNAME_LENGTH + 1];
00100        LPSTR lpCompName;
00101        DWORD ComputerNameSize = sizeof ComputerName / sizeof ComputerName[0];
00102 
00103        if ((ifi!= NULL) && (ifi->client->config != NULL))
00104           config = ifi->client->config;
00105        else
00106        {
00107            warn("util.c read_client_conf poorly implemented!");
00108            return 0;
00109        }
00110 
00111 
00112        GetComputerName(ComputerName, & ComputerNameSize);
00113        debug("Hostname: %s, length: %lu",
00114                ComputerName, ComputerNameSize);
00115        /* This never gets freed since it's only called once */
00116        lpCompName =
00117        HeapAlloc(GetProcessHeap(), 0, ComputerNameSize + 1);
00118        if (lpCompName !=NULL) {
00119            memcpy(lpCompName, ComputerName, ComputerNameSize + 1);
00120            /* Send our hostname, some dhcpds use this to update DNS */
00121            config->send_options[DHO_HOST_NAME].data = (u_int8_t*)lpCompName;
00122            config->send_options[DHO_HOST_NAME].len = ComputerNameSize;
00123            debug("Hostname: %s, length: %d",
00124                  config->send_options[DHO_HOST_NAME].data,
00125                  config->send_options[DHO_HOST_NAME].len);
00126        } else {
00127            error("Failed to allocate heap for hostname");
00128        }
00129        /* Both Linux and Windows send this */
00130        config->send_options[DHO_DHCP_CLIENT_IDENTIFIER].data =
00131              ifi->hw_address.haddr;
00132        config->send_options[DHO_DHCP_CLIENT_IDENTIFIER].len =
00133              ifi->hw_address.hlen;
00134 
00135        /* Setup the requested option list */
00136        config->requested_options
00137            [config->requested_option_count++] = DHO_SUBNET_MASK;
00138        config->requested_options
00139            [config->requested_option_count++] = DHO_BROADCAST_ADDRESS;
00140        config->requested_options
00141            [config->requested_option_count++] = DHO_TIME_OFFSET;
00142        config->requested_options
00143            [config->requested_option_count++] = DHO_ROUTERS;
00144        config->requested_options
00145            [config->requested_option_count++] = DHO_DOMAIN_NAME;
00146        config->requested_options
00147            [config->requested_option_count++] = DHO_DOMAIN_NAME_SERVERS;
00148        config->requested_options
00149            [config->requested_option_count++] = DHO_HOST_NAME;
00150        config->requested_options
00151            [config->requested_option_count++] = DHO_NTP_SERVERS;
00152 
00153        warn("util.c read_client_conf poorly implemented!");
00154     return 0;
00155 }
00156 
00157 struct iaddr broadcast_addr( struct iaddr addr, struct iaddr mask ) {
00158     struct iaddr bcast = { 0 };
00159     return bcast;
00160 }
00161 
00162 struct iaddr subnet_number( struct iaddr addr, struct iaddr mask ) {
00163     struct iaddr bcast = { 0 };
00164     return bcast;
00165 }

Generated on Thu May 24 2012 04:22:26 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.