• 大小: 1.49MB
    文件类型: .gz
    金币: 1
    下载: 0 次
    发布日期: 2023-10-11
  • 语言: 其他
  • 标签: openssh-7.9p  

资源简介

不知道哪里下的openssh-7.9p1,大家随便看看吧,不懂openssh-7.9p1,

资源截图

代码片段和文件信息

/*	$OpenBSD: addrmatch.cv 1.14 2018/07/31 03:07:24 djm Exp $ */

/*
 * Copyright (c) 2004-2008 Damien Miller 
 *
 * Permission to use copy modify and distribute this software for any
 * purpose with or without fee is hereby granted provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED “AS IS“ AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL DIRECT INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE DATA OR PROFITS WHETHER IN AN
 * ACTION OF CONTRACT NEGLIGENCE OR OTHER TORTIOUS ACTION ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include “includes.h“

#include 
#include 
#include 
#include 

#include 
#include 
#include 
#include 
#include 

#include “match.h“
#include “log.h“

struct xaddr {
sa_family_t af;
union {
struct in_addr v4;
struct in6_addr v6;
u_int8_t addr8[16];
u_int32_t addr32[4];
} xa;     /* 128-bit address */
u_int32_t scope_id; /* iface scope id for v6 */
#define v4 xa.v4
#define v6 xa.v6
#define addr8 xa.addr8
#define addr32 xa.addr32
};

static int
addr_unicast_masklen(int af)
{
switch (af) {
case AF_INET:
return 32;
case AF_INET6:
return 128;
default:
return -1;
}
}

static inline int
masklen_valid(int af u_int masklen)
{
switch (af) {
case AF_INET:
return masklen <= 32 ? 0 : -1;
case AF_INET6:
return masklen <= 128 ? 0 : -1;
default:
return -1;
}
}

/*
 * Convert struct sockaddr to struct xaddr
 * Returns 0 on success -1 on failure.
 */
static int
addr_sa_to_xaddr(struct sockaddr *sa socklen_t slen struct xaddr *xa)
{
struct sockaddr_in *in4 = (struct sockaddr_in *)sa;
struct sockaddr_in6 *in6 = (struct sockaddr_in6 *)sa;

memset(xa ‘\0‘ sizeof(*xa));

switch (sa->sa_family) {
case AF_INET:
if (slen < (socklen_t)sizeof(*in4))
return -1;
xa->af = AF_INET;
memcpy(&xa->v4 &in4->sin_addr sizeof(xa->v4));
break;
case AF_INET6:
if (slen < (socklen_t)sizeof(*in6))
return -1;
xa->af = AF_INET6;
memcpy(&xa->v6 &in6->sin6_addr sizeof(xa->v6));
#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
xa->scope_id = in6->sin6_scope_id;
#endif
break;
default:
return -1;
}

return 0;
}

/*
 * Calculate a netmask of length ‘l‘ for address family ‘af‘ and
 * store it in ‘n‘.
 * Returns 0 on success -1 on failure.
 */
static int
addr_netmask(int af u_int l struct xaddr *n)
{
int i;

if (masklen_valid(af l) != 0 || n == NULL)
return -1;

memset(n ‘\0‘ sizeof(*n));
switch (af) {
case AF_INET:
n->af = AF_INET;
if (l == 0)
return 0;
n->v4.s_addr = htonl((0xffffffff << (32 - l)) & 0xffffffff);
return 0;
case AF_INET6:
n->af = A

评论

共有 条评论