Deleted Added
sdiff udiff text old ( 176012 ) new ( 176033 )
full compact
1/*-
2 * Copyright (c) 2005 Daniel Braniss <danny@cs.huji.ac.il>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 16 unchanged lines hidden (view full) ---

25 *
26 */
27
28/*
29 | $Id: misc.c,v 2.1 2006/11/12 08:06:51 danny Exp $
30 */
31
32#include <sys/cdefs.h>
33__FBSDID("$FreeBSD: head/sbin/iscontrol/misc.c 176033 2008-02-06 08:02:55Z pb $");
34
35#include <sys/param.h>
36#include <sys/types.h>
37#include <sys/socket.h>
38#include <sys/sysctl.h>
39
40#include <netinet/in.h>
41#include <netinet/tcp.h>

--- 111 unchanged lines hidden (view full) ---

153 *rsp = tmp;
154 return len;
155}
156
157char *
158bin2str(char *encoding, unsigned char *md, int blen)
159{
160 int len;
161 char *dst, *ds;
162 unsigned char *cp;
163
164 if(strncasecmp(encoding, "0x", 2) == 0) {
165 char ofmt[5];
166
167 len = blen * 2;
168 dst = malloc(len + 3);
169 strcpy(dst, encoding);
170 ds = dst + 2;
171 cp = md;
172 sprintf(ofmt, "%%02%c", encoding[1]);
173 while(blen-- > 0) {
174 sprintf(ds, ofmt, *cp++);
175 ds += 2;
176 }
177 *ds = 0;
178 return dst;
179 }
180 if(strncasecmp(encoding, "0b", 2) == 0) {
181 int i, b6;
182
183 len = (blen + 2) * 4 / 3;
184 dst = malloc(len + 3);
185 strcpy(dst, encoding);
186 ds = dst + 2;
187 cp = md;
188 b6 = 0; // to keep copiler happy.
189 for(i = 0; i < blen; i++) {
190 switch(i % 3) {
191 case 0:
192 *ds++ = base64[*cp >> 2];
193 b6 = (*cp & 0x3) << 4;
194 break;
195 case 1:

--- 31 unchanged lines hidden ---