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


C++ satosin函数代码示例

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


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

示例1: rtpp_stream_guess_addr

static int
rtpp_stream_guess_addr(struct rtpp_stream *self,
  struct rtp_packet *packet)
{
    int rport;
    const char *actor, *ptype;
    struct rtpp_stream_priv *pvt;

    pvt = PUB2PVT(self);

    if (self->addr != NULL && ishostseq(self->addr, sstosa(&packet->raddr))) {
        return (0);
    }
    if (self->addr == NULL) {
        self->addr = malloc(packet->rlen);
        if (self->addr == NULL) {
            return (-1);
        }
    }
    actor = rtpp_stream_get_actor(self);
    ptype =  rtpp_stream_get_proto(self);
    rport = ntohs(satosin(&packet->raddr)->sin_port);
    if (IS_LAST_PORT(rport)) {
        return (-1);
    }
    memcpy(self->addr, &packet->raddr, packet->rlen);
    satosin(self->addr)->sin_port = htons(rport + 1);
    /* Use guessed value as the only true one for asymmetric clients */
    self->latch_info.latched = self->asymmetric;
    RTPP_LOG(pvt->pub.log, RTPP_LOG_INFO, "guessing %s port "
      "for %s to be %d", ptype, actor, rport + 1);

    return (0);
}
开发者ID:digideskio,项目名称:rtpproxy,代码行数:34,代码来源:rtpp_stream.c

示例2: prepare_pkt_hdr_adhoc

static int
prepare_pkt_hdr_adhoc(struct rtpp_session *sp, struct rtp_packet *packet,
  struct pkt_hdr_adhoc *hdrp, struct sockaddr *daddr, struct sockaddr *ldaddr,
  int ldport, int face)
{

    memset(hdrp, 0, sizeof(*hdrp));
    hdrp->time = packet->rtime;
    if (hdrp->time == -1) {
	rtpp_log_ewrite(RTPP_LOG_ERR, sp->log, "can't get current time");
	return -1;
    }
    switch (sstosa(&packet->raddr)->sa_family) {
    case AF_INET:
	hdrp->addr.in4.sin_family = sstosa(&packet->raddr)->sa_family;
	hdrp->addr.in4.sin_port = satosin(&packet->raddr)->sin_port;
	hdrp->addr.in4.sin_addr = satosin(&packet->raddr)->sin_addr;
	break;

    case AF_INET6:
	hdrp->addr.in6.sin_family = sstosa(&packet->raddr)->sa_family;
	hdrp->addr.in6.sin_port = satosin6(&packet->raddr)->sin6_port;
	hdrp->addr.in6.sin_addr = satosin6(&packet->raddr)->sin6_addr;
	break;

    default:
	abort();
    }

    hdrp->plen = packet->size;
    return 0;
}
开发者ID:changtailiang,项目名称:rtpproxy,代码行数:32,代码来源:rtpp_record.c

示例3: rwrite

void
rwrite(struct rtpp_session *sp, void *rrc, struct sockaddr *saddr, void *buf, int len)
{
    struct iovec v[2];
    struct pkt_hdr hdr;
    int rval;

    if (RRC_CAST(rrc)->fd == -1)
        return;

    memset(&hdr, 0, sizeof(hdr));

    hdr.time = getctime();
    if (hdr.time == -1) {
	rtpp_log_ewrite(RTPP_LOG_ERR, sp->log, "can't get current time");
	goto fatal_error;
    }

    switch (saddr->sa_family) {
    case AF_INET:
	hdr.addr.in4.sin_family = saddr->sa_family;
	hdr.addr.in4.sin_port = satosin(saddr)->sin_port;
	hdr.addr.in4.sin_addr = satosin(saddr)->sin_addr;
	break;

    case AF_INET6:
	hdr.addr.in6.sin_family = saddr->sa_family;
	hdr.addr.in6.sin_port = satosin6(saddr)->sin6_port;
	hdr.addr.in6.sin_addr = satosin6(saddr)->sin6_addr;
	break;

    default:
	abort();
    }

    hdr.plen = len;

    v[0].iov_base = (void *)&hdr;
    v[0].iov_len = sizeof(hdr);
    v[1].iov_base = buf;
    v[1].iov_len = len;

    rval = writev(RRC_CAST(rrc)->fd, v, 2);
    if (rval != -1)
	return;

    rtpp_log_ewrite(RTPP_LOG_ERR, sp->log, "error while recording session (%s)",
      (sp->rtcp != NULL) ? "RTP" : "RTCP");
fatal_error:
    /* Prevent futher writing if error happens */
    close(RRC_CAST(rrc)->fd);
    RRC_CAST(rrc)->fd = -1;
}
开发者ID:BackupTheBerlios,项目名称:semsivr,代码行数:53,代码来源:rtpp_record.c

