aboutsummaryrefslogtreecommitdiff
path: root/openssl/trunk/crypto
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2006-08-17 04:26:25 +0000
committerRob Austein <sra@hactrn.net>2006-08-17 04:26:25 +0000
commitc582a857020b04d6509160fd9738dc7b7075267e (patch)
tree67717b68e432c0443880df26525d65abaf208d63 /openssl/trunk/crypto
parentafb13a243b68a827c4310c6e8aacf40dbf7c1b76 (diff)
Get rid of dependencies on inet_pton() and inet_ntop().
svn path=/openssl/trunk/crypto/x509v3/v3_addr.c; revision=166
Diffstat (limited to 'openssl/trunk/crypto')
-rw-r--r--openssl/trunk/crypto/x509v3/v3_addr.c43
-rw-r--r--openssl/trunk/crypto/x509v3/v3_utl.c3
-rw-r--r--openssl/trunk/crypto/x509v3/x509v3.h1
3 files changed, 16 insertions, 31 deletions
diff --git a/openssl/trunk/crypto/x509v3/v3_addr.c b/openssl/trunk/crypto/x509v3/v3_addr.c
index d5d149fb..de27d9fa 100644
--- a/openssl/trunk/crypto/x509v3/v3_addr.c
+++ b/openssl/trunk/crypto/x509v3/v3_addr.c
@@ -23,13 +23,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
-
-/* All of this just to pull in inet_ntop() and inet_pton(). Ick. */
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
#include "cryptlib.h"
#include <openssl/conf.h>
#include <openssl/asn1.h>
@@ -76,12 +69,6 @@ IMPLEMENT_ASN1_FUNCTIONS(IPAddressFamily)
#define ADDR_RAW_BUF_LEN 16
/*
- * How much buffer space do we need for the text form of an address?
- * Output routines (inet_ntop() or whatever) must check for overflow.
- */
-#define ADDR_TXT_BUF_LEN 48
-
-/*
* What's the address length associated with this AFI?
*/
static int length_from_afi(const unsigned afi)
@@ -144,21 +131,21 @@ static int i2r_address(BIO *out,
const ASN1_BIT_STRING *bs)
{
unsigned char addr[ADDR_RAW_BUF_LEN];
- char buf[ADDR_TXT_BUF_LEN];
- int i;
+ int i, n;
switch (afi) {
case IANA_AFI_IPV4:
addr_expand(addr, bs, 4, fill);
- if (!inet_ntop(AF_INET, addr, buf, sizeof(buf)))
- return 0;
- BIO_puts(out, buf);
+ BIO_printf(out, "%d.%d.%d.%d", addr[0], addr[1], addr[2], addr[3]);
break;
case IANA_AFI_IPV6:
addr_expand(addr, bs, 16, fill);
- if (!inet_ntop(AF_INET6, addr, buf, sizeof(buf)))
- return 0;
- BIO_puts(out, buf);
+ for (n = 16; n > 1 && addr[n-1] == 0x00 && addr[n-2] == 0x00; n -= 2)
+ ;
+ for (i = 0; i < n; i += 2)
+ BIO_printf(out, "%x%s", (addr[i] << 8) | addr[i+1], (i < 14 ? ":" : ""));
+ if (i < 16)
+ BIO_puts(out, ":");
break;
default:
for (i = 0; i < bs->length; i++)
@@ -832,7 +819,7 @@ static void *v2i_IPAddrBlocks(struct v3_ext_method *method,
unsigned char min[ADDR_RAW_BUF_LEN], max[ADDR_RAW_BUF_LEN];
unsigned afi, *safi = NULL, safi_;
const char *addr_chars;
- int prefixlen, af, i1, i2, delim, host_prefixlength;
+ int prefixlen, i1, i2, delim, length;
if ( !name_cmp(val->name, "IPv4")) {
afi = IANA_AFI_IPV4;
@@ -852,17 +839,15 @@ static void *v2i_IPAddrBlocks(struct v3_ext_method *method,
switch (afi) {
case IANA_AFI_IPV4:
- af = AF_INET;
- host_prefixlength = 32;
addr_chars = v4addr_chars;
break;
case IANA_AFI_IPV6:
- af = AF_INET6;
- host_prefixlength = 128;
addr_chars = v6addr_chars;
break;
}
+ length = length_from_afi(afi);
+
/*
* Handle SAFI, if any, and strdup() so we can null-terminate
* the other input values.
@@ -905,7 +890,7 @@ static void *v2i_IPAddrBlocks(struct v3_ext_method *method,
delim = s[i2++];
s[i1] = '\0';
- if (inet_pton(af, s, min) != 1) {
+ if (a2i_ipadd(min, s) != length) {
X509V3err(X509V3_F_V2I_IPADDRBLOCKS, X509V3_R_INVALID_IPADDRESS);
X509V3_conf_err(val);
goto err;
@@ -932,7 +917,7 @@ static void *v2i_IPAddrBlocks(struct v3_ext_method *method,
X509V3_conf_err(val);
goto err;
}
- if (inet_pton(af, s + i1, max) != 1) {
+ if (a2i_ipadd(max, s + i1) != length) {
X509V3err(X509V3_F_V2I_IPADDRBLOCKS, X509V3_R_INVALID_IPADDRESS);
X509V3_conf_err(val);
goto err;
@@ -943,7 +928,7 @@ static void *v2i_IPAddrBlocks(struct v3_ext_method *method,
}
break;
case '\0':
- if (!addr_add_prefix(addr, afi, safi, min, host_prefixlength)) {
+ if (!addr_add_prefix(addr, afi, safi, min, length * 8)) {
X509V3err(X509V3_F_V2I_IPADDRBLOCKS, ERR_R_MALLOC_FAILURE);
goto err;
}
diff --git a/openssl/trunk/crypto/x509v3/v3_utl.c b/openssl/trunk/crypto/x509v3/v3_utl.c
index 7911c4bd..7c1d26fc 100644
--- a/openssl/trunk/crypto/x509v3/v3_utl.c
+++ b/openssl/trunk/crypto/x509v3/v3_utl.c
@@ -71,7 +71,6 @@ static STACK *get_email(X509_NAME *name, GENERAL_NAMES *gens);
static void str_free(void *str);
static int append_ia5(STACK **sk, ASN1_IA5STRING *email);
-static int a2i_ipadd(unsigned char *ipout, const char *ipasc);
static int ipv4_from_asc(unsigned char *v4, const char *in);
static int ipv6_from_asc(unsigned char *v6, const char *in);
static int ipv6_cb(const char *elem, int len, void *usr);
@@ -615,7 +614,7 @@ ASN1_OCTET_STRING *a2i_IPADDRESS_NC(const char *ipasc)
}
-static int a2i_ipadd(unsigned char *ipout, const char *ipasc)
+int a2i_ipadd(unsigned char *ipout, const char *ipasc)
{
/* If string contains a ':' assume IPv6 */
diff --git a/openssl/trunk/crypto/x509v3/x509v3.h b/openssl/trunk/crypto/x509v3/x509v3.h
index 44faf17f..2e2e2e21 100644
--- a/openssl/trunk/crypto/x509v3/x509v3.h
+++ b/openssl/trunk/crypto/x509v3/x509v3.h
@@ -620,6 +620,7 @@ void X509_email_free(STACK *sk);
ASN1_OCTET_STRING *a2i_IPADDRESS(const char *ipasc);
ASN1_OCTET_STRING *a2i_IPADDRESS_NC(const char *ipasc);
+int a2i_ipadd(unsigned char *ipout, const char *ipasc);
int X509V3_NAME_from_section(X509_NAME *nm, STACK_OF(CONF_VALUE)*dn_sk,
unsigned long chtype);