Deleted Added
full compact
misc.c (176012) misc.c (176033)
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>
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 176012 2008-02-05 23:42:38Z pb $");
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;
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 unsigned char *dst, *ds, *cp;
161 char *dst, *ds;
162 unsigned char *cp;
162
163 if(strncasecmp(encoding, "0x", 2) == 0) {
164 char ofmt[5];
165
166 len = blen * 2;
167 dst = malloc(len + 3);
168 strcpy(dst, encoding);
169 ds = dst + 2;
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;
170 cp = (char *)md;
171 cp = md;
171 sprintf(ofmt, "%%02%c", encoding[1]);
172 while(blen-- > 0) {
173 sprintf(ds, ofmt, *cp++);
174 ds += 2;
175 }
176 *ds = 0;
177 return dst;
178 }
179 if(strncasecmp(encoding, "0b", 2) == 0) {
180 int i, b6;
181
182 len = (blen + 2) * 4 / 3;
183 dst = malloc(len + 3);
184 strcpy(dst, encoding);
185 ds = dst + 2;
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;
186 cp = (char *)md;
187 cp = md;
187 b6 = 0; // to keep copiler happy.
188 for(i = 0; i < blen; i++) {
189 switch(i % 3) {
190 case 0:
191 *ds++ = base64[*cp >> 2];
192 b6 = (*cp & 0x3) << 4;
193 break;
194 case 1:

--- 31 unchanged lines hidden ---
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 ---