本文整理汇总了C++中NTOHS函数的典型用法代码示例。如果您正苦于以下问题:C++ NTOHS函数的具体用法?C++ NTOHS怎么用?C++ NTOHS使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NTOHS函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: udp_packet_handler
void udp_packet_handler(void)
{
msg_t m_recv_ip, m_send_ip, m_recv_udp, m_send_udp;
ipv6_hdr_t *ipv6_header;
udp_hdr_t *udp_header;
socket_internal_t *udp_socket = NULL;
uint16_t chksum;
while (1) {
msg_receive(&m_recv_ip);
ipv6_header = ((ipv6_hdr_t *)m_recv_ip.content.ptr);
udp_header = ((udp_hdr_t *)(m_recv_ip.content.ptr + IPV6_HDR_LEN));
chksum = ipv6_csum(ipv6_header, (uint8_t*) udp_header, NTOHS(udp_header->length), IPPROTO_UDP);
if (chksum == 0xffff) {
udp_socket = get_udp_socket(udp_header);
if (udp_socket != NULL) {
m_send_udp.content.ptr = (char *)ipv6_header;
msg_send_receive(&m_send_udp, &m_recv_udp, udp_socket->recv_pid);
}
else {
printf("Dropped UDP Message because no thread ID was found for delivery!\n");
}
}
else {
printf("Wrong checksum (%x)!\n", chksum);
}
msg_reply(&m_recv_ip, &m_send_ip);
}
}
开发者ID:Dinesh-Ramakrishnan,项目名称:RIOT,代码行数:33,代码来源:udp.c
示例2: app_notify_icmp_data
/**@brief Function for notifying application of the ICMPv6 received packet.
*
* @param[in] p_interface Pointer to external interface from which packet come.
* @param[in] p_pbuffer Pointer to packet buffer of ICMP6_PACKET_TYPE.
* @param[in] process_result Result of internal processing packet.
*
* @return NRF_SUCCESS after successful processing, error otherwise.
*/
static uint32_t app_notify_icmp_data(iot_interface_t * p_interface,
iot_pbuffer_t * p_pbuffer,
uint32_t process_result)
{
uint32_t err_code = NRF_SUCCESS;
if(m_event_handler != NULL)
{
ipv6_header_t * p_ip_header = (ipv6_header_t *)
(p_pbuffer->p_payload - ICMP6_HEADER_SIZE - IPV6_IP_HEADER_SIZE);
icmp6_header_t * p_icmp_header = (icmp6_header_t *)
(p_pbuffer->p_payload - ICMP6_HEADER_SIZE);
ICMP6_MUTEX_UNLOCK();
// Change byte order of ICMP header given to application.
p_icmp_header->checksum = NTOHS(p_icmp_header->checksum);
err_code = m_event_handler(p_interface,
p_ip_header,
p_icmp_header,
process_result,
p_pbuffer);
ICMP6_MUTEX_LOCK();
}
return err_code;
}
开发者ID:sische,项目名称:MasterThesis,代码行数:38,代码来源:icmp6.c
示例3: destiny_socket_sendto
int32_t destiny_socket_sendto(int s, const void *buf, uint32_t len, int flags,
sockaddr6_t *to, uint32_t tolen)
{
if (isUDPSocket(s) &&
(get_socket(s)->socket_values.foreign_address.sin6_port == 0)) {
uint8_t send_buffer[BUFFER_SIZE];
ipv6_hdr_t *temp_ipv6_header = ((ipv6_hdr_t *)(&send_buffer));
udp_hdr_t *current_udp_packet = ((udp_hdr_t *)(&send_buffer[IPV6_HDR_LEN]));
uint8_t *payload = &send_buffer[IPV6_HDR_LEN + UDP_HDR_LEN];
memcpy(&(temp_ipv6_header->destaddr), &to->sin6_addr, 16);
ipv6_iface_get_best_src_addr(&(temp_ipv6_header->srcaddr), &(temp_ipv6_header->destaddr));
current_udp_packet->src_port = get_free_source_port(IPPROTO_UDP);
current_udp_packet->dst_port = to->sin6_port;
current_udp_packet->checksum = 0;
memcpy(payload, buf, len);
current_udp_packet->length = HTONS(UDP_HDR_LEN + len);
temp_ipv6_header->length = UDP_HDR_LEN + len;
current_udp_packet->checksum = ~udp_csum(temp_ipv6_header,
current_udp_packet);
ipv6_sendto(&to->sin6_addr, IPPROTO_UDP,
(uint8_t *)(current_udp_packet),
NTOHS(current_udp_packet->length));
return current_udp_packet->length;
}
else {
return -1;
}
}
开发者ID:manoja328,项目名称:RIOT,代码行数:34,代码来源:socket.c
示例4: decode_vlan_n_hash
/**
* Parser + hash function for VLAN packet
*/
static inline uint32_t
decode_vlan_n_hash(struct ethhdr *ethh, uint8_t hash_split, uint8_t seed)
{
TRACE_PKTHASH_FUNC_START();
uint32_t rc = 0;
struct vlanhdr *vhdr = (struct vlanhdr *)(ethh + 1);
switch (NTOHS(vhdr->proto)) {
case ETH_P_IP:
rc = decode_ip_n_hash((struct iphdr *)(vhdr + 1),
hash_split, seed);
break;
case ETH_P_IPV6:
rc = decode_ipv6_n_hash((struct ipv6hdr *)(vhdr + 1),
hash_split, seed);
break;
case ETH_P_PPP_DISC:
case ETH_P_PPP_SES:
case ETH_P_IPX:
case ETH_P_LOOP:
case ETH_P_MPLS_MC:
case ETH_P_MPLS_UC:
case ETH_P_ARP:
case ETH_P_RARP:
default:
/* others */
rc = decode_others_n_hash(ethh, seed);
break;
}
TRACE_PKTHASH_FUNC_END();
return rc;
}
开发者ID:ajamshed,项目名称:packet-bricks,代码行数:35,代码来源:pkt_hash.c
示例5: Mtftp4WrqHandleAck
/**
Function to handle received ACK packet.
If the ACK number matches the expected block number, and there are more
data pending, send the next block. Otherwise tell the caller that we are done.
@param Instance The MTFTP upload session
@param Packet The MTFTP packet received
@param Len The packet length
@param Completed Return whether the upload has finished.
@retval EFI_SUCCESS The ACK is successfully processed.
@retval EFI_TFTP_ERROR The block number loops back.
@retval Others Failed to transmit the next data packet.
**/
EFI_STATUS
Mtftp4WrqHandleAck (
IN MTFTP4_PROTOCOL *Instance,
IN EFI_MTFTP4_PACKET *Packet,
IN UINT32 Len,
OUT BOOLEAN *Completed
)
{
UINT16 AckNum;
INTN Expected;
UINT64 TotalBlock;
*Completed = FALSE;
AckNum = NTOHS (Packet->Ack.Block[0]);
Expected = Mtftp4GetNextBlockNum (&Instance->Blocks);
ASSERT (Expected >= 0);
//
// Get an unwanted ACK, return EFI_SUCCESS to let Mtftp4WrqInput
// restart receive.
//
if (Expected != AckNum) {
return EFI_SUCCESS;
}
//
// Remove the acked block number, if this is the last block number,
// tell the Mtftp4WrqInput to finish the transfer. This is the last
// block number if the block range are empty..
//
Mtftp4RemoveBlockNum (&Instance->Blocks, AckNum, *Completed,&TotalBlock);
Expected = Mtftp4GetNextBlockNum (&Instance->Blocks);
if (Expected < 0) {
//
// The block range is empty. It may either because the the last
// block has been ACKed, or the sequence number just looped back,
// that is, there is more than 0xffff blocks.
//
if (Instance->LastBlock == AckNum) {
ASSERT (Instance->LastBlock >= 1);
*Completed = TRUE;
return EFI_SUCCESS;
} else {
Mtftp4SendError (
Instance,
EFI_MTFTP4_ERRORCODE_REQUEST_DENIED,
(UINT8 *) "Block number rolls back, not supported, try blksize option"
);
return EFI_TFTP_ERROR;
}
}
return Mtftp4WrqSendBlock (Instance, (UINT16) Expected);
}
开发者ID:kraxel,项目名称:edk2,代码行数:76,代码来源:Mtftp4Wrq.c
示例6: ipv6_input
/**@brief Function for multiplexing transport protocol to different modules.
*
* @param[in] p_interface Pointer to external interface from which packet come.
* @param[in] p_pbuffer Pointer to packet buffer.
*
* @return NRF_SUCCESS if success, otherwise an error code.
*/
static uint32_t ipv6_input(iot_interface_t * p_interface, iot_pbuffer_t * p_pbuffer)
{
uint32_t err_code = NRF_SUCCESS;
ipv6_header_t * p_iphdr = (ipv6_header_t *)(p_pbuffer->p_payload - IPV6_IP_HEADER_SIZE);
// Change byte order of IP header given to application.
p_iphdr->length = NTOHS(p_iphdr->length);
p_iphdr->flowlabel = NTOHS(p_iphdr->flowlabel);
switch (p_iphdr->next_header)
{
case IPV6_NEXT_HEADER_ICMP6:
IPV6_TRC("Got ICMPv6 packet.");
IPV6_MUTEX_UNLOCK();
err_code = icmp6_input(p_interface, p_iphdr, p_pbuffer);
IPV6_MUTEX_LOCK();
break;
case IPV6_NEXT_HEADER_UDP:
IPV6_TRC("Got UDP packet.");
IPV6_MUTEX_UNLOCK();
err_code = udp_input(p_interface, p_iphdr, p_pbuffer);
IPV6_MUTEX_LOCK();
break;
default:
IPV6_ERR("Got unsupported protocol packet. Protocol ID = 0x%x!",
p_iphdr->next_header);
#if (IPV6_ENABLE_USNUPORTED_PROTOCOLS_TO_APPLICATION == 1)
app_notify_rx_data(p_interface, p_pbuffer);
#endif
break;
}
// Free packet buffer unless marked explicitly as pending
if (err_code != IOT_IPV6_ERR_PENDING)
{
UNUSED_VARIABLE(iot_pbuffer_free(p_pbuffer, true));
}
return err_code;
}
开发者ID:kiibohd,项目名称:controller,代码行数:54,代码来源:ipv6.c
示例7: pcap_nametoport
/*
* Convert a port name to its port and protocol numbers.
* We assume only TCP or UDP.
* Return 0 upon failure.
*/
int
pcap_nametoport(const char *name, int *port, int *proto)
{
struct servent *sp;
char *other;
sp = getservbyname(name, (char *)0);
if (sp != NULL) {
NTOHS(sp->s_port);
*port = sp->s_port;
*proto = pcap_nametoproto(sp->s_proto);
/*
* We need to check /etc/services for ambiguous entries.
* If we find the ambiguous entry, and it has the
* same port number, change the proto to PROTO_UNDEF
* so both TCP and UDP will be checked.
*/
if (*proto == IPPROTO_TCP)
other = "udp";
else
other = "tcp";
sp = getservbyname(name, other);
if (sp != 0) {
NTOHS(sp->s_port);
#ifdef notdef
if (*port != sp->s_port)
/* Can't handle ambiguous names that refer
to different port numbers. */
warning("ambiguous port %s in /etc/services",
name);
#endif
*proto = PROTO_UNDEF;
}
return 1;
}
#if defined(ultrix) || defined(__osf__)
/* Special hack in case NFS isn't in /etc/services */
if (strcmp(name, "nfs") == 0) {
*port = 2049;
*proto = PROTO_UNDEF;
return 1;
}
#endif
return 0;
}
开发者ID:wbx-github,项目名称:openadk,代码行数:51,代码来源:nametoaddr.c
示例8: print_socket
void print_socket(socket_t *current_socket)
{
char addr_str[IPV6_MAX_ADDR_STR_LEN];
printf("Domain: %i, Type: %i, Protocol: %i \n",
current_socket->domain,
current_socket->type,
current_socket->protocol);
printf("Local address: %s\n",
ipv6_addr_to_str(addr_str,
¤t_socket->local_address.sin6_addr));
printf("Foreign address: %s\n",
ipv6_addr_to_str(addr_str,
¤t_socket->foreign_address.sin6_addr));
printf("Local Port: %u, Foreign Port: %u\n",
NTOHS(current_socket->local_address.sin6_port),
NTOHS(current_socket->foreign_address.sin6_port));
}
开发者ID:manoja328,项目名称:RIOT,代码行数:17,代码来源:socket.c
示例9: TcpGetUint16
/**
Get a UINT16 value from buffer.
@param[in] Buf Pointer to input buffer.
@return The UINT16 value obtained from the buffer.
**/
UINT16
TcpGetUint16 (
IN UINT8 *Buf
)
{
UINT16 Value;
CopyMem (&Value, Buf, sizeof (UINT16));
return NTOHS (Value);
}
开发者ID:shijunjing,项目名称:edk2,代码行数:17,代码来源:TcpOption.c
示例10: swab_dbrec
void swab_dbrec (struct or_dbrec *rec, SWABDIR direction)
{
#ifndef BYTE_SWAP
return;
#else
if (direction == NTOH) {
NTOHL (rec->or_dbflags);
NTOHL (rec->or_dbuflags);
NTOHL (rec->or_reccount);
NTOHL (rec->or_maxdba);
NTOHL (rec->or_availd99);
NTOHL (rec->or_unavaild99);
NTOHL (rec->or_hufid);
NTOHL (rec->or_dbsecmask);
NTOHS (rec->or_dbotype);
NTOHS (rec->or_compflags);
NTOHS (rec->or_dbaccess);
NTOHS (rec->or_minwordsz);
NTOHS (rec->or_maxwordsz);
NTOHS (rec->or_recslots);
NTOHS (rec->or_fzkeysz);
NTOHS (rec->or_abstrsz);
NTOHS (rec->or_language);
}
else { /* going the other direction */
HTONL (rec->or_dbflags);
HTONL (rec->or_dbuflags);
HTONL (rec->or_reccount);
HTONL (rec->or_maxdba);
HTONL (rec->or_availd99);
HTONL (rec->or_unavaild99);
HTONL (rec->or_hufid);
HTONL (rec->or_dbsecmask);
HTONS (rec->or_dbotype);
HTONS (rec->or_compflags);
HTONS (rec->or_dbaccess);
HTONS (rec->or_minwordsz);
HTONS (rec->or_maxwordsz);
HTONS (rec->or_recslots);
HTONS (rec->or_fzkeysz);
HTONS (rec->or_abstrsz);
HTONS (rec->or_language);
}
return;
#endif /* BYTE_SWAP */
} /* swab_dbrec() */
开发者ID:idunham,项目名称:cdesktop,代码行数:49,代码来源:dtsrswab.c
示例11: INITIALIZE_NDFS_REQUEST_HEADER
VOID
INITIALIZE_NDFS_REQUEST_HEADER (
PNDFS_REQUEST_HEADER NdfsRequestHeader,
UINT8 Command,
PSECONDARY Secondary,
UINT8 IrpMajorFunction,
UINT32 DataSize
)
{
ExAcquireFastMutex( &Secondary->FastMutex );
RtlCopyMemory(NdfsRequestHeader->Protocol, NDFS_PROTOCOL, sizeof(NdfsRequestHeader->Protocol));
NdfsRequestHeader->Command = Command;
NdfsRequestHeader->Flags = Secondary->Thread.SessionContext.Flags;
NdfsRequestHeader->Uid2 = NTOHS(Secondary->Thread.SessionContext.Uid);
NdfsRequestHeader->Tid2 = NTOHS(Secondary->Thread.SessionContext.Tid);
NdfsRequestHeader->Mid2 = 0;
NdfsRequestHeader->MessageSize4
= sizeof(NDFS_REQUEST_HEADER)
+ (
(Secondary->Thread.SessionContext.MessageSecurity == 0)
? sizeof(NDFS_WINXP_REQUEST_HEADER) + DataSize
: (
((IrpMajorFunction == IRP_MJ_WRITE
&& Secondary->Thread.SessionContext.RwDataSecurity == 0
&& DataSize <= Secondary->Thread.SessionContext.PrimaryMaxDataSize)
||
IrpMajorFunction == IRP_MJ_READ
&& Secondary->Thread.SessionContext.RwDataSecurity == 0
&& DataSize <= Secondary->Thread.SessionContext.SecondaryMaxDataSize)
? ADD_ALIGN8(sizeof(NDFS_WINXP_REQUEST_HEADER) + DataSize)
: ADD_ALIGN8(sizeof(NDFS_WINXP_REQUEST_HEADER) + DataSize)
)
);
NdfsRequestHeader->MessageSize4 = NTOHL(NdfsRequestHeader->MessageSize4);
ExReleaseFastMutex( &Secondary->FastMutex );
return;
}
开发者ID:Nevermore2015,项目名称:ndas4windows,代码行数:43,代码来源:Secondary.c
示例12: udp_csum
uint16_t udp_csum(ipv6_hdr_t *ipv6_header, udp_hdr_t *udp_header)
{
uint16_t sum;
uint16_t len = NTOHS(udp_header->length);
sum = len + IPPROTO_UDP;
sum = csum(sum, (uint8_t *)&ipv6_header->srcaddr, 2 * sizeof(ipv6_addr_t));
sum = csum(sum, (uint8_t *)udp_header, len);
return (sum == 0) ? 0xffff : HTONS(sum);
}
开发者ID:A-L-E-X,项目名称:RIOT,代码行数:10,代码来源:udp.c
示例13: decode_ip_hdr
static
int decode_ip_hdr(struct iphdr *iphd)
{
cprintf("IP Header\n");
cprintf("SRC IP: \t%ld.%ld.%ld.%ld\n",
IP_ADDR_FORMAT((long)NTOHL(iphd->ip_source)));
cprintf("DST IP: \t%ld.%ld.%ld.%ld\n",
IP_ADDR_FORMAT((long)NTOHL(iphd->ip_dest)));
cprintf("version: \t%d\n", iphd->ip_v);
cprintf("protocol: \t%d\n", iphd->ip_p);
cprintf("frag offset:\t%d\n", NTOHS(iphd->ip_off)&0x1fff);
cprintf("more frags: \t%d\n", (NTOHS(iphd->ip_off)&0x2000) >> 13);
cprintf("ip hdr len: \t%d\n", iphd->ip_hl*4);
cprintf("total len: \t%d\n", NTOHS(iphd->ip_len));
cprintf("id: \t%d\n", NTOHS(iphd->ip_id));
cprintf("\n");
return 0;
}
开发者ID:BillTheBest,项目名称:k42,代码行数:19,代码来源:PacketFilterRoot.C
示例14: conn_udp_getlocaladdr
int conn_udp_getlocaladdr(conn_udp_t *conn, void *addr, uint16_t *port)
{
if (conn->sock.input_callback != NULL) {
mutex_lock(&conn->mutex);
memset(addr, 0, sizeof(ipv6_addr_t));
*port = NTOHS(conn->sock.udp_conn->lport);
mutex_unlock(&conn->mutex);
return sizeof(ipv6_addr_t);
}
return -EBADF;
}
开发者ID:AdamRLukaitis,项目名称:RIOT,代码行数:11,代码来源:emb6_conn_udp.c
示例15: decode_tcp_hdr
static
int decode_tcp_hdr(struct tcphdr *tcphd)
{
cprintf("TCP Header\n");
cprintf("SRC Port:\t%d\n", NTOHS(tcphd->tcp_source));
cprintf("DST Port:\t%d\n", NTOHS(tcphd->tcp_dest));
cprintf("seq #: \t%lu\n", (long)NTOHL(tcphd->tcp_seq));
cprintf("ack #: \t%lu\n", (long)NTOHL(tcphd->tcp_ack_seq));
cprintf("hdr len: \t%d\n", tcphd->tcp_doff * 4);
cprintf("rst: \t%d\n", tcphd->tcp_rst);
cprintf("syn: \t%d\n", tcphd->tcp_syn);
cprintf("fin: \t%d\n", tcphd->tcp_fin);
cprintf("window: \t%d\n", NTOHS(tcphd->tcp_window));
cprintf("cksum: \t%d\n", NTOHS(tcphd->tcp_sum));
cprintf("urg_ptr: \t%d\n", NTOHS(tcphd->tcp_urg_ptr));
cprintf("P: %d, A: %d, U: %d, R1: %d, R2: %d\n",
tcphd->tcp_psh, tcphd->tcp_ack, tcphd->tcp_urg, tcphd->tcp_res1,
tcphd->tcp_res2);
return 0;
}
开发者ID:BillTheBest,项目名称:k42,代码行数:21,代码来源:PacketFilterRoot.C
示例16: decode_ip_n_hash
/**
* Parser + hash function for the IPv4 packet
*/
static uint32_t
decode_ip_n_hash(struct iphdr *iph, uint8_t hash_split, uint8_t seed)
{
TRACE_PKTHASH_FUNC_START();
uint32_t rc = 0;
if (hash_split == 2) {
rc = sym_hash_fn(NTOHL(iph->saddr),
NTOHL(iph->daddr),
NTOHS(0xFFFD) + seed,
NTOHS(0xFFFE) + seed);
} else {
struct tcphdr *tcph = NULL;
struct udphdr *udph = NULL;
switch (iph->protocol) {
case IPPROTO_TCP:
tcph = (struct tcphdr *)((uint8_t *)iph + (iph->ihl<<2));
rc = sym_hash_fn(NTOHL(iph->saddr),
NTOHL(iph->daddr),
NTOHS(tcph->source) + seed,
NTOHS(tcph->dest) + seed);
break;
case IPPROTO_UDP:
udph = (struct udphdr *)((uint8_t *)iph + (iph->ihl<<2));
rc = sym_hash_fn(NTOHL(iph->saddr),
NTOHL(iph->daddr),
NTOHS(udph->source) + seed,
NTOHS(udph->dest) + seed);
break;
case IPPROTO_IPIP:
/* tunneling */
rc = decode_ip_n_hash((struct iphdr *)((uint8_t *)iph + (iph->ihl<<2)),
hash_split, seed);
break;
default:
/*
* the hash strength (although weaker but) should still hold
* even with 2 fields
*/
rc = sym_hash_fn(NTOHL(iph->saddr),
NTOHL(iph->daddr),
NTOHS(0xFFFD) + seed,
NTOHS(0xFFFE) + seed);
break;
}
}
TRACE_PKTHASH_FUNC_END();
return rc;
}
开发者ID:ajamshed,项目名称:packet-bricks,代码行数:53,代码来源:pkt_hash.c
示例17: pGetNdasUnitDevice
VOID
CNdasIXServer::OnIXPrimaryUpdate(
CLpxDatagramSocket& sock,
CONST SOCKADDR_LPX* pRemoteAddr,
CONST LSINFOX_PRIMARY_UPDATE* pData)
{
NDAS_UNITDEVICE_ID unitDeviceId = {
{
pData->NetDiskNode[0], pData->NetDiskNode[1],
pData->NetDiskNode[2], pData->NetDiskNode[3],
pData->NetDiskNode[4], pData->NetDiskNode[5]
},
pData->UnitDiskNo
};
CNdasUnitDevicePtr pUnitDevice = pGetNdasUnitDevice(unitDeviceId);
if (0 == pUnitDevice.get()) {
//
// Discard non-discovered unit device
//
return;
}
NDAS_UNITDEVICE_PRIMARY_HOST_INFO hostinfo;
::CopyMemory(
hostinfo.Host.Node,
pData->PrimaryNode,
sizeof(hostinfo.Host.Node));
hostinfo.Host.Port = NTOHS(pData->PrimaryPort);
hostinfo.SWMajorVersion = pData->SWMajorVersion;
hostinfo.SWMinorVersion = pData->SWMinorVersion;
hostinfo.SWBuildNumber = pData->SWBuildNumber;
hostinfo.NDFSCompatVersion = pData->NDFSCompatVersion;
hostinfo.NDFSVersion = pData->NDFSVersion;
XTLTRACE2(NDASSVC_IX, TRACE_LEVEL_RESERVED6,
"LSINFOX_PRIMATE_UPDATE_MESSAGE: %02X:%02X:%02X:%02X:%02X:%[email protected]%d\n",
pData->NetDiskNode[0],
pData->NetDiskNode[1],
pData->NetDiskNode[2],
pData->NetDiskNode[3],
pData->NetDiskNode[4],
pData->NetDiskNode[5],
pData->UnitDiskNo);
pUnitDevice->UpdatePrimaryHostInfo(hostinfo);
return;
}
开发者ID:JanD1943,项目名称:ndas4windows,代码行数:51,代码来源:ndasix.cpp
示例18: perror
/* Start a fake net connection (used for demos on CLIENT) */
netconnection_t *net_fake_connection(char *demoname, demo_header *header)
{
int fd;
ssize_t size;
netconnection_t *nc;
if( !(fd = open(demoname, O_RDONLY)) ) {
perror("open");
return NULL;
}
size = read(fd, header, sizeof(demo_header));
if( size != sizeof(demo_header) ) {
printf("Couldn't Read header information from \"%s\"\n", demoname);
if( size < 0 )
perror("read");
else
printf("Read only %d bytes of %d.\n", size, sizeof(demo_header));
close(fd);
return NULL;
}
NTOHS( header->x_tiles );
NTOHS( header->y_tiles );
NTOHS( header->fps );
if( (nc = nc_alloc()) ) {
net_connection_reset(nc);
nc->fd = fd;
nc->record_fd = 0;
nc->fake = 1;
nc->remote_address = fake_address;
}
return nc;
}
开发者ID:davmlaw,项目名称:xtux,代码行数:39,代码来源:net.c
示例19: rpl_remove_srh_header
void rpl_remove_srh_header(ipv6_hdr_t *ipv6_header, const void *buf, uint8_t nextheader)
{
ipv6_hdr_t *temp_ipv6_header = ((ipv6_hdr_t *)(&srh_send_buffer));
uint8_t *payload = &srh_send_buffer[IPV6_HDR_LEN];
memcpy(temp_ipv6_header, ipv6_header, sizeof(ipv6_hdr_t));
int msg_length = NTOHS(ipv6_header->length) - sizeof(ipv6_srh_t);
temp_ipv6_header->length = HTONS(msg_length);
temp_ipv6_header->nextheader = nextheader;
memcpy(payload, buf, msg_length);
DEBUGF("Source routing header extraction finished.\n");
DEBUGF("Dest is now: %s\n", ipv6_addr_to_str(addr_str, IPV6_MAX_ADDR_STR_LEN, &temp_ipv6_header->destaddr));
srh_m_send.content.ptr = (char *) srh_send_buffer;
DEBUGF("Return from relay: %d\n", msg_send_receive(&srh_m_send, &srh_m_recv, ip_process_pid));
}
开发者ID:shawnlintw,项目名称:RIOT,代码行数:14,代码来源:rpl.c
示例20: decode_others_n_hash
/**
* A temp solution while hash for other protocols are filled...
* (See decode_vlan_n_hash & pkt_hdr_hash functions).
*/
static uint32_t
decode_others_n_hash(struct ethhdr *ethh, uint8_t seed)
{
TRACE_PKTHASH_FUNC_START();
uint32_t saddr, daddr, rc;
saddr = ethh->h_source[5] |
(ethh->h_source[4] << 8) |
(ethh->h_source[3] << 16) |
(ethh->h_source[2] << 24);
daddr = ethh->h_dest[5] |
(ethh->h_dest[4] << 8) |
(ethh->h_dest[3] << 16) |
(ethh->h_dest[2] << 24);
rc = sym_hash_fn(NTOHL(saddr),
NTOHL(daddr),
NTOHS(0xFFFD) + seed,
NTOHS(0xFFFE) + seed);
TRACE_PKTHASH_FUNC_END();
return rc;
}
开发者ID:ajamshed,项目名称:packet-bricks,代码行数:27,代码来源:pkt_hash.c
注:本文中的NTOHS函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论