本文整理汇总了C++中satosin函数的典型用法代码示例。如果您正苦于以下问题:C++ satosin函数的具体用法?C++ satosin怎么用?C++ satosin使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了satosin函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: in_addroute
/*
* Do what we need to do when inserting a route.
*/
static struct radix_node *
in_addroute(void *v_arg, void *n_arg, struct radix_node_head *head,
struct radix_node *treenodes)
{
struct rtentry *rt = (struct rtentry *)treenodes;
struct sockaddr_in *sin = (struct sockaddr_in *)rt_key(rt);
RADIX_NODE_HEAD_WLOCK_ASSERT(head);
/*
* A little bit of help for both IP output and input:
* For host routes, we make sure that RTF_BROADCAST
* is set for anything that looks like a broadcast address.
* This way, we can avoid an expensive call to in_broadcast()
* in ip_output() most of the time (because the route passed
* to ip_output() is almost always a host route).
*
* We also do the same for local addresses, with the thought
* that this might one day be used to speed up ip_input().
*
* We also mark routes to multicast addresses as such, because
* it's easy to do and might be useful (but this is much more
* dubious since it's so easy to inspect the address).
*/
if (rt->rt_flags & RTF_HOST) {
if (in_broadcast(sin->sin_addr, rt->rt_ifp)) {
rt->rt_flags |= RTF_BROADCAST;
} else if (satosin(rt->rt_ifa->ifa_addr)->sin_addr.s_addr ==
sin->sin_addr.s_addr) {
rt->rt_flags |= RTF_LOCAL;
}
}
if (IN_MULTICAST(ntohl(sin->sin_addr.s_addr)))
rt->rt_flags |= RTF_MULTICAST;
if (rt->rt_ifp != NULL) {
/*
* Check route MTU:
* inherit interface MTU if not set or
* check if MTU is too large.
*/
if (rt->rt_mtu == 0) {
rt->rt_mtu = rt->rt_ifp->if_mtu;
} else if (rt->rt_mtu > rt->rt_ifp->if_mtu)
rt->rt_mtu = rt->rt_ifp->if_mtu;
}
return (rn_addroute(v_arg, n_arg, head, treenodes));
}
开发者ID:jp629,项目名称:freebsd,代码行数:52,代码来源:in_rmx.c
示例17: add_addr
int
add_addr(struct sockaddr *addr, struct pf_pool *pfp)
{
if (addr->sa_family == AF_INET) {
memcpy(&pfp->addr.v.a.addr.v4,
&satosin(addr)->sin_addr.s_addr, 4);
memset(&pfp->addr.v.a.mask.addr8, 255, 4);
} else {
memcpy(&pfp->addr.v.a.addr.v6,
&satosin6(addr)->sin6_addr.s6_addr, 16);
memset(&pfp->addr.v.a.mask.addr8, 255, 16);
}
pfp->addr.type = PF_ADDR_ADDRMASK;
return (0);
}
开发者ID:SylvestreG,项目名称:bitrig,代码行数:15,代码来源:filter.c
示例18: inpcb_find_anypcb_byaddr
__private_extern__ uint32_t
inpcb_find_anypcb_byaddr(struct ifaddr *ifa, struct inpcbinfo *pcbinfo)
{
struct inpcb *inp;
inp_gen_t gencnt = pcbinfo->ipi_gencnt;
struct socket *so = NULL;
int af;
if ((ifa->ifa_addr->sa_family != AF_INET) &&
(ifa->ifa_addr->sa_family != AF_INET6)) {
return (0);
}
lck_rw_lock_shared(pcbinfo->ipi_lock);
for (inp = LIST_FIRST(pcbinfo->ipi_listhead);
inp != NULL; inp = LIST_NEXT(inp, inp_list)) {
if (inp->inp_gencnt <= gencnt &&
inp->inp_state != INPCB_STATE_DEAD &&
inp->inp_socket != NULL) {
so = inp->inp_socket;
af = SOCK_DOM(so);
if (af != ifa->ifa_addr->sa_family)
continue;
if (inp->inp_last_outifp != ifa->ifa_ifp)
continue;
if (af == AF_INET) {
if (inp->inp_laddr.s_addr ==
(satosin(ifa->ifa_addr))->sin_addr.s_addr) {
lck_rw_done(pcbinfo->ipi_lock);
return (1);
}
}
if (af == AF_INET6) {
if (IN6_ARE_ADDR_EQUAL(IFA_IN6(ifa),
&inp->in6p_laddr)) {
lck_rw_done(pcbinfo->ipi_lock);
return (1);
}
}
}
}
lck_rw_done(pcbinfo->ipi_lock);
return (0);
}
开发者ID:jndok,项目名称:xnu,代码行数:46,代码来源:in_pcblist.c
示例19: in_pcbladdr
int
in_pcbladdr(struct inpcb *inp, struct mbuf *nam, struct sockaddr_in **plocal_sin)
{
struct in_ifaddr *ia;
register struct sockaddr_in *sin = mtod(nam, struct sockaddr_in *);
if (nam->m_len != sizeof (*sin))
return (EINVAL);
if (sin->sin_family != AF_INET)
return (EAFNOSUPPORT);
if (sin->sin_port == 0)
return (EADDRNOTAVAIL);
if (in_ifaddr) {
/*
* If the destination address is INADDR_ANY,
* use the primary local address.
* If the supplied address is INADDR_BROADCAST,
* and the primary interface supports broadcast,
* choose the broadcast address for that interface.
*/
#define satosin(sa) ((struct sockaddr_in *)(sa))
#define sintosa(sin) ((struct sockaddr *)(sin))
#define ifatoia(ifa) ((struct in_ifaddr *)(ifa))
if (sin->sin_addr.s_addr == INADDR_ANY)
sin->sin_addr = IA_SIN(in_ifaddr)->sin_addr;
else if (sin->sin_addr.s_addr == (u_long)INADDR_BROADCAST &&
(in_ifaddr->ia_ifp->if_flags & IFF_BROADCAST))
sin->sin_addr = satosin(&in_ifaddr->ia_broadaddr)->sin_addr;
}
if (inp->inp_laddr.s_addr == INADDR_ANY) {
register struct route *ro;
ia = (struct in_ifaddr *)0;
/*
* If route is known or can be allocated now,
* our src addr is taken from the i/f, else punt.
*/
ro = &inp->inp_route;
if (ro->ro_rt &&
(satosin(&ro->ro_dst)->sin_addr.s_addr !=
sin->sin_addr.s_addr ||
inp->inp_socket->so_options & SO_DONTROUTE)) {
RTFREE(ro->ro_rt);
ro->ro_rt = (struct rtentry *)0;
}
if ((inp->inp_socket->so_options & SO_DONTROUTE) == 0 && /*XXX*/
(ro->ro_rt == (struct rtentry *)0 ||
ro->ro_rt->rt_ifp == (struct ifnet *)0)) {
/* No route yet, so try to acquire one */
ro->ro_dst.sa_family = AF_INET;
ro->ro_dst.sa_len = sizeof(struct sockaddr_in);
((struct sockaddr_in *) &ro->ro_dst)->sin_addr =
sin->sin_addr;
rtalloc(ro);
}
/*
* If we found a route, use the address
* corresponding to the outgoing interface
* unless it is the loopback (in case a route
* to our address on another net goes to loopback).
*/
if (ro->ro_rt && !(ro->ro_rt->rt_ifp->if_flags & IFF_LOOPBACK))
ia = ifatoia(ro->ro_rt->rt_ifa);
if (ia == 0) {
u_short fport = sin->sin_port;
sin->sin_port = 0;
ia = ifatoia(ifa_ifwithdstaddr(sintosa(sin)));
if (ia == 0)
ia = ifatoia(ifa_ifwithnet(sintosa(sin)));
sin->sin_port = fport;
if (ia == 0)
ia = in_ifaddr;
if (ia == 0)
return (EADDRNOTAVAIL);
}
/*
* If the destination address is multicast and an outgoing
* interface has been set as a multicast option, use the
* address of that interface as our source address.
*/
if (IN_MULTICAST(ntohl(sin->sin_addr.s_addr)) &&
inp->inp_moptions != NULL) {
struct ip_moptions *imo;
struct ifnet *ifp;
imo = inp->inp_moptions;
if (imo->imo_multicast_ifp != NULL) {
ifp = imo->imo_multicast_ifp;
for (ia = in_ifaddr; ia; ia = ia->ia_next)
if (ia->ia_ifp == ifp)
break;
if (ia == 0)
return (EADDRNOTAVAIL);
}
}
/*
* Don't do pcblookup call here; return interface in plocal_sin
* and exit to caller, that will do the lookup.
*/
//.........这里部分代码省略.........
开发者ID:FullMentalPanic,项目名称:RTEMS_NEW_TOOL_CHAIN,代码行数:101,代码来源:in_pcb.c
示例20: rtpp_command_ul_opts_parse
//.........这里部分代码省略.........
memcpy(ulop->codecs, t, cp - t);
ulop->codecs[cp - t] = '\0';
cp--;
break;
case 'l':
case 'L':
len = extractaddr(cp + 1, &t, &cp, &tpf);
if (len == -1) {
RTPP_LOG(cf->stable->glog, RTPP_LOG_ERR, "command syntax error");
reply_error(cmd, ECODE_PARSE_15);
goto err_undo_1;
}
c = t[len];
t[len] = '\0';
ulop->local_addr = host2bindaddr(cf, t, tpf, &errmsg);
if (ulop->local_addr == NULL) {
RTPP_LOG(cf->stable->glog, RTPP_LOG_ERR,
"invalid local address: %s: %s", t, errmsg);
reply_error(cmd, ECODE_INVLARG_1);
goto err_undo_1;
}
t[len] = c;
cp--;
break;
case 'r':
case 'R':
len = extractaddr(cp + 1, &t, &cp, &tpf);
if (len == -1) {
RTPP_LOG(cf->stable->glog, RTPP_LOG_ERR, "command syntax error");
reply_error(cmd, ECODE_PARSE_16);
goto err_undo_1;
}
c = t[len];
t[len] = '\0';
ulop->local_addr = alloca(sizeof(struct sockaddr_storage));
n = resolve(ulop->local_addr, tpf, t, SERVICE, AI_PASSIVE);
if (n != 0) {
RTPP_LOG(cf->stable->glog, RTPP_LOG_ERR,
"invalid remote address: %s: %s", t, gai_strerror(n));
reply_error(cmd, ECODE_INVLARG_2);
goto err_undo_1;
}
if (local4remote(ulop->local_addr, satoss(ulop->local_addr)) == -1) {
RTPP_LOG(cf->stable->glog, RTPP_LOG_ERR,
"can't find local address for remote address: %s", t);
reply_error(cmd, ECODE_INVLARG_3);
goto err_undo_1;
}
ulop->local_addr = addr2bindaddr(cf, ulop->local_addr, &errmsg);
if (ulop->local_addr == NULL) {
RTPP_LOG(cf->stable->glog, RTPP_LOG_ERR,
"invalid local address: %s", errmsg);
reply_error(cmd, ECODE_INVLARG_4);
goto err_undo_1;
}
t[len] = c;
cp--;
break;
case 'n':
case 'N':
ulop->new_port = 1;
break;
default:
RTPP_LOG(cf->stable->glog, RTPP_LOG_ERR, "unknown command modifier `%c'",
*cp);
break;
}
}
if (ulop->addr != NULL && ulop->port != NULL && strlen(ulop->addr) >= 7) {
n = resolve(sstosa(&tia), ulop->pf, ulop->addr, ulop->port, AI_NUMERICHOST);
if (n == 0) {
if (!ishostnull(sstosa(&tia))) {
for (i = 0; i < 2; i++) {
ulop->ia[i] = malloc(SS_LEN(&tia));
if (ulop->ia[i] == NULL) {
reply_error(cmd, ECODE_NOMEM_3);
goto err_undo_1;
}
memcpy(ulop->ia[i], &tia, SS_LEN(&tia));
}
/* Set port for RTCP, will work both for IPv4 and IPv6 */
n = ntohs(satosin(ulop->ia[1])->sin_port);
satosin(ulop->ia[1])->sin_port = htons(n + 1);
}
} else {
RTPP_LOG(cf->stable->glog, RTPP_LOG_ERR, "getaddrinfo(pf=%d, addr=%s, port=%s): %s",
ulop->pf, ulop->addr, ulop->port, gai_strerror(n));
}
}
return (ulop);
err_undo_1:
rtpp_command_ul_opts_free(ulop);
err_undo_0:
return (NULL);
}
开发者ID:kcratie,项目名称:rtpproxy,代码行数:101,代码来源:rtpp_command_ul.c
注:本文中的satosin函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论