- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的代码当前正在使用 INADDR_ANY,我正在测试是否能够通过 Ubuntu 路由器[使用 IPTables] 将数据包从 VM 客户端发送到我的主机。
我能够从 Linux 路由器后面的客户端和主机上的客户端 ping 通主机,但是当我发送 UDP 数据包时,它永远不会到达主机。
问题要么出在这两个地方之一,我为路由设置的 IPTable 无法正常工作,要么出在我绑定(bind)到 INADDR_ANY 的服务器代码中,INADDR_ANY 不包括 VMware 接口(interface)。
我查了一下,但没有找到具体信息。据我了解,没有理由它不起作用。
扩展问题:
根据this如果我运行这些命令,我将能够复制相应的 NAT,但是是否显示公共(public) ip 位于此处和私有(private) ip 位于此处是指目的IP还是公私接口(interface)IP?即 eth0 和 eth1 的 IP 地址?
已解决
我在错误的 eth 卡上设置了 iptable 规则!因此,请确保您在正确的 eth 上应用命令。
最佳答案
以下代码是 UDP 连接的客户端。
这适用于 ubuntu linux、VM、Windows XP。
注意:左边距的代码语句(通常)用于调试
注意:系统函数“sendto()”和“recvfrom()”是 UDP 通信的正确调用。
注意:函数大小写等取决于本地使用的编码风格。
注意:与任何“现实生活”项目一样,大部分代码都是为了处理错误。
您可能对 create_UDP_socket()
函数最感兴趣。
/* *************** Included files************************************* */
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h> // for system() and itoa() utilities
#include <stdarg.h> // for va_list(), etc
#include <string.h> // string handling utilities
#include <semaphore.h> // semaphores handling utilities
#include <fcntl.h> // symbolic definitions for flags bits
#include <sys/types.h> // contains definitions of data types used in system calls
#include <sys/socket.h>// type definitions (I.E. struct sockaddr_in)
#include <sys/stat.h> // symbolic definitions for permission bits and open()
#include <sys/ipc.h> // ipc interface utilities
#include <sys/shm.h> // shared memory utilities
#include <arpa/inet.h> // defines INADDR_ANY, etc
#include <errno.h> // for accessing errno and related functions
#include <stdbool.h> // define true, false, bool
#include <time.h>
// contains common data type definitions
#include "localTypes.h"
// contains data definitions for ON and OFF, enum enumReturnStatus
#include "Defines.h"
// contains prototypes for writing to Log file
#include "CommonWriteLog.h"
// contains prototypes, and data type definitions
#include "CommonConfiguration.h"
//contains prototypes for globally visible functions in this file
#include "Common_UDP_Utilities.h"
/* *************** Global variables *********************************** */
/* *************** File Static Variables ****************************** */
/* *************** Code *********************************************** */
enum enumReturnStatus create_UDP_socket( INT32 taskSelector, INT32 *pUDPsocket_FD )
{
enum enumReturnStatus returnStatus = eRS_Success; // indicate success
INT32 LocalPort;
INT32 socket_FD;
struct sockaddr_in *pLocal_sockaddr;
char *txtAddress;
if( is_taskSelector_Valid( taskSelector ) )
{ // then parameters valid
socket_FD = get_UDPsocket_FD( eTask_Retrieve_GPS );
if( 0 >= socket_FD )
{ // then socket not yet opened
pLocal_sockaddr = get_pUDPsocket_sockaddr( taskSelector );
txtAddress = inet_ntoa((*pLocal_sockaddr).sin_addr);
fprintf(stdout, "OPENING SOCKET on socket addresss: %s \n", txtAddress );
if( NULL != pLocal_sockaddr )
{ // then, sockaddr configured
LocalPort = get_UDPsocket_LocalPort( taskSelector );
fprintf(stdout, "OPENING SOCKET on PORT: %d \n", LocalPort );
if( 0 <= LocalPort )
{ // then port configured
socket_FD = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
if( -1 != socket_FD )
{ // then, socket creation successful
int TurnOn = 1;
returnStatus = setsockopt( socket_FD, SOL_SOCKET, SO_REUSEADDR, &TurnOn, sizeof( TurnOn ) );
if ( eRS_Success == returnStatus )
{ // then setsockopt() successful
bzero((char *) pLocal_sockaddr, sizeof(struct sockaddr_in) );
pLocal_sockaddr->sin_family = AF_INET;
pLocal_sockaddr->sin_port = htons( LocalPort );
pLocal_sockaddr->sin_addr.s_addr = htonl(INADDR_ANY); // todo: change to specific GPS IP address
CommonWriteLog( eLL_Info,
"INFO:File:%s: Line:%d:\n\t%s 0X%08X %d\n\n",
__FILE__, __LINE__,
"addr.sin_port =",
pLocal_sockaddr->sin_port,
pLocal_sockaddr->sin_port );
returnStatus = bind( socket_FD, (struct sockaddr *)pLocal_sockaddr, sizeof(struct sockaddr) );
if( eRS_Success == returnStatus )
{ // then bind successful
returnStatus = set_UDPsocket_FD( taskSelector, socket_FD );
if( eRS_Success != returnStatus )
{ // then set_UDPsocket_FD failed
CommonWriteLog( eLL_Error,
get_pFormatString( eFormat_EFFL_string ),
__FILE__, __LINE__,
"Function:set_UDPsocket_FD() failed" );
returnStatus = eRS_UDP_Create_Failure; // indicate error occurred
close( socket_FD );
socket_FD = -1;
}
// set callers data
*pUDPsocket_FD = socket_FD;
}
else
{ // else, bind() failed
CommonWriteLog( eLL_Error,
get_pFormatString( eFormat_EFFL_taskSelector_dataIndex_string_string ),
__FILE__, __LINE__,
taskSelector, 0,
"LibFunc:bind() failed",
strerror(errno) );
} // endif( bind )
}
else
{ // else setsockopt() failed
CommonWriteLog( eLL_Error,
get_pFormatString( eFormat_EFFL_taskSelector_dataIndex_string_string ),
__FILE__, __LINE__,
taskSelector, 0,
"LibFunc:setsockopt( SO_REUSEADDR ) failed",
strerror(errno) );
} // endif( SO_REUSEADDR )
}
else
{ // else failed to create socket
fprintf(stdout, "FAILED TO OPEN SOCKET: \n" );
fflush(stdout);
system("sync;sync;");
exit(EXIT_FAILURE);
CommonWriteLog( eLL_Error,
get_pFormatString( eFormat_EFFL_taskSelector_dataIndex_string_string ),
__FILE__, __LINE__,
taskSelector, 0,
"LibFunc:socket() failed",
strerror(errno) );
returnStatus = eRS_SystemCall_Failure; // indicate error occured
} // endif( socket )
}
else
{ // else port not configured
CommonWriteLog( eLL_Error,
get_pFormatString( eFormat_EFFL_taskSelector_dataIndex_string ),
__FILE__, __LINE__,
taskSelector, 0,
"port not configured" );
returnStatus = eRS_Configuration_Failure; // indicate error occurred
}
}
else
{ // else get pUDP sockaddr failed
CommonWriteLog( eLL_Error,
get_pFormatString( eFormat_EFFL_taskSelector_dataIndex_string ),
__FILE__, __LINE__,
taskSelector, 0,
"Function:get_pUDPsocket_sockaddr() failed" );
returnStatus = eRS_UDP_Create_Failure; // indicate error occurred
} // endif( get_pUDPsocket_sockaddr() successful )
} // endif( socket already open )
}
else
{ // else, bad parameters
returnStatus = eRS_UDP_Create_Failure;
CommonWriteLog( eLL_Error,
get_pFormatString( eFormat_EFFL_digit_string ),
__FILE__, __LINE__,
taskSelector,
"Parameter:taskSelector out of range" );
}
return( returnStatus );
} // end create_UDP_socket()
enum enumReturnStatus write_UDP_socket( INT32 Socket_FD, char *pSocket_OutBuffer, INT32 Size, struct sockaddr *pTo_sockaddr, INT32 *pWriteCount )
{
enum enumReturnStatus returnStatus = eRS_Success; // indicate success
INT32 flags = 0;
INT32 sendtoStatus;
// do not call CommonWriteLog() to help avoid extranious 'recursion' messages in logs
// and to avoid recrusive operation
sendtoStatus =
sendto( Socket_FD, pSocket_OutBuffer, Size, flags,pTo_sockaddr, sizeof(struct sockaddr) );
if( 0 <= sendtoStatus )
{ // then, sendto() successful
*pWriteCount = sendtoStatus;
if( sendtoStatus != Size )
{ // then not all char sent
CommonWriteLog( eLL_Error,
"ERROR:File:%s: Line:%d:\n\t%s:num2Send:%d, numSent:%d\n\n",
__FILE__, __LINE__,
"LibFunc:sendto() failed",
Size, sendtoStatus );
returnStatus = eRS_UDP_Write_Failure; // indicate error occurred
}
}
else
{
CommonWriteLog( eLL_Error,
get_pFormatString( eFormat_EFFL_string_string ),
__FILE__, __LINE__,
"LibFunc:sendto() failed",
strerror(errno) );
returnStatus = eRS_SystemCall_Failure; // indicate error occurred
*pWriteCount = 0;
}
return( returnStatus );
} // end write_UDP_socket()
enum enumReturnStatus read_UDP_socket( INT32 Socket_FD, char *pSocket_InBuffer, INT32 Size, INT32 *pReadCount )
{
enum enumReturnStatus returnStatus = eRS_Success;
INT32 readStatus = 0; // result of call to recvfrom()
INT32 flags = 0; // option parameter for call to recvfrom()
struct sockaddr_in from_sockaddr;
UINT32 slen = 0; // sizeof struct sockaddr_in
memset( &from_sockaddr, 0x00, sizeof(from_sockaddr) );
slen = sizeof( struct sockaddr_in );
readStatus = recvfrom( Socket_FD, pSocket_InBuffer,Size, flags,(struct sockaddr*)&from_sockaddr, &slen ); // filled during call
if( 0 > readStatus )
{ // then, an I/O error occurred
CommonWriteLog( eLL_Error,
get_pFormatString( eFormat_EFFL_string_string ),
__FILE__, __LINE__,
"LibFunc:recvfrom() failed",
strerror(errno) );
*pReadCount = 0;
returnStatus = eRS_SystemCall_Failure; // indicate error occurred
}
else
{ //else 0 or more bytes read
// update callers' info
*pReadCount = readStatus;
}
return( returnStatus );
} // end read_UDP_socket()
/* ******************************************************************** **
** End of source file: Common_UDP_Utilities.c
** ******************************************************************** */
关于c - INADDR_ANY 接口(interface)是否包括 VMware Network Adapter?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28916598/
我正在使用AWS中的VM设置Elasticsearch集群。 我知道每个节点都会自动尝试加入一个在同一网络中具有相同群集名称的现有群集。 但是,我无法理解“同一网络” 是什么。 为了了解同一网络,我发
我尝试部署一个已经存在于 Kovan 网络上的合约实例,以通过 web3 和 metamask 与其交互。 首先,我将 metamask 设置为我的当前提供者,然后我部署了一个合约实例,如下所示:
停止 docker 后,它拒绝重新启动。它提示另一个名为 docker0 的网桥已经存在: level=warning msg="devmapper: Base device already exis
我正在使用“docker network create --d bridge mynet”创建一个 docker 网络。我想获取与此 docker 网络关联的网桥名称。 我知道我可以使用“-o”来提供
我的一位同事的VPN连接有问题。似乎他的操作系统重设了代理设置,并且他需要手动将其更改回。有没有办法使用Powershell设置VPN和代理? 他正在使用Windows 7,因此可以使用Powersh
我在 Azure VM 中有一个虚拟机,我想获取网络输入/网络输出指标。 在 Azure 门户中,我将诊断设置和指标设置为存储到选定的存储表中。但存储的指标与我在 Azure 门户中看到的指标之间存在
我有一个用例,我的 Docker 容器的第二个接口(interface)需要共享主机的第二个网络接口(interface)的接口(interface)。这可能使用 docker network con
我在 Azure VM 中有一个虚拟机,我想获取网络输入/网络输出指标。 在 Azure 门户中,我将诊断设置和指标设置为存储到选定的存储表中。但存储的指标与我在 Azure 门户中看到的指标之间存在
我想了解一些关于 Docker 的事情: 如何找到我的容器所在的网络? 我可以动态分离我的容器并附加到其他网络吗?怎么样? 如果我有两个容器正在运行,如何检查这两个容器是否在同一个网络?我可以 pin
我已经开发了一款使用Reaction Native和世博会的应用程序,并想在它的末尾添加一个横幅广告。当我在Android模拟器上的开发版本上运行应用程序时,应用程序的其余部分在没有应用程序的情况下运
我已经编辑了 eth0,但我犯了一个错误,我的 VPS 现在处于脱机状态,甚至无法连接到 ssh,并在故障恢复控制台显示以下消息: “网络不可达”。 配置/编辑网络的命令是什么!? Photo 最佳答
今天早上我启动了我的 GCE 实例,并且 4/6 完全无法访问。所有这些都在同一个 us-east1-d 区域中。 SSH 连接也无法正常工作,因此我使用串行控制台连接到有问题的实例之一。 当我尝试
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 5年前关闭。 Improve this qu
我正在使用 Network.Browser 4000.0.9 检索网页: import Network.Browser import Network.HTTP main = do (uri
我正在尝试更新我在 docker 容器中的 apt 存储库,但我做不到。 docker run -it --dns 8.8.8.8 --dns 8.8.4.4 debian apt-get 更新 ..
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
Axios 是否可以区分以下内容: 由于客户端没有网络连接而失败的请求发出请求的时间 - (ERR_CONNECTION_REFUSED)。 由于网络连接丢失而失败的请求之后已发出请求,但在收到响应之
Unity 已升级其网络系统,并将旧网络称为遗留网络。 那么我们如何将 RPC 调用更改为新的 Unity Networking?这种方法的等价物是什么?我们应该为它编写自己的方法吗? (发送字节数组
在机器学习工具 vowpal wabbit ( https://github.com/JohnLangford/vowpal_wabbit/ ) 中,通常训练线性估计器 y*=wx。但是,可以添加前向
我正在尝试将 Boost 用于某些 IPv6 和多播网络通信。我需要构建一个使用特定网络接口(interface)索引的 IPv6 多播套接字。 我能够在 boost/asio/ip/detail/s
我是一名优秀的程序员,十分优秀!