comparison fake-rfc2553.c @ 589:9fd27bc37807

- Update fake-rfc2553.{c,h} from OpenSSH 5.5p1
author Matt Johnston <matt@ucc.asn.au>
date Wed, 21 Jul 2010 13:53:23 +0000
parents 86725004a0ea
children
comparison
equal deleted inserted replaced
587:1151059c5eff 589:9fd27bc37807
1 /* Taken for Dropbear from OpenSSH 5.5p1 */
2
1 /* 3 /*
2 *
3 * Taken from OpenSSH 3.8.1p1
4 *
5 * Copyright (C) 2000-2003 Damien Miller. All rights reserved. 4 * Copyright (C) 2000-2003 Damien Miller. All rights reserved.
6 * Copyright (C) 1999 WIDE Project. All rights reserved. 5 * Copyright (C) 1999 WIDE Project. All rights reserved.
7 * 6 *
8 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
38 * that ai_family is AF_INET. Don't use it for another purpose. 37 * that ai_family is AF_INET. Don't use it for another purpose.
39 */ 38 */
40 39
41 #include "includes.h" 40 #include "includes.h"
42 41
43 /* RCSID("$.Id: fake-rfc2553.c,v 1.5 2003/09/22 02:08:23 dtucker Exp $");*/ 42 #include <stdlib.h>
43 #include <string.h>
44
45 #include <netinet/in.h>
46 #include <arpa/inet.h>
44 47
45 #ifndef HAVE_GETNAMEINFO 48 #ifndef HAVE_GETNAMEINFO
46 int getnameinfo(const struct sockaddr *sa, size_t salen, char *host, 49 int getnameinfo(const struct sockaddr *sa, size_t salen, char *host,
47 size_t hostlen, char *serv, size_t servlen, int flags) 50 size_t hostlen, char *serv, size_t servlen, int flags)
48 { 51 {
49 struct sockaddr_in *sin = (struct sockaddr_in *)sa; 52 struct sockaddr_in *sin = (struct sockaddr_in *)sa;
50 struct hostent *hp; 53 struct hostent *hp;
51 char tmpserv[16]; 54 char tmpserv[16];
52 55
56 if (sa->sa_family != AF_UNSPEC && sa->sa_family != AF_INET)
57 return (EAI_FAMILY);
53 if (serv != NULL) { 58 if (serv != NULL) {
54 snprintf(tmpserv, sizeof(tmpserv), "%d", ntohs(sin->sin_port)); 59 snprintf(tmpserv, sizeof(tmpserv), "%d", ntohs(sin->sin_port));
55 if (strlcpy(serv, tmpserv, servlen) >= servlen) 60 if (strlcpy(serv, tmpserv, servlen) >= servlen)
56 return (EAI_MEMORY); 61 return (EAI_MEMORY);
57 } 62 }
92 return ("no address associated with name"); 97 return ("no address associated with name");
93 case EAI_MEMORY: 98 case EAI_MEMORY:
94 return ("memory allocation failure."); 99 return ("memory allocation failure.");
95 case EAI_NONAME: 100 case EAI_NONAME:
96 return ("nodename nor servname provided, or not known"); 101 return ("nodename nor servname provided, or not known");
102 case EAI_FAMILY:
103 return ("ai_family not supported");
97 default: 104 default:
98 return ("unknown/invalid error."); 105 return ("unknown/invalid error.");
99 } 106 }
100 } 107 }
101 #endif /* !HAVE_GAI_STRERROR */ 108 #endif /* !HAVE_GAI_STRERROR */
156 int i; 163 int i;
157 long int port; 164 long int port;
158 u_long addr; 165 u_long addr;
159 166
160 port = 0; 167 port = 0;
168 if (hints && hints->ai_family != AF_UNSPEC &&
169 hints->ai_family != AF_INET)
170 return (EAI_FAMILY);
161 if (servname != NULL) { 171 if (servname != NULL) {
162 char *cp; 172 char *cp;
163 173
164 port = strtol(servname, &cp, 10); 174 port = strtol(servname, &cp, 10);
165 if (port > 0 && port <= 65535 && *cp == '\0') 175 if (port > 0 && port <= 65535 && *cp == '\0')