当前位置: 首页>>代码示例>>C++>>正文


C++ DifferentialChecksum函数代码示例

本文整理汇总了C++中DifferentialChecksum函数的典型用法代码示例。如果您正苦于以下问题:C++ DifferentialChecksum函数的具体用法?C++ DifferentialChecksum怎么用?C++ DifferentialChecksum使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了DifferentialChecksum函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: AliasHandlePptpGreOut

int
AliasHandlePptpGreOut(struct ip *pip)
{
    GreHdr		*gr;
    struct alias_link	*link;

    gr = (GreHdr *)((char *)pip + (pip->ip_hl << 2));

    /* Check GRE header bits. */
    if ((ntohl(*((u_int32_t *)gr)) & PPTP_INIT_MASK) != PPTP_INIT_VALUE)
	return (-1);

    link = FindPptpOutByPeerCallId(pip->ip_src, pip->ip_dst, gr->gh_call_id);
    if (link != NULL) {
	struct in_addr alias_addr = GetAliasAddress(link);

	/* Change source IP address. */
	DifferentialChecksum(&pip->ip_sum,
			     (u_short *)&alias_addr,
			     (u_short *)&pip->ip_src,
			     2);
	pip->ip_src = alias_addr;
    }

    return (0);
}
开发者ID:Leon555,项目名称:Mac-src-essentials,代码行数:26,代码来源:alias_pptp.c

示例2: ProtoAliasOut

static int
ProtoAliasOut(struct libalias *la, struct in_addr *ip_src, 
    struct in_addr ip_dst, u_char ip_p, u_short *ip_sum, int create)
{
/*
  Handle outgoing IP packets. The
  only thing which is done in this case is to alias
  the source IP address of the packet.
*/
	struct alias_link *lnk;

	LIBALIAS_LOCK_ASSERT(la);
	(void)create;

/* Return if proxy-only mode is enabled */
	if (la->packetAliasMode & PKT_ALIAS_PROXY_ONLY)
		return (PKT_ALIAS_OK);

	lnk = FindProtoOut(la, *ip_src, ip_dst, ip_p);
	if (lnk != NULL) {
		struct in_addr alias_address;

		alias_address = GetAliasAddress(lnk);

/* Change source address */
		DifferentialChecksum(ip_sum,
		    &alias_address, ip_src, 2);
		*ip_src = alias_address;

		return (PKT_ALIAS_OK);
	}
	return (PKT_ALIAS_IGNORED);
}
开发者ID:ChaosJohn,项目名称:freebsd,代码行数:33,代码来源:alias.c

示例3: ProtoAliasIn

static int
ProtoAliasIn(struct libalias *la, struct in_addr ip_src, 
    struct in_addr *ip_dst, u_char ip_p, u_short *ip_sum)
{
/*
  Handle incoming IP packets. The
  only thing which is done in this case is to alias
  the dest IP address of the packet to our inside
  machine.
*/
	struct alias_link *lnk;

	LIBALIAS_LOCK_ASSERT(la);
/* Return if proxy-only mode is enabled */
	if (la->packetAliasMode & PKT_ALIAS_PROXY_ONLY)
		return (PKT_ALIAS_OK);

	lnk = FindProtoIn(la, ip_src, *ip_dst, ip_p);
	if (lnk != NULL) {
		struct in_addr original_address;

		original_address = GetOriginalAddress(lnk);

/* Restore original IP address */
		DifferentialChecksum(ip_sum,
		    &original_address, ip_dst, 2);
		*ip_dst = original_address;

		return (PKT_ALIAS_OK);
	}
	return (PKT_ALIAS_IGNORED);
}
开发者ID:ChaosJohn,项目名称:freebsd,代码行数:32,代码来源:alias.c

示例4: ProtoAliasIn

static int
ProtoAliasIn(struct ip *pip)
{
/*
  Handle incoming IP packets. The
  only thing which is done in this case is to alias
  the dest IP address of the packet to our inside
  machine.
*/
    struct alias_link *link;

/* Return if proxy-only mode is enabled */
    if (packetAliasMode & PKT_ALIAS_PROXY_ONLY)
        return PKT_ALIAS_OK;

    link = FindProtoIn(pip->ip_src, pip->ip_dst, pip->ip_p);
    if (link != NULL)
    {
        struct in_addr original_address;

        original_address = GetOriginalAddress(link);

/* Restore original IP address */
        DifferentialChecksum(&pip->ip_sum,
                             (u_short *) &original_address,
                             (u_short *) &pip->ip_dst,
                             2);
        pip->ip_dst = original_address;

	return(PKT_ALIAS_OK);
    }
    return(PKT_ALIAS_IGNORED);
}
开发者ID:juanfra684,项目名称:DragonFlyBSD,代码行数:33,代码来源:alias.c