示例4: server_lookup

int
server_lookup(struct sockaddr *client, struct sockaddr *proxy,
    struct sockaddr *server, u_int8_t proto)
{
	if (client->sa_family == AF_INET)
		return (server_lookup4(satosin(client), satosin(proxy),
		    satosin(server), proto));

	if (client->sa_family == AF_INET6)
		return (server_lookup6(satosin6(client), satosin6(proxy),
		    satosin6(server), proto));

	errno = EPROTONOSUPPORT;
	return (-1);
}
开发者ID:MattDooner,项目名称:freebsd-west,代码行数:15,代码来源:filter.c

示例5: tuninit

/*
 * Call at splnet().
 */
static void
tuninit(struct tun_softc *tp)
{
	struct ifnet	*ifp = &tp->tun_if;
	struct ifaddr	*ifa;

	TUNDEBUG("%s: tuninit\n", ifp->if_xname);

	mutex_enter(&tp->tun_lock);
	ifp->if_flags |= IFF_UP | IFF_RUNNING;

	tp->tun_flags &= ~(TUN_IASET|TUN_DSTADDR);
	IFADDR_FOREACH(ifa, ifp) {
#ifdef INET
		if (ifa->ifa_addr->sa_family == AF_INET) {
			struct sockaddr_in *sin;

			sin = satosin(ifa->ifa_addr);
			if (sin && sin->sin_addr.s_addr)
				tp->tun_flags |= TUN_IASET;

			if (ifp->if_flags & IFF_POINTOPOINT) {
				sin = satosin(ifa->ifa_dstaddr);
				if (sin && sin->sin_addr.s_addr)
					tp->tun_flags |= TUN_DSTADDR;
			}
		}
#endif
#ifdef INET6
		if (ifa->ifa_addr->sa_family == AF_INET6) {
			struct sockaddr_in6 *sin;

			sin = (struct sockaddr_in6 *)ifa->ifa_addr;
			if (!IN6_IS_ADDR_UNSPECIFIED(&sin->sin6_addr))
				tp->tun_flags |= TUN_IASET;

			if (ifp->if_flags & IFF_POINTOPOINT) {
				sin = (struct sockaddr_in6 *)ifa->ifa_dstaddr;
				if (sin &&
				    !IN6_IS_ADDR_UNSPECIFIED(&sin->sin6_addr))
					tp->tun_flags |= TUN_DSTADDR;
			} else
				tp->tun_flags &= ~TUN_DSTADDR;
		}
#endif /* INET6 */
	}
	mutex_exit(&tp->tun_lock);
}
开发者ID:RyanLucchese,项目名称:rumpkernel-netbsd-src,代码行数:51,代码来源:if_tun.c

示例6: add_nat

int
add_nat(u_int32_t id, struct sockaddr *src, struct sockaddr *dst,
    u_int16_t d_port, struct sockaddr *nat, u_int16_t nat_range_low,
    u_int16_t nat_range_high, u_int8_t proto)
{
	if (!src || !dst || !d_port || !nat || !nat_range_low || !proto ||
	    (src->sa_family != nat->sa_family)) {
		errno = EINVAL;
		return (-1);
	}

	if (prepare_rule(id, PF_RULESET_NAT, src, dst, d_port, proto) == -1)
		return (-1);

	if (nat->sa_family == AF_INET) {
		memcpy(&pfp.addr.addr.v.a.addr.v4,
		    &satosin(nat)->sin_addr.s_addr, 4);
		memset(&pfp.addr.addr.v.a.mask.addr8, 255, 4);
	} else {
		memcpy(&pfp.addr.addr.v.a.addr.v6,
		    &satosin6(nat)->sin6_addr.s6_addr, 16);
		memset(&pfp.addr.addr.v.a.mask.addr8, 255, 16);
	}
	if (ioctl(dev, DIOCADDADDR, &pfp) == -1)
		return (-1);

	pfr.rule.rpool.proxy_port[0] = nat_range_low;
	pfr.rule.rpool.proxy_port[1] = nat_range_high;
	if (ioctl(dev, DIOCADDRULE, &pfr) == -1)
		return (-1);

	return (0);
}
开发者ID:MattDooner,项目名称:freebsd-west,代码行数:33,代码来源:filter.c

示例7: routename

char *
routename(struct sockaddr *sa, int flags)
{
	static char line[NI_MAXHOST];
	int error, f;

	f = (flags) ? NI_NUMERICHOST : 0;
	error = getnameinfo(sa, sa->sa_len, line, sizeof(line),
	    NULL, 0, f);
	if (error) {
		const void *src;
		switch (sa->sa_family) {
#ifdef INET
		case AF_INET:
			src = &satosin(sa)->sin_addr;
			break;
#endif /* INET */
#ifdef INET6
		case AF_INET6:
			src = &satosin6(sa)->sin6_addr;
			break;
#endif /* INET6 */
		default:
			return(line);
		}
		inet_ntop(sa->sa_family, src, line, sizeof(line) - 1);
		return (line);
	}
	trimdomain(line, strlen(line));

	return (line);
}
开发者ID:mulichao,项目名称:freebsd,代码行数:32,代码来源:route.c

示例8: add_rdr

int
add_rdr(u_int32_t id, struct sockaddr *src, struct sockaddr *dst,
    u_int16_t d_port, struct sockaddr *rdr, u_int16_t rdr_port, u_int8_t proto)
{
	if (!src || !dst || !d_port || !rdr || !rdr_port || !proto ||
	    (src->sa_family != rdr->sa_family)) {
		errno = EINVAL;
		return (-1);
	}

	if (prepare_rule(id, PF_RULESET_RDR, src, dst, d_port, proto) == -1)
		return (-1);

	if (rdr->sa_family == AF_INET) {
		memcpy(&pfp.addr.addr.v.a.addr.v4,
		    &satosin(rdr)->sin_addr.s_addr, 4);
		memset(&pfp.addr.addr.v.a.mask.addr8, 255, 4);
	} else {
		memcpy(&pfp.addr.addr.v.a.addr.v6,
		    &satosin6(rdr)->sin6_addr.s6_addr, 16);
		memset(&pfp.addr.addr.v.a.mask.addr8, 255, 16);
	}
	if (ioctl(dev, DIOCADDADDR, &pfp) == -1)
		return (-1);

	pfr.rule.rpool.proxy_port[0] = rdr_port;
	if (ioctl(dev, DIOCADDRULE, &pfr) == -1)
		return (-1);

	return (0);
}
开发者ID:MattDooner,项目名称:freebsd-west,代码行数:31,代码来源:filter.c

示例9: openlog

void
openlog(const char *ident, int logstat, int logfac)
{
	if (ident != NULL)
		LogTag = ident;
	LogStat = logstat;
	if (logfac != 0 && (logfac &~ LOG_FACMASK) == 0)
		LogFacility = logfac;

	if (LogFile == -1) {
#ifndef USE_INET
		SyslogAddr.sa_family = AF_UNIX;
		(void)strncpy(SyslogAddr.sa_data, _PATH_LOG,
		    sizeof(SyslogAddr.sa_data));
		if (LogStat & LOG_NDELAY) {
			if ((LogFile = socket(AF_UNIX, SOCK_DGRAM, 0)) == -1)
				return;
			(void)fcntl(LogFile, F_SETFD, 1);
		}
#else
#define satosin(sa)     ((struct sockaddr_in *)(sa))

		satosin(&SyslogAddr)->sin_family = AF_INET;
		satosin(&SyslogAddr)->sin_port = 514;
		satosin(&SyslogAddr)->sin_addr.s_addr = inet_addr("127.0.0.1");
		if (LogStat & LOG_NDELAY) {
			if ((LogFile = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
				return;
			(void)fcntl(LogFile, F_SETFD, 1);
			if (connect(LogFile, &SyslogAddr,
			    sizeof(SyslogAddr)) < 0) {
				closelog();
				return;
			}
		}
#endif
	}
	if (LogFile != -1 && !connected) {
		if (connect(LogFile, &SyslogAddr, sizeof(SyslogAddr)) == -1) {
			(void)close(LogFile);
			LogFile = -1;
		} else
			connected = 1;
	}
}
开发者ID:boateam,项目名称:boa,代码行数:45,代码来源:syslog.c

示例10: set_mcast_if

int set_mcast_if(struct sockaddr *int_addr)
{
struct in_addr if_addr;
	if_addr.s_addr = satosin(*int_addr)->sin_addr.s_addr;
	return setsockopt_multicast_ipv4(sock, 
			IP_MULTICAST_IF, 
			if_addr,
			0xE0000009,
			0);
}
开发者ID:appleorange1,项目名称:asus-rt-n12-lx,代码行数:10,代码来源:main.c

示例11: mcast_leave

int mcast_leave(struct sockaddr *int_addr)
{
struct in_addr if_addr;
	if_addr.s_addr = satosin(*int_addr)->sin_addr.s_addr;
	return setsockopt_multicast_ipv4(sock, 
			IP_DROP_MEMBERSHIP, 
			if_addr,
			0xE0000009,
			0);
}
开发者ID:appleorange1,项目名称:asus-rt-n12-lx,代码行数:10,代码来源:main.c

示例12: Mod_fw_lookup_orig_dst

int
Mod_fw_lookup_orig_dst(FW_handle_T handle, struct sockaddr *src,
                       struct sockaddr *proxy, struct sockaddr *orig_dst)
{
    struct fw_handle *fwh = handle->fwh;

    if(src->sa_family == AF_INET) {
        return server_lookup4(fwh->pfdev, satosin(src), satosin(proxy),
                              satosin(orig_dst));
    }

    if(src->sa_family == AF_INET6) {
        return server_lookup6(fwh->pfdev, satosin6(src), satosin6(proxy),
                              satosin6(orig_dst));
    }

    errno = EPROTONOSUPPORT;
    return -1;
}
开发者ID:FluentDevelopment,项目名称:greyd,代码行数:19,代码来源:pf.c

示例13: create_twinlistener

static int
create_twinlistener(struct cfg_stable *cf, struct sockaddr *ia, int port, int *fds)
{
    struct sockaddr_storage iac;
    int rval, i, flags;

    fds[0] = fds[1] = -1;

    rval = -1;

    for (i = 0; i < 2; i++) {
        fds[i] = socket(ia->sa_family, SOCK_DGRAM, 0);

        if (fds[i] == -1) {
            rtpp_log_ewrite(RTPP_LOG_ERR, cf->glog, "can't create %s socket",
                            (ia->sa_family == AF_INET) ? "IPv4" : "IPv6");
            goto failure;
        }

        memcpy(&iac, ia, SA_LEN(ia));
        satosin(&iac)->sin_port = htons(port);

        if (bind(fds[i], sstosa(&iac), SA_LEN(ia)) != 0) {
            if (errno != EADDRINUSE && errno != EACCES) {
                rtpp_log_ewrite(RTPP_LOG_ERR, cf->glog, "can't bind to the %s port %d",
                                (ia->sa_family == AF_INET) ? "IPv4" : "IPv6", port);
            } else {
                rval = -2;
            }

            goto failure;
        }

        port++;

        if ((ia->sa_family == AF_INET) && (cf->tos >= 0) &&
                (setsockopt(fds[i], IPPROTO_IP, IP_TOS, &cf->tos, sizeof(cf->tos)) == -1))
            rtpp_log_ewrite(RTPP_LOG_ERR, cf->glog, "unable to set TOS to %d", cf->tos);

        flags = fcntl(fds[i], F_GETFL);
        fcntl(fds[i], F_SETFL, flags | O_NONBLOCK);
    }

    return 0;

failure:

    for (i = 0; i < 2; i++)
        if (fds[i] != -1) {
            close(fds[i]);
            fds[i] = -1;
        }

    return rval;
}
开发者ID:sambatyon,项目名称:rtpproxy,代码行数:55,代码来源:rtpp_command.c

示例14: netname

/*
 * Return the name of the network whose address is given.
 */
const char *
netname(struct sockaddr *sa, struct sockaddr *mask)
{
	switch (sa->sa_family) {
	case AF_INET:
		if (mask != NULL)
			return (netname4(satosin(sa)->sin_addr.s_addr,
			    satosin(mask)->sin_addr.s_addr));
		else
			return (netname4(satosin(sa)->sin_addr.s_addr,
			    INADDR_ANY));
		break;
#ifdef INET6
	case AF_INET6:
		return (netname6(satosin6(sa), satosin6(mask)));
#endif /* INET6 */
	default:
		return (NULL);
	}
}
开发者ID:mulichao,项目名称:freebsd,代码行数:23,代码来源:route.c

示例15: prepare_pkt_hdr_pcap

static int
prepare_pkt_hdr_pcap(struct rtpp_session *sp, struct rtp_packet *packet, struct pkt_hdr_pcap *hdrp)
{

    if (packet->rtime == -1) {
	rtpp_log_ewrite(RTPP_LOG_ERR, sp->log, "can't get current time");
	return -1;
    }

    if (sstosa(&packet->raddr)->sa_family != AF_INET) {
	rtpp_log_ewrite(RTPP_LOG_ERR, sp->log, "only AF_INET pcap format is supported");
	return -1;
    }

    memset(hdrp, 0, sizeof(*hdrp));
    dtime2ts(packet->rtime, &(hdrp->pcaprec_hdr.ts_sec), &(hdrp->pcaprec_hdr.ts_usec));
    hdrp->pcaprec_hdr.orig_len = hdrp->pcaprec_hdr.incl_len = sizeof(*hdrp) -
      sizeof(hdrp->pcaprec_hdr) + packet->size;

    hdrp->family = sstosa(&packet->raddr)->sa_family;

    /* Prepare fake IP header */
    hdrp->iphdr.ip_v = 4;
    hdrp->iphdr.ip_hl = sizeof(hdrp->iphdr) >> 2;
    hdrp->iphdr.ip_len = htons(sizeof(hdrp->iphdr) + sizeof(hdrp->udphdr) + packet->size);
    hdrp->iphdr.ip_src = satosin(&(packet->raddr))->sin_addr;
    hdrp->iphdr.ip_dst = satosin(packet->laddr)->sin_addr;
    hdrp->iphdr.ip_p = IPPROTO_UDP;
    hdrp->iphdr.ip_id = htons(ip_id++);
    hdrp->iphdr.ip_ttl = 127;
    hdrp->iphdr.ip_sum = rtpp_in_cksum(&(hdrp->iphdr), sizeof(hdrp->iphdr));

    /* Prepare fake UDP header */
    hdrp->udphdr.uh_sport = satosin(&packet->raddr)->sin_port;
    hdrp->udphdr.uh_dport = htons(packet->rport);
    hdrp->udphdr.uh_ulen = htons(sizeof(hdrp->udphdr) + packet->size);

    return 0;
}
开发者ID:gtkiller,项目名称:rtpproxyd,代码行数:39,代码来源:rtpp_record.c


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