本文整理汇总了C++中M_PREPEND函数的典型用法代码示例。如果您正苦于以下问题:C++ M_PREPEND函数的具体用法?C++ M_PREPEND怎么用?C++ M_PREPEND使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了M_PREPEND函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: tkip_encap
/*
* Add privacy headers and do any s/w encryption required.
*/
static int
tkip_encap(struct ieee80211_key *k, struct mbuf *m, uint8_t keyid)
{
struct tkip_ctx *ctx = k->wk_private;
struct ieee80211vap *vap = ctx->tc_vap;
struct ieee80211com *ic = vap->iv_ic;
uint8_t *ivp;
int hdrlen;
/*
* Handle TKIP counter measures requirement.
*/
if (vap->iv_flags & IEEE80211_F_COUNTERM) {
#ifdef IEEE80211_DEBUG
struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *);
#endif
IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_CRYPTO, wh->i_addr2,
"discard frame due to countermeasures (%s)", __func__);
vap->iv_stats.is_crypto_tkipcm++;
return 0;
}
hdrlen = ieee80211_hdrspace(ic, mtod(m, void *));
/*
* Copy down 802.11 header and add the IV, KeyID, and ExtIV.
*/
M_PREPEND(m, tkip.ic_header, M_NOWAIT);
if (m == NULL)
return 0;
ivp = mtod(m, uint8_t *);
memmove(ivp, ivp + tkip.ic_header, hdrlen);
ivp += hdrlen;
ivp[0] = k->wk_keytsc >> 8; /* TSC1 */
ivp[1] = (ivp[0] | 0x20) & 0x7f; /* WEP seed */
ivp[2] = k->wk_keytsc >> 0; /* TSC0 */
ivp[3] = keyid | IEEE80211_WEP_EXTIV; /* KeyID | ExtID */
ivp[4] = k->wk_keytsc >> 16; /* TSC2 */
ivp[5] = k->wk_keytsc >> 24; /* TSC3 */
ivp[6] = k->wk_keytsc >> 32; /* TSC4 */
ivp[7] = k->wk_keytsc >> 40; /* TSC5 */
#if 0
if (hdrlen == 24)
{
M_PREPEND(m, tkip.ic_miclen + 12, M_NOWAIT);
if (m == NULL)
return 0;
ivp = mtod(m, uint8_t *);
memmove(ivp, ivp + tkip.ic_miclen + 12, hdrlen + tkip.ic_header);
ivp += hdrlen + tkip.ic_header;
bzero(ivp, 20);
memcpy((ivp+12), k->wk_txmic, tkip.ic_header);
}
开发者ID:anilkumarnagella,项目名称:redpine,代码行数:57,代码来源:ieee80211_crypto_tkip.c
示例2: rip_output
/*
* Generate IP header and pass packet to ip_output.
* Tack on options user may have setup with control call.
*/
int
rip_output(struct mbuf *m, struct socket *so, u_long dst)
{
struct ip *ip;
struct inpcb *inp = sotoinpcb(so);
int flags = ((so->so_options & SO_DONTROUTE) ? IP_ROUTETOIF : 0) |
IP_ALLOWBROADCAST;
/*
* If the user handed us a complete IP packet, use it.
* Otherwise, allocate an mbuf for a header and fill it in.
*/
if ((inp->inp_flags & INP_HDRINCL) == 0) {
if (m->m_pkthdr.len + sizeof(struct ip) > IP_MAXPACKET) {
m_freem(m);
return(EMSGSIZE);
}
M_PREPEND(m, sizeof(struct ip), M_WAIT);
ip = mtod(m, struct ip *);
ip->ip_tos = 0;
ip->ip_off = 0;
ip->ip_p = inp->inp_ip_p;
ip->ip_len = m->m_pkthdr.len;
ip->ip_src = inp->inp_laddr;
ip->ip_dst.s_addr = dst;
ip->ip_ttl = MAXTTL;
} else {
if (m->m_pkthdr.len > IP_MAXPACKET) {
开发者ID:jfpmonteiro,项目名称:rtems-4.8-rhealstone,代码行数:32,代码来源:raw_ip.c
示例3: netdump_ether_output
/*
* Handles creation of the ethernet header, then places outgoing packets into
* the tx buffer for the NIC
*
* Parameters:
* m The mbuf containing the packet to be sent (will be freed by
* this function or the NIC driver)
* ifp The interface to send on
* dst The destination ethernet address (source address will be looked
* up using ifp)
* etype The ETHERTYPE_* value for the protocol that is being sent
*
* Returns:
* int see errno.h, 0 for success
*/
static int
netdump_ether_output(struct mbuf *m, struct ifnet *ifp, struct ether_addr dst,
u_short etype)
{
struct ether_header *eh;
if (((ifp->if_flags & (IFF_MONITOR | IFF_UP)) != IFF_UP) ||
(ifp->if_drv_flags & IFF_DRV_RUNNING) != IFF_DRV_RUNNING) {
if_printf(ifp, "netdump_ether_output: interface isn't up\n");
m_freem(m);
return (ENETDOWN);
}
/* Fill in the ethernet header. */
M_PREPEND(m, ETHER_HDR_LEN, M_NOWAIT);
if (m == NULL) {
printf("%s: out of mbufs\n", __func__);
return (ENOBUFS);
}
eh = mtod(m, struct ether_header *);
memcpy(eh->ether_shost, IF_LLADDR(ifp), ETHER_ADDR_LEN);
memcpy(eh->ether_dhost, dst.octet, ETHER_ADDR_LEN);
eh->ether_type = htons(etype);
return ((ifp->if_netdump_methods->nd_transmit)(ifp, m));
}
开发者ID:derekmarcotte,项目名称:freebsd,代码行数:40,代码来源:netdump_client.c
示例4: sscfu_send_lower
static void
sscfu_send_lower(struct sscfu *sscf, void *p, enum sscop_aasig sig,
struct mbuf *m, u_int arg)
{
node_p node = (node_p)p;
struct priv *priv = NG_NODE_PRIVATE(node);
int error;
struct sscop_arg *a;
if (priv->lower == NULL) {
if (m != NULL)
m_freem(m);
return;
}
if (m == NULL) {
MGETHDR(m, M_NOWAIT, MT_DATA);
if (m == NULL)
return;
m->m_len = sizeof(struct sscop_arg);
m->m_pkthdr.len = m->m_len;
} else {
M_PREPEND(m, sizeof(struct sscop_arg), M_NOWAIT);
if (m == NULL)
return;
}
a = mtod(m, struct sscop_arg *);
a->sig = sig;
a->arg = arg;
NG_SEND_DATA_ONLY(error, priv->lower, m);
}
开发者ID:MarginC,项目名称:kame,代码行数:31,代码来源:ng_sscfu.c
示例5: fwe_as_output
/* Async. stream output */
static void
fwe_as_output(struct fwe_softc *fwe, struct ifnet *ifp)
{
struct mbuf *m;
struct fw_xfer *xfer;
struct fw_xferq *xferq;
struct fw_pkt *fp;
int i = 0;
xfer = NULL;
xferq = fwe->fd.fc->atq;
while ((xferq->queued < xferq->maxq - 1) &&
(ifp->if_snd.ifq_head != NULL)) {
FWE_LOCK(fwe);
xfer = STAILQ_FIRST(&fwe->xferlist);
if (xfer == NULL) {
#if 0
printf("if_fwe: lack of xfer\n");
#endif
FWE_UNLOCK(fwe);
break;
}
STAILQ_REMOVE_HEAD(&fwe->xferlist, link);
FWE_UNLOCK(fwe);
IF_DEQUEUE(&ifp->if_snd, m);
if (m == NULL) {
FWE_LOCK(fwe);
STAILQ_INSERT_HEAD(&fwe->xferlist, xfer, link);
FWE_UNLOCK(fwe);
break;
}
BPF_MTAP(ifp, m);
/* keep ip packet alignment for alpha */
M_PREPEND(m, ETHER_ALIGN, M_NOWAIT);
fp = &xfer->send.hdr;
*(uint32_t *)&xfer->send.hdr = *(int32_t *)&fwe->pkt_hdr;
fp->mode.stream.len = m->m_pkthdr.len;
xfer->mbuf = m;
xfer->send.pay_len = m->m_pkthdr.len;
if (fw_asyreq(fwe->fd.fc, -1, xfer) != 0) {
/* error */
if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
/* XXX set error code */
fwe_output_callback(xfer);
} else {
if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1);
i++;
}
}
#if 0
if (i > 1)
printf("%d queued\n", i);
#endif
if (i > 0)
xferq->start(fwe->fd.fc);
}
开发者ID:2trill2spill,项目名称:freebsd,代码行数:60,代码来源:if_fwe.c
示例6: fwe_as_output
/* Async. stream output */
static void
fwe_as_output(struct fwe_softc *fwe, struct ifnet *ifp)
{
struct mbuf *m;
struct fw_xfer *xfer;
struct fw_xferq *xferq;
struct fw_pkt *fp;
int i = 0;
xfer = NULL;
xferq = fwe->fd.fc->atq;
while (xferq->queued < xferq->maxq) {
IF_DEQUEUE(&ifp->if_snd, m);
if (m == NULL)
break;
xfer = fw_xfer_alloc();
if (xfer == NULL) {
return;
}
#if __FreeBSD_version >= 500000
BPF_MTAP(ifp, m);
#else
if (ifp->if_bpf != NULL)
bpf_mtap(ifp, m);
#endif
xfer->send.off = 0;
xfer->spd = 2;
xfer->fc = fwe->fd.fc;
xfer->retry_req = fw_asybusy;
xfer->sc = (caddr_t)fwe;
xfer->act.hand = fwe_output_callback;
/* keep ip packet alignment for alpha */
M_PREPEND(m, ALIGN_PAD, M_DONTWAIT);
fp = (struct fw_pkt *)&xfer->dst; /* XXX */
xfer->dst = *((int32_t *)&fwe->pkt_hdr);
fp->mode.stream.len = htons(m->m_pkthdr.len);
xfer->send.buf = (caddr_t) fp;
xfer->mbuf = m;
xfer->send.len = m->m_pkthdr.len + HDR_LEN;
i++;
if (fw_asyreq(xfer->fc, -1, xfer) != 0) {
/* error */
ifp->if_oerrors ++;
/* XXX set error code */
fwe_output_callback(xfer);
} else {
ifp->if_opackets ++;
}
}
#if 0
if (i > 1)
printf("%d queued\n", i);
#endif
if (xfer != NULL)
xferq->start(xfer->fc);
}
开发者ID:MarginC,项目名称:kame,代码行数:60,代码来源:if_fwe.c
示例7: ether_frameout
/*
* Ethernet output routine.
* Encapsulate a packet of type family for the local net.
* Use trailer local net encapsulation if enough data in first
* packet leaves a multiple of 512 bytes of data in remainder.
*/
int
ether_frameout(
struct ifnet *ifp,
struct mbuf **m,
const struct sockaddr *ndest,
const char *edst,
const char *ether_type)
{
struct ether_header *eh;
int hlen; /* link layer header length */
hlen = ETHER_HDR_LEN;
/*
* If a simplex interface, and the packet is being sent to our
* Ethernet address or a broadcast address, loopback a copy.
* XXX To make a simplex device behave exactly like a duplex
* device, we should copy in the case of sending to our own
* ethernet address (thus letting the original actually appear
* on the wire). However, we don't do that here for security
* reasons and compatibility with the original behavior.
*/
if ((ifp->if_flags & IFF_SIMPLEX) &&
((*m)->m_flags & M_LOOP)) {
if (lo_ifp) {
if ((*m)->m_flags & M_BCAST) {
struct mbuf *n = m_copy(*m, 0, (int)M_COPYALL);
if (n != NULL)
dlil_output(lo_ifp, ndest->sa_family, n, NULL, ndest, 0);
}
else {
if (_ether_cmp(edst, ifnet_lladdr(ifp)) == 0) {
dlil_output(lo_ifp, ndest->sa_family, *m, NULL, ndest, 0);
return EJUSTRETURN;
}
}
}
}
/*
* Add local net header. If no space in first mbuf,
* allocate another.
*/
M_PREPEND(*m, sizeof (struct ether_header), M_DONTWAIT);
if (*m == 0) {
return (EJUSTRETURN);
}
eh = mtod(*m, struct ether_header *);
(void)memcpy(&eh->ether_type, ether_type,
sizeof(eh->ether_type));
(void)memcpy(eh->ether_dhost, edst, ETHER_ADDR_LEN);
ifnet_lladdr_copy_bytes(ifp, eh->ether_shost, ETHER_ADDR_LEN);
return 0;
}
开发者ID:MACasuba,项目名称:MACasuba-Utils-git,代码行数:63,代码来源:ether_if_module.c
示例8: svc_vc_backchannel_reply
static bool_t
svc_vc_backchannel_reply(SVCXPRT *xprt, struct rpc_msg *msg,
struct sockaddr *addr, struct mbuf *m, uint32_t *seq)
{
struct ct_data *ct;
XDR xdrs;
struct mbuf *mrep;
bool_t stat = TRUE;
int error;
/*
* Leave space for record mark.
*/
mrep = m_gethdr(M_WAITOK, MT_DATA);
mrep->m_data += sizeof(uint32_t);
xdrmbuf_create(&xdrs, mrep, XDR_ENCODE);
if (msg->rm_reply.rp_stat == MSG_ACCEPTED &&
msg->rm_reply.rp_acpt.ar_stat == SUCCESS) {
if (!xdr_replymsg(&xdrs, msg))
stat = FALSE;
else
xdrmbuf_append(&xdrs, m);
} else {
stat = xdr_replymsg(&xdrs, msg);
}
if (stat) {
m_fixhdr(mrep);
/*
* Prepend a record marker containing the reply length.
*/
M_PREPEND(mrep, sizeof(uint32_t), M_WAITOK);
*mtod(mrep, uint32_t *) =
htonl(0x80000000 | (mrep->m_pkthdr.len
- sizeof(uint32_t)));
sx_xlock(&xprt->xp_lock);
ct = (struct ct_data *)xprt->xp_p2;
if (ct != NULL)
error = sosend(ct->ct_socket, NULL, NULL, mrep, NULL,
0, curthread);
else
error = EPIPE;
sx_xunlock(&xprt->xp_lock);
if (!error) {
stat = TRUE;
}
} else {
m_freem(mrep);
}
XDR_DESTROY(&xdrs);
return (stat);
}
开发者ID:hmatyschok,项目名称:MeshBSD,代码行数:57,代码来源:svc_vc.c
示例9: ether_addheader
static inline int
ether_addheader(struct mbuf **m, struct ifnet *ifp, u_int16_t etype,
u_char *esrc, u_char *edst)
{
struct ether_header *eh;
#if NVLAN > 0
if ((*m)->m_flags & M_VLANTAG) {
struct ifvlan *ifv = ifp->if_softc;
struct ifnet *p = ifv->ifv_p;
/* should we use the tx tagging hw offload at all? */
if ((p->if_capabilities & IFCAP_VLAN_HWTAGGING) &&
(ifv->ifv_type == ETHERTYPE_VLAN)) {
(*m)->m_pkthdr.ether_vtag = ifv->ifv_tag +
((*m)->m_pkthdr.pf.prio << EVL_PRIO_BITS);
/* don't return, need to add regular ethernet header */
} else {
struct ether_vlan_header *evh;
M_PREPEND(*m, sizeof(*evh), M_DONTWAIT);
if (*m == NULL)
return (-1);
evh = mtod(*m, struct ether_vlan_header *);
memcpy(evh->evl_dhost, edst, sizeof(evh->evl_dhost));
memcpy(evh->evl_shost, esrc, sizeof(evh->evl_shost));
evh->evl_proto = etype;
evh->evl_encap_proto = htons(ifv->ifv_type);
evh->evl_tag = htons(ifv->ifv_tag +
((*m)->m_pkthdr.pf.prio << EVL_PRIO_BITS));
(*m)->m_flags &= ~M_VLANTAG;
return (0);
}
}
#endif /* NVLAN > 0 */
M_PREPEND(*m, ETHER_HDR_LEN, M_DONTWAIT);
if (*m == NULL)
return (-1);
eh = mtod(*m, struct ether_header *);
eh->ether_type = etype;
memcpy(eh->ether_dhost, edst, sizeof(eh->ether_dhost));
memcpy(eh->ether_shost, esrc, sizeof(eh->ether_shost));
return (0);
}
开发者ID:bradla,项目名称:OpenBSD-Hammer2,代码行数:44,代码来源:if_ethersubr.c
示例10: svc_vc_reply
static bool_t
svc_vc_reply(SVCXPRT *xprt, struct rpc_msg *msg,
struct sockaddr *addr, struct mbuf *m, uint32_t *seq)
{
XDR xdrs;
struct mbuf *mrep;
bool_t stat = TRUE;
int error, len;
/*
* Leave space for record mark.
*/
mrep = m_gethdr(M_WAITOK, MT_DATA);
mrep->m_data += sizeof(uint32_t);
xdrmbuf_create(&xdrs, mrep, XDR_ENCODE);
if (msg->rm_reply.rp_stat == MSG_ACCEPTED &&
msg->rm_reply.rp_acpt.ar_stat == SUCCESS) {
if (!xdr_replymsg(&xdrs, msg))
stat = FALSE;
else
xdrmbuf_append(&xdrs, m);
} else {
stat = xdr_replymsg(&xdrs, msg);
}
if (stat) {
m_fixhdr(mrep);
/*
* Prepend a record marker containing the reply length.
*/
M_PREPEND(mrep, sizeof(uint32_t), M_WAITOK);
len = mrep->m_pkthdr.len;
*mtod(mrep, uint32_t *) =
htonl(0x80000000 | (len - sizeof(uint32_t)));
atomic_add_32(&xprt->xp_snd_cnt, len);
error = sosend(xprt->xp_socket, NULL, NULL, mrep, NULL,
0, curthread);
if (!error) {
atomic_add_rel_32(&xprt->xp_snt_cnt, len);
if (seq)
*seq = xprt->xp_snd_cnt;
stat = TRUE;
} else
atomic_subtract_32(&xprt->xp_snd_cnt, len);
} else {
m_freem(mrep);
}
XDR_DESTROY(&xdrs);
return (stat);
}
开发者ID:hmatyschok,项目名称:MeshBSD,代码行数:55,代码来源:svc_vc.c
示例11: put_uint32
static void
put_uint32(struct mbuf **mp, uint32_t v)
{
struct mbuf *m = *mp;
uint32_t n;
M_PREPEND(m, sizeof(uint32_t), M_WAITOK);
n = htonl(v);
bcopy(&n, mtod(m, uint32_t *), sizeof(uint32_t));
*mp = m;
}
开发者ID:JabirTech,项目名称:Source,代码行数:11,代码来源:rpcsec_gss_prot.c
示例12: M_PREPEND
M_BLK_ID endEtherAddressForm
(
M_BLK_ID pMblk, /* pointer to packet mBlk */
M_BLK_ID pSrcAddr, /* pointer to source address */
M_BLK_ID pDstAddr, /* pointer to destination address */
BOOL bcastFlag /* use link-level broadcast? */
)
{
USHORT *pDst;
USHORT *pSrc;
M_PREPEND(pMblk, SIZEOF_ETHERHEADER, M_DONTWAIT);
/*
* This routine has been optimized somewhat in order to avoid
* the use of bcopy(). On some architectures, a bcopy() could
* result in a call into (allegedly) optimized architecture-
* specific routines. This may be fine for copying large chunks
* of data, but we're only copying 6 bytes. It's simpler just
* to open code some 16-bit assignments. The compiler would be
* hard-pressed to produce sub-optimal code for this, and it
* avoids at least one function call (possibly several).
*/
if (pMblk != NULL)
{
pDst = (USHORT *)pMblk->m_data;
if (bcastFlag)
{
pDst[0] = 0xFFFF;
pDst[1] = 0xFFFF;
pDst[2] = 0xFFFF;
}
else
{
pSrc = (USHORT *)pDstAddr->m_data;
pDst[0] = pSrc[0];
pDst[1] = pSrc[1];
pDst[2] = pSrc[2];
}
/* Advance to the source address field, fill it in. */
pDst += 3;
pSrc = (USHORT *)pSrcAddr->m_data;
pDst[0] = pSrc[0];
pDst[1] = pSrc[1];
pDst[2] = pSrc[2];
((struct ether_header *)pMblk->m_data)->ether_type =
pDstAddr->mBlkHdr.reserved;
}
return(pMblk);
}
开发者ID:ariavie,项目名称:bcm,代码行数:53,代码来源:endLib.c
示例13: mveth_tx
int
mveth_tx(struct mv64340_private *mp, char *data, int len, int nbufs)
{
int rval = -1,l;
char *p;
struct mbuf *m;
char *emsg = 0;
rtems_bsdnet_semaphore_obtain();
MGETHDR(m, M_WAIT, MT_DATA);
if ( !m ) {
emsg="Unable to allocate header\n";
goto bail;
}
MCLGET(m, M_WAIT);
if ( !(m->m_flags & M_EXT) ) {
m_freem(m);
emsg="Unable to allocate cluster\n";
goto bail;
}
p = mtod(m, char *);
l = 0;
switch (nbufs) {
case 3:
default:
emsg="nbufs arg must be 1..3\n";
goto bail;
case 1:
l += sizeof(BcHeader);
memcpy(p, &BcHeader, sizeof(BcHeader));
p += sizeof(BcHeader);
case 2:
memcpy(p,data,len);
l += len;
m->m_len = m->m_pkthdr.len = l;
if ( 2 == nbufs ) {
M_PREPEND(m, sizeof (BcHeader), M_WAIT);
if (!m) {
emsg = "Unable to prepend\n";
goto bail;
}
p = mtod(m, char*);
memcpy(p,&BcHeader,sizeof(BcHeader));
l += sizeof(BcHeader);
}
break;
}
开发者ID:0871087123,项目名称:rtems,代码行数:49,代码来源:testing.c
示例14: netdump_udp_output
/*
* Unreliable transmission of an mbuf chain to the netdump server
* Note: can't handle fragmentation; fails if the packet is larger than
* nd_ifp->if_mtu after adding the UDP/IP headers
*
* Parameters:
* m mbuf chain
*
* Returns:
* int see errno.h, 0 for success
*/
static int
netdump_udp_output(struct mbuf *m)
{
struct udpiphdr *ui;
struct ip *ip;
MPASS(nd_ifp != NULL);
M_PREPEND(m, sizeof(struct udpiphdr), M_NOWAIT);
if (m == NULL) {
printf("%s: out of mbufs\n", __func__);
return (ENOBUFS);
}
if (m->m_pkthdr.len > nd_ifp->if_mtu) {
printf("netdump_udp_output: Packet is too big: %d > MTU %u\n",
m->m_pkthdr.len, nd_ifp->if_mtu);
m_freem(m);
return (ENOBUFS);
}
ui = mtod(m, struct udpiphdr *);
bzero(ui->ui_x1, sizeof(ui->ui_x1));
ui->ui_pr = IPPROTO_UDP;
ui->ui_len = htons(m->m_pkthdr.len - sizeof(struct ip));
ui->ui_ulen = ui->ui_len;
ui->ui_src = nd_client;
ui->ui_dst = nd_server;
/* Use this src port so that the server can connect() the socket */
ui->ui_sport = htons(NETDUMP_ACKPORT);
ui->ui_dport = htons(nd_server_port);
ui->ui_sum = 0;
if ((ui->ui_sum = in_cksum(m, m->m_pkthdr.len)) == 0)
ui->ui_sum = 0xffff;
ip = mtod(m, struct ip *);
ip->ip_v = IPVERSION;
ip->ip_hl = sizeof(struct ip) >> 2;
ip->ip_tos = 0;
ip->ip_len = htons(m->m_pkthdr.len);
ip->ip_id = 0;
ip->ip_off = htons(IP_DF);
ip->ip_ttl = 255;
ip->ip_sum = 0;
ip->ip_sum = in_cksum(m, sizeof(struct ip));
return (netdump_ether_output(m, nd_ifp, nd_gw_mac, ETHERTYPE_IP));
}
开发者ID:derekmarcotte,项目名称:freebsd,代码行数:59,代码来源:netdump_client.c
示例15: wep_encap
/*
* Add privacy headers appropriate for the specified key.
*/
static int
wep_encap(struct ieee80211_key *k, struct mbuf *m, uint8_t keyid)
{
struct wep_ctx *ctx = k->wk_private;
struct ieee80211com *ic = ctx->wc_ic;
uint32_t iv;
uint8_t *ivp;
int hdrlen;
hdrlen = ieee80211_hdrspace(ic, mtod(m, void *));
/*
* Copy down 802.11 header and add the IV + KeyID.
*/
M_PREPEND(m, wep.ic_header, MB_DONTWAIT);
if (m == NULL)
return 0;
ivp = mtod(m, uint8_t *);
ovbcopy(ivp + wep.ic_header, ivp, hdrlen);
ivp += hdrlen;
/*
* XXX
* IV must not duplicate during the lifetime of the key.
* But no mechanism to renew keys is defined in IEEE 802.11
* for WEP. And the IV may be duplicated at other stations
* because the session key itself is shared. So we use a
* pseudo random IV for now, though it is not the right way.
*
* NB: Rather than use a strictly random IV we select a
* random one to start and then increment the value for
* each frame. This is an explicit tradeoff between
* overhead and security. Given the basic insecurity of
* WEP this seems worthwhile.
*/
/*
* Skip 'bad' IVs from Fluhrer/Mantin/Shamir:
* (B, 255, N) with 3 <= B < 16 and 0 <= N <= 255
*/
iv = ctx->wc_iv;
if ((iv & 0xff00) == 0xff00) {
int B = (iv & 0xff0000) >> 16;
if (3 <= B && B < 16)
iv += 0x0100;
}
开发者ID:juanfra684,项目名称:DragonFlyBSD,代码行数:49,代码来源:ieee80211_crypto_wep.c
示例16: in_gif_output
int
in_gif_output(struct ifnet *ifp, struct mbuf *m, int proto, uint8_t ecn)
{
GIF_RLOCK_TRACKER;
struct gif_softc *sc = ifp->if_softc;
struct ip *ip;
int len;
/* prepend new IP header */
len = sizeof(struct ip);
#ifndef __NO_STRICT_ALIGNMENT
if (proto == IPPROTO_ETHERIP)
len += ETHERIP_ALIGN;
#endif
M_PREPEND(m, len, M_NOWAIT);
if (m == NULL)
return (ENOBUFS);
#ifndef __NO_STRICT_ALIGNMENT
if (proto == IPPROTO_ETHERIP) {
len = mtod(m, vm_offset_t) & 3;
KASSERT(len == 0 || len == ETHERIP_ALIGN,
("in_gif_output: unexpected misalignment"));
m->m_data += len;
m->m_len -= ETHERIP_ALIGN;
}
#endif
ip = mtod(m, struct ip *);
GIF_RLOCK(sc);
if (sc->gif_family != AF_INET) {
m_freem(m);
GIF_RUNLOCK(sc);
return (ENETDOWN);
}
bcopy(sc->gif_iphdr, ip, sizeof(struct ip));
GIF_RUNLOCK(sc);
ip->ip_p = proto;
/* version will be set in ip_output() */
ip->ip_ttl = V_ip_gif_ttl;
ip->ip_len = htons(m->m_pkthdr.len);
ip->ip_tos = ecn;
return (ip_output(m, NULL, NULL, 0, NULL, NULL));
}
开发者ID:coyizumi,项目名称:cs111,代码行数:44,代码来源:in_gif.c
示例17: natm_usr_send
static int
natm_usr_send(struct socket *so, int flags, struct mbuf *m, struct mbuf *nam,
struct mbuf *control)
{
struct natmpcb *npcb;
struct atm_pseudohdr *aph;
int error = 0;
int s = SPLSOFTNET();
int proto = so->so_proto->pr_protocol;
npcb = (struct natmpcb *) so->so_pcb;
if (npcb == NULL) {
error = EINVAL;
goto out;
}
if (control && control->m_len) {
m_freem(control);
m_freem(m);
error = EINVAL;
goto out;
}
/*
* send the data. we must put an atm_pseudohdr on first
*/
M_PREPEND(m, sizeof(*aph), M_WAITOK);
if (m == NULL) {
error = ENOBUFS;
goto out;
}
aph = mtod(m, struct atm_pseudohdr *);
ATM_PH_VPI(aph) = npcb->npcb_vpi;
ATM_PH_SETVCI(aph, npcb->npcb_vci);
ATM_PH_FLAGS(aph) = (proto == PROTO_NATMAAL5) ? ATM_PH_AAL5 : 0;
error = atm_output(npcb->npcb_ifp, m, NULL, NULL);
out:
splx(s);
return (error);
}
开发者ID:UnitedMarsupials,项目名称:kame,代码行数:43,代码来源:natm.c
示例18: ddp_output
int
ddp_output( struct mbuf *m, struct socket *so)
{
struct ddpehdr *deh;
struct ddpcb *ddp = sotoddpcb( so );
#ifdef MAC
mac_create_mbuf_from_socket(so, m);
#endif
M_PREPEND( m, sizeof( struct ddpehdr ), M_TRYWAIT );
deh = mtod( m, struct ddpehdr *);
deh->deh_pad = 0;
deh->deh_hops = 0;
deh->deh_len = m->m_pkthdr.len;
deh->deh_dnet = ddp->ddp_fsat.sat_addr.s_net;
deh->deh_dnode = ddp->ddp_fsat.sat_addr.s_node;
deh->deh_dport = ddp->ddp_fsat.sat_port;
deh->deh_snet = ddp->ddp_lsat.sat_addr.s_net;
deh->deh_snode = ddp->ddp_lsat.sat_addr.s_node;
deh->deh_sport = ddp->ddp_lsat.sat_port;
/*
* The checksum calculation is done after all of the other bytes have
* been filled in.
*/
if ( ddp_cksum ) {
deh->deh_sum = at_cksum( m, sizeof( int ));
} else {
deh->deh_sum = 0;
}
deh->deh_bytes = htonl( deh->deh_bytes );
#ifdef NETATALK_DEBUG
printf ("ddp_output: from %d.%d:%d to %d.%d:%d\n",
ntohs(deh->deh_snet), deh->deh_snode, deh->deh_sport,
ntohs(deh->deh_dnet), deh->deh_dnode, deh->deh_dport);
#endif
return( ddp_route( m, &ddp->ddp_route ));
}
开发者ID:MarginC,项目名称:kame,代码行数:43,代码来源:ddp_output.c
示例19: ieee1394_fragment
struct mbuf *
ieee1394_fragment(struct ifnet *ifp, struct mbuf *m0, int maxsize,
uint16_t etype)
{
struct ieee1394com *ic = (struct ieee1394com *)ifp;
int totlen, fraglen, off;
struct mbuf *m, **mp;
struct ieee1394_fraghdr *ifh;
struct ieee1394_unfraghdr *iuh;
totlen = m0->m_pkthdr.len;
if (totlen + sizeof(struct ieee1394_unfraghdr) <= maxsize) {
M_PREPEND(m0, sizeof(struct ieee1394_unfraghdr), M_DONTWAIT);
if (m0 == NULL)
goto bad;
iuh = mtod(m0, struct ieee1394_unfraghdr *);
iuh->iuh_ft = 0;
iuh->iuh_etype = etype;
return m0;
}
开发者ID:ryo,项目名称:netbsd-src,代码行数:20,代码来源:if_ieee1394subr.c
示例20: ddp_output
int
ddp_output(struct mbuf *m, ...)
{
struct ddpcb *ddp;
struct ddpehdr *deh;
va_list ap;
va_start(ap, m);
ddp = va_arg(ap, struct ddpcb *);
va_end(ap);
M_PREPEND( m, sizeof( struct ddpehdr ), M_DONTWAIT );
if (!m)
return (ENOBUFS);
deh = mtod( m, struct ddpehdr *);
deh->deh_pad = 0;
deh->deh_hops = 0;
deh->deh_len = m->m_pkthdr.len;
deh->deh_dnet = ddp->ddp_fsat.sat_addr.s_net;
deh->deh_dnode = ddp->ddp_fsat.sat_addr.s_node;
deh->deh_dport = ddp->ddp_fsat.sat_port;
deh->deh_snet = ddp->ddp_lsat.sat_addr.s_net;
deh->deh_snode = ddp->ddp_lsat.sat_addr.s_node;
deh->deh_sport = ddp->ddp_lsat.sat_port;
/*
* The checksum calculation is done after all of the other bytes have
* been filled in.
*/
if ( ddp_cksum ) {
deh->deh_sum = at_cksum( m, sizeof( int ));
} else {
deh->deh_sum = 0;
}
deh->deh_bytes = htonl( deh->deh_bytes );
return( ddp_route( m, &ddp->ddp_route ));
}
开发者ID:repos-holder,项目名称:openbsd-patches,代码行数:41,代码来源:ddp_output.c
注:本文中的M_PREPEND函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论