00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "dhcpd.h"
00031
00032 #include <omapip/omapip_p.h>
00033
00034 u_int32_t getULong (buf)
00035 const unsigned char *buf;
00036 {
00037 u_int32_t ibuf;
00038
00039 memcpy (&ibuf, buf, sizeof (u_int32_t));
00040 return ntohl (ibuf);
00041 }
00042
00043 int32_t getLong (buf)
00044 const unsigned char *buf;
00045 {
00046 int32_t ibuf;
00047
00048 memcpy (&ibuf, buf, sizeof (int32_t));
00049 return ntohl (ibuf);
00050 }
00051
00052 u_int32_t getUShort (buf)
00053 const unsigned char *buf;
00054 {
00055 unsigned short ibuf;
00056
00057 memcpy (&ibuf, buf, sizeof (u_int16_t));
00058 return ntohs (ibuf);
00059 }
00060
00061 int32_t getShort (buf)
00062 const unsigned char *buf;
00063 {
00064 short ibuf;
00065
00066 memcpy (&ibuf, buf, sizeof (int16_t));
00067 return ntohs (ibuf);
00068 }
00069
00070 void putULong (obuf, val)
00071 unsigned char *obuf;
00072 u_int32_t val;
00073 {
00074 u_int32_t tmp = htonl (val);
00075 memcpy (obuf, &tmp, sizeof tmp);
00076 }
00077
00078 void putLong (obuf, val)
00079 unsigned char *obuf;
00080 int32_t val;
00081 {
00082 int32_t tmp = htonl (val);
00083 memcpy (obuf, &tmp, sizeof tmp);
00084 }
00085
00086 void putUShort (obuf, val)
00087 unsigned char *obuf;
00088 u_int32_t val;
00089 {
00090 u_int16_t tmp = htons (val);
00091 memcpy (obuf, &tmp, sizeof tmp);
00092 }
00093
00094 void putShort (obuf, val)
00095 unsigned char *obuf;
00096 int32_t val;
00097 {
00098 int16_t tmp = htons (val);
00099 memcpy (obuf, &tmp, sizeof tmp);
00100 }
00101
00102 void putUChar (obuf, val)
00103 unsigned char *obuf;
00104 u_int32_t val;
00105 {
00106 *obuf = val;
00107 }
00108
00109 u_int32_t getUChar (obuf)
00110 const unsigned char *obuf;
00111 {
00112 return obuf [0];
00113 }
00114
00115 int converted_length (buf, base, width)
00116 const unsigned char *buf;
00117 unsigned int base;
00118 unsigned int width;
00119 {
00120 u_int32_t number;
00121 u_int32_t column;
00122 int power = 1;
00123 u_int32_t newcolumn = base;
00124
00125 if (base > 16)
00126 return 0;
00127
00128 if (width == 1)
00129 number = getUChar (buf);
00130 else if (width == 2)
00131 number = getUShort (buf);
00132 else if (width == 4)
00133 number = getULong (buf);
00134 else
00135 return 0;
00136
00137 do {
00138 column = newcolumn;
00139
00140 if (number < column)
00141 return power;
00142 power++;
00143 newcolumn = column * base;
00144
00145 } while (newcolumn > column);
00146
00147 return power;
00148 }
00149
00150 int binary_to_ascii (outbuf, inbuf, base, width)
00151 unsigned char *outbuf;
00152 const unsigned char *inbuf;
00153 unsigned int base;
00154 unsigned int width;
00155 {
00156 u_int32_t number;
00157 static char h2a [] = "0123456789abcdef";
00158 int power = converted_length (inbuf, base, width);
00159 int i;
00160
00161 if (base > 16)
00162 return 0;
00163
00164 if (width == 1)
00165 number = getUChar (inbuf);
00166 else if (width == 2)
00167 number = getUShort (inbuf);
00168 else if (width == 4)
00169 number = getULong (inbuf);
00170 else
00171 return 0;
00172
00173 for (i = power - 1 ; i >= 0; i--) {
00174 outbuf [i] = h2a [number % base];
00175 number /= base;
00176 }
00177
00178 return power;
00179 }