示例5: ProtoAliasOut

static int
ProtoAliasOut(struct ip *pip)
{
/*
  Handle outgoing IP packets. The
  only thing which is done in this case is to alias
  the source IP address of the packet.
*/
    struct alias_link *link;

/* Return if proxy-only mode is enabled */
    if (packetAliasMode & PKT_ALIAS_PROXY_ONLY)
        return PKT_ALIAS_OK;

    link = FindProtoOut(pip->ip_src, pip->ip_dst, pip->ip_p);
    if (link != NULL)
    {
        struct in_addr alias_address;

        alias_address = GetAliasAddress(link);

/* Change source address */
        DifferentialChecksum(&pip->ip_sum,
                             (u_short *) &alias_address,
                             (u_short *) &pip->ip_src,
                             2);
        pip->ip_src = alias_address;

        return(PKT_ALIAS_OK);
    }
    return(PKT_ALIAS_IGNORED);
}
开发者ID:juanfra684,项目名称:DragonFlyBSD,代码行数:32,代码来源:alias.c

示例6: UdpAliasOut

static int
UdpAliasOut(struct libalias *la, struct ip *pip, int create)
{
    struct udphdr *ud;
    struct alias_link *lnk;
    int error;

    LIBALIAS_LOCK_ASSERT(la);
/* Return if proxy-only mode is enabled */
    if (la->packetAliasMode & PKT_ALIAS_PROXY_ONLY)
        return (PKT_ALIAS_OK);

    ud = (struct udphdr *)ip_next(pip);

    lnk = FindUdpTcpOut(la, pip->ip_src, pip->ip_dst,
        ud->uh_sport, ud->uh_dport,
        IPPROTO_UDP, create);
    if (lnk != NULL) {
        u_short alias_port;
        struct in_addr alias_address;
        struct alias_data ad;
        ad.lnk = lnk;
        ad.oaddr = NULL;
        ad.aaddr = &alias_address;
        ad.aport = &alias_port;
        ad.sport = &ud->uh_sport;
        ad.dport = &ud->uh_dport;
        ad.maxpktsize = 0;

        alias_address = GetAliasAddress(lnk);
        alias_port = GetAliasPort(lnk);

        /* Walk out chain. */
        error = find_handler(OUT, UDP, la, pip, &ad);

/* If UDP checksum is not zero, adjust since source port is */
/* being aliased and source address is being altered        */
        if (ud->uh_sum != 0) {
            int accumulate;

            accumulate = ud->uh_sport;
            accumulate -= alias_port;
            accumulate += twowords(&pip->ip_src);
            accumulate -= twowords(&alias_address);
            ADJUST_CHECKSUM(accumulate, ud->uh_sum);
        }
/* Put alias port in UDP header */
        ud->uh_sport = alias_port;

/* Change source address */
        DifferentialChecksum(&pip->ip_sum,
            &alias_address, &pip->ip_src, 2);
        pip->ip_src = alias_address;

        return (PKT_ALIAS_OK);
    }
    return (PKT_ALIAS_IGNORED);
}
开发者ID:MadHacker217,项目名称:VirtualBox-OSE,代码行数:58,代码来源:alias.c

示例7: FragmentOut

static int
FragmentOut(struct libalias *la, struct ip *pip)
{
    struct in_addr alias_address;

    LIBALIAS_LOCK_ASSERT(la);
    alias_address = FindAliasAddress(la, pip->ip_src);
    DifferentialChecksum(&pip->ip_sum,
        &alias_address, &pip->ip_src, 2);
    pip->ip_src = alias_address;

    return (PKT_ALIAS_OK);
}
开发者ID:MadHacker217,项目名称:VirtualBox-OSE,代码行数:13,代码来源:alias.c

示例8: FragmentOut

static int
FragmentOut(struct ip *pip)
{
    struct in_addr alias_address;

    alias_address = FindAliasAddress(pip->ip_src);
    DifferentialChecksum(&pip->ip_sum,
                         (u_short *) &alias_address,
                         (u_short *) &pip->ip_src,
                          2);
    pip->ip_src = alias_address;

    return(PKT_ALIAS_OK);
}
开发者ID:juanfra684,项目名称:DragonFlyBSD,代码行数:14,代码来源:alias.c

示例9: IcmpAliasOut1

static int
IcmpAliasOut1(struct ip *pip)
{
/*
    Alias outgoing echo and timestamp requests.
    De-alias outgoing echo and timestamp replies.
*/
    struct alias_link *link;
    struct icmp *ic;

    ic = (struct icmp *) ((char *) pip + (pip->ip_hl << 2));

/* Save overwritten data for when echo packet returns */
    link = FindIcmpOut(pip->ip_src, pip->ip_dst, ic->icmp_id, 1);
    if (link != NULL)
    {
        u_short alias_id;
        int accumulate;

        alias_id = GetAliasPort(link);

/* Since data field is being modified, adjust ICMP checksum */
        accumulate  = ic->icmp_id;
        accumulate -= alias_id;
        ADJUST_CHECKSUM(accumulate, ic->icmp_cksum);

/* Alias sequence number */
        ic->icmp_id = alias_id;

/* Change source address */
        {
            struct in_addr alias_address;

            alias_address = GetAliasAddress(link);
            DifferentialChecksum(&pip->ip_sum,
                                 (u_short *) &alias_address,
                                 (u_short *) &pip->ip_src,
                                 2);
            pip->ip_src = alias_address;
        }

        return(PKT_ALIAS_OK);
    }
    return(PKT_ALIAS_IGNORED);
}
开发者ID:juanfra684,项目名称:DragonFlyBSD,代码行数:45,代码来源:alias.c

示例10: IcmpAliasIn1

static int
IcmpAliasIn1(struct libalias *la, struct ip *pip)
{

/*
    De-alias incoming echo and timestamp replies.
    Alias incoming echo and timestamp requests.
*/
    struct alias_link *lnk;
    struct icmp *ic;

    LIBALIAS_LOCK_ASSERT(la);

    ic = (struct icmp *)ip_next(pip);

/* Get source address from ICMP data field and restore original data */
    lnk = FindIcmpIn(la, pip->ip_src, pip->ip_dst, ic->icmp_id, 1);
    if (lnk != NULL) {
        u_short original_id;
        int accumulate;

        original_id = GetOriginalPort(lnk);

/* Adjust ICMP checksum */
        accumulate = ic->icmp_id;
        accumulate -= original_id;
        ADJUST_CHECKSUM(accumulate, ic->icmp_cksum);

/* Put original sequence number back in */
        ic->icmp_id = original_id;

/* Put original address back into IP header */
        {
            struct in_addr original_address;

            original_address = GetOriginalAddress(lnk);
            DifferentialChecksum(&pip->ip_sum,
                &original_address, &pip->ip_dst, 2);
            pip->ip_dst = original_address;
        }

        return (PKT_ALIAS_OK);
    }
    return (PKT_ALIAS_IGNORED);
}
开发者ID:MadHacker217,项目名称:VirtualBox-OSE,代码行数:45,代码来源:alias.c

示例11: FragmentIn

static int
FragmentIn(struct libalias *la, struct ip *pip)
{
    struct alias_link *lnk;

    LIBALIAS_LOCK_ASSERT(la);
    lnk = FindFragmentIn2(la, pip->ip_src, pip->ip_dst, pip->ip_id);
    if (lnk != NULL) {
        struct in_addr original_address;

        GetFragmentAddr(lnk, &original_address);
        DifferentialChecksum(&pip->ip_sum,
            &original_address, &pip->ip_dst, 2);
        pip->ip_dst = original_address;

        return (PKT_ALIAS_OK);
    }
    return (PKT_ALIAS_UNRESOLVED_FRAGMENT);
}
开发者ID:MadHacker217,项目名称:VirtualBox-OSE,代码行数:19,代码来源:alias.c

示例12: PacketAliasFragmentIn

void
PacketAliasFragmentIn(char *ptr,          /* Points to correctly de-aliased
                                             header fragment */
                      char *ptr_fragment  /* Points to fragment which must
                                             be de-aliased   */
                     )
{
    struct ip *pip;
    struct ip *fpip;

    pip = (struct ip *) ptr;
    fpip = (struct ip *) ptr_fragment;

    DifferentialChecksum(&fpip->ip_sum,
                         (u_short *) &pip->ip_dst,
                         (u_short *) &fpip->ip_dst,
                         2);
    fpip->ip_dst = pip->ip_dst;
}
开发者ID:juanfra684,项目名称:DragonFlyBSD,代码行数:19,代码来源:alias.c

示例13: LibAliasFragmentIn

void
LibAliasFragmentIn(struct libalias *la, char *ptr,  /* Points to correctly
                             * de-aliased header
                             * fragment */
    char *ptr_fragment      /* Points to fragment which must be
                 * de-aliased   */
)
{
    struct ip *pip;
    struct ip *fpip;

    LIBALIAS_LOCK(la);
    (void)la;
    pip = (struct ip *)ptr;
    fpip = (struct ip *)ptr_fragment;

    DifferentialChecksum(&fpip->ip_sum,
        &pip->ip_dst, &fpip->ip_dst, 2);
    fpip->ip_dst = pip->ip_dst;
    LIBALIAS_UNLOCK(la);
}
开发者ID:MadHacker217,项目名称:VirtualBox-OSE,代码行数:21,代码来源:alias.c

示例14: FragmentIn

static int
FragmentIn(struct ip *pip)
{
    struct alias_link *link;

    link = FindFragmentIn2(pip->ip_src, pip->ip_dst, pip->ip_id);
    if (link != NULL)
    {
        struct in_addr original_address;

        GetFragmentAddr(link, &original_address);
        DifferentialChecksum(&pip->ip_sum,
                             (u_short *) &original_address,
                             (u_short *) &pip->ip_dst,
                             2);
        pip->ip_dst = original_address; 
   
        return(PKT_ALIAS_OK);
    }
    return(PKT_ALIAS_UNRESOLVED_FRAGMENT);
}
开发者ID:juanfra684,项目名称:DragonFlyBSD,代码行数:21,代码来源:alias.c

示例15: alias_rtsp_out


//.........这里部分代码省略.........
#ifdef LIBALIAS_DEBUG
                        fprintf(stderr,
                                "PacketAlias/RTSP: Cannot find contiguous RTSP data ports\n");
#endif
                    } else {

                        base_alias = ntohs(salias);
                        for (j = 0; j < RTSP_PORT_GROUP; j++) {
                            /*
                             * Establish link
                             * to port found in
                             * RTSP packet
                             */
                            rtsp_lnk = FindRtspOut(la, GetOriginalAddress(lnk), null_addr,
                                                   htons(base_port + j), htons(base_alias + j),
                                                   IPPROTO_UDP);
                            if (rtsp_lnk != NULL) {
#ifndef NO_FW_PUNCH
                                /*
                                 * Punch
                                 * hole in
                                 * firewall
                                 */
                                PunchFWHole(rtsp_lnk);
#endif
                            } else {
#ifdef LIBALIAS_DEBUG
                                fprintf(stderr,
                                        "PacketAlias/RTSP: Cannot allocate RTSP data ports\n");
#endif
                                break;
                            }
                        }
                    }
                    ealias = htons(base_alias + (RTSP_PORT_GROUP - 1));
                }
                if (salias && rtsp_lnk) {

                    pkt_updated = 1;

                    /* Copy into IP packet */
                    sprintf(stemp, "%d", ntohs(salias));
                    memcpy(port_newdata, stemp, strlen(stemp));
                    port_newdata += strlen(stemp);

                    if (eport != 0) {
                        *port_newdata = '-';
                        port_newdata++;

                        /* Copy into IP packet */
                        sprintf(stemp, "%d", ntohs(ealias));
                        memcpy(port_newdata, stemp, strlen(stemp));
                        port_newdata += strlen(stemp);
                    }
                    *port_newdata = ';';
                    port_newdata++;
                }
                state++;
                break;
            }
            if (state > 3) {
                break;
            }
        }
        port_data += i;
        port_dlen -= i;
    }

    if (!pkt_updated)
        return (-1);

    memcpy(port_newdata, port_data, port_dlen);
    port_newdata += port_dlen;
    *port_newdata = '\0';

    /* Create new packet */
    new_dlen = port_newdata - newdata;
    memcpy(data, newdata, new_dlen);

    SetAckModified(lnk);
    tc = (struct tcphdr *)ip_next(pip);
    delta = GetDeltaSeqOut(tc->th_seq, lnk);
    AddSeq(lnk, delta + new_dlen - dlen, pip->ip_hl, pip->ip_len,
           tc->th_seq, tc->th_off);

    new_len = htons(hlen + new_dlen);
    DifferentialChecksum(&pip->ip_sum,
                         &new_len,
                         &pip->ip_len,
                         1);
    pip->ip_len = new_len;

    tc->th_sum = 0;
#ifdef _KERNEL
    tc->th_x2 = 1;
#else
    tc->th_sum = TcpChecksum(pip);
#endif
    return (0);
}
开发者ID:hmatyschok,项目名称:MeshBSD,代码行数:101,代码来源:alias_smedia.c


注:本文中的DifferentialChecksum函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。