A version of LWIP, provided for backwards compatibility.

Dependents:   AA_DemoBoard DemoBoard HelloServerDemo DemoBoard_RangeIndicator ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers util.cpp Source File

util.cpp

00001 #include "util.h"
00002 
00003 unsigned int base64enc_len(const char *str) {
00004   return (((strlen(str)-1)/3)+1)<<2;
00005 }
00006 
00007 void base64enc(const char *input, unsigned int length, char *output) {
00008   static const char base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
00009   unsigned int c, c1, c2, c3;
00010   for(unsigned int i = 0, j = 0; i<length; i+=3,j+=4) {
00011     c1 = ((((unsigned char)*((unsigned char *)&input[i]))));
00012     c2 = (length>i+1)?((((unsigned char)*((unsigned char *)&input[i+1])))):0;
00013     c3 = (length>i+2)?((((unsigned char)*((unsigned char *)&input[i+2])))):0;
00014 
00015     c = ((c1 & 0xFC) >> 2);
00016     output[j+0] = base64[c];
00017     c = ((c1 & 0x03) << 4) | ((c2 & 0xF0) >> 4);
00018     output[j+1] = base64[c];
00019     c = ((c2 & 0x0F) << 2) | ((c3 & 0xC0) >> 6);
00020     output[j+2] = (length>i+1)?base64[c]:'=';
00021     c = (c3 & 0x3F);
00022     output[j+3] = (length>i+2)?base64[c]:'=';
00023   }
00024   output[(((length-1)/3)+1)<<2] = '\0';
00025 }
00026 
00027 const char *ethernet_mac_address() {
00028     // Will be replaced with mechanism to return a unique mac
00029     static char mac[6] = {0x00, 0x30, 0x2F, 0x00, 0xEE, 0xAF}; // 01:23:45:67:89:AB
00030     return mac; 
00031 }
00032