VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/darwin/VBoxNetSend.h@ 68283

Last change on this file since 68283 was 63515, checked in by vboxsync, 8 years ago

HostDrivers: warnings (clang)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.8 KB
Line 
1/* $Id: VBoxNetSend.h 63515 2016-08-15 23:19:14Z vboxsync $ */
2/** @file
3 * A place to share code and definitions between VBoxNetAdp and VBoxNetFlt host drivers.
4 */
5
6/*
7 * Copyright (C) 2014-2016 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18/** @todo move this to src/VBox/HostDrivers/darwin as a .cpp file. */
19#ifndef ___VBox_VBoxNetSend_h
20#define ___VBox_VBoxNetSend_h
21
22#if defined(RT_OS_DARWIN)
23
24# include <iprt/err.h>
25# include <iprt/assert.h>
26# include <iprt/string.h>
27
28# include <sys/socket.h>
29# include <net/kpi_interface.h>
30RT_C_DECLS_BEGIN /* Buggy 10.4 headers, fixed in 10.5. */
31# include <sys/kpi_mbuf.h>
32RT_C_DECLS_END
33# include <net/if.h>
34
35RT_C_DECLS_BEGIN
36
37# if defined(IN_RING0)
38
39/**
40 * Constructs and submits a dummy packet to ifnet_input().
41 *
42 * This is a workaround for "stuck dock icon" issue. When the first packet goes
43 * through the interface DLIL grabs a reference to the thread that submits the
44 * packet and holds it until the interface is destroyed. By submitting this
45 * dummy we make DLIL grab the thread of a non-GUI process.
46 *
47 * Most of this function was copied from vboxNetFltDarwinMBufFromSG().
48 *
49 * @returns VBox status code.
50 * @param pIfNet The interface that will hold the reference to the calling
51 * thread. We submit dummy as if it was coming from this interface.
52 */
53DECLINLINE(int) VBoxNetSendDummy(ifnet_t pIfNet)
54{
55 int rc = VINF_SUCCESS;
56
57 size_t cbTotal = 50; /* No Ethernet header */
58 mbuf_how_t How = MBUF_WAITOK;
59 mbuf_t pPkt = NULL;
60 errno_t err = mbuf_allocpacket(How, cbTotal, NULL, &pPkt);
61 if (!err)
62 {
63 /* Skip zero sized memory buffers (paranoia). */
64 mbuf_t pCur = pPkt;
65 while (pCur && !mbuf_maxlen(pCur))
66 pCur = mbuf_next(pCur);
67 Assert(pCur);
68
69 /* Set the required packet header attributes. */
70 mbuf_pkthdr_setlen(pPkt, cbTotal);
71 mbuf_pkthdr_setheader(pPkt, mbuf_data(pCur));
72
73 mbuf_setlen(pCur, cbTotal);
74 memset(mbuf_data(pCur), 0, cbTotal);
75
76 mbuf_pkthdr_setrcvif(pPkt, pIfNet); /* will crash without this. */
77
78 err = ifnet_input(pIfNet, pPkt, NULL);
79 if (err)
80 {
81 rc = RTErrConvertFromErrno(err);
82 mbuf_freem(pPkt);
83 }
84 }
85 else
86 rc = RTErrConvertFromErrno(err);
87
88 return rc;
89}
90
91# endif /* IN_RING0 */
92
93RT_C_DECLS_END
94
95#endif /* RT_OS_DARWIN */
96
97#endif /* !___VBox_VBoxNetSend_h */
98
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette