本文整理汇总了C++中IP_V函数的典型用法代码示例。如果您正苦于以下问题:C++ IP_V函数的具体用法?C++ IP_V怎么用?C++ IP_V使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IP_V函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sl_if_print
u_int
sl_if_print(const struct pcap_pkthdr *h, const u_char *p)
{
register u_int caplen = h->caplen;
register u_int length = h->len;
register const struct ip *ip;
if (caplen < SLIP_HDRLEN) {
printf("[|slip]");
return (caplen);
}
length -= SLIP_HDRLEN;
ip = (struct ip *)(p + SLIP_HDRLEN);
if (eflag)
sliplink_print(p, ip, length);
switch (IP_V(ip)) {
case 4:
ip_print(gndo, (u_char *)ip, length);
break;
#ifdef INET6
case 6:
ip6_print((u_char *)ip, length);
break;
#endif
default:
printf ("ip v%d", IP_V(ip));
}
return (SLIP_HDRLEN);
}
示例2: sl_if_print
u_int
sl_if_print(netdissect_options *ndo,
const struct pcap_pkthdr *h, const u_char *p)
{
register u_int caplen = h->caplen;
register u_int length = h->len;
register const struct ip *ip;
if (caplen < SLIP_HDRLEN || length < SLIP_HDRLEN) {
ND_PRINT((ndo, "%s", tstr));
return (caplen);
}
length -= SLIP_HDRLEN;
ip = (struct ip *)(p + SLIP_HDRLEN);
if (ndo->ndo_eflag)
sliplink_print(ndo, p, ip, length);
switch (IP_V(ip)) {
case 4:
ip_print(ndo, (u_char *)ip, length);
break;
case 6:
ip6_print(ndo, (u_char *)ip, length);
break;
default:
ND_PRINT((ndo, "ip v%d", IP_V(ip)));
}
return (SLIP_HDRLEN);
}
示例3: assign_addr_pair
/**
* Creates an addr_pair from an ip (and tcp/udp) header, swapping src and dst
* if required
*/
void assign_addr_pair(addr_pair* ap, struct ip* iptr, int flip) {
unsigned short int src_port = 0;
unsigned short int dst_port = 0;
/* Arrange for predictable values. */
memset(ap, '\0', sizeof(*ap));
if(IP_V(iptr) == 4) {
ap->af = AF_INET;
/* Does this protocol use ports? */
if(iptr->ip_p == IPPROTO_TCP || iptr->ip_p == IPPROTO_UDP) {
/* We take a slight liberty here by treating UDP the same as TCP */
/* Find the TCP/UDP header */
struct tcphdr* thdr = ((void*)iptr) + IP_HL(iptr) * 4;
src_port = ntohs(thdr->th_sport);
dst_port = ntohs(thdr->th_dport);
}
if(flip == 0) {
ap->src = iptr->ip_src;
ap->src_port = src_port;
ap->dst = iptr->ip_dst;
ap->dst_port = dst_port;
}
else {
ap->src = iptr->ip_dst;
ap->src_port = dst_port;
ap->dst = iptr->ip_src;
ap->dst_port = src_port;
}
} /* IPv4 */
else if (IP_V(iptr) == 6) {
/* IPv6 packet seen. */
struct ip6_hdr *ip6tr = (struct ip6_hdr *) iptr;
ap->af = AF_INET6;
if( (ip6tr->ip6_nxt == IPPROTO_TCP) || (ip6tr->ip6_nxt == IPPROTO_UDP) ) {
struct tcphdr *thdr = ((void *) ip6tr) + 40;
src_port = ntohs(thdr->th_sport);
dst_port = ntohs(thdr->th_dport);
}
if(flip == 0) {
memcpy(&ap->src6, &ip6tr->ip6_src, sizeof(ap->src6));
ap->src_port = src_port;
memcpy(&ap->dst6, &ip6tr->ip6_dst, sizeof(ap->dst6));
ap->dst_port = dst_port;
}
else {
memcpy(&ap->src6, &ip6tr->ip6_dst, sizeof(ap->src6));
ap->src_port = dst_port;
memcpy(&ap->dst6, &ip6tr->ip6_src, sizeof(ap->dst6));
ap->dst_port = src_port;
}
}
}
示例4: print_nfsaddr
static void
print_nfsaddr(netdissect_options *ndo,
const u_char *bp, const char *s, const char *d)
{
const struct ip *ip;
const struct ip6_hdr *ip6;
char srcaddr[INET6_ADDRSTRLEN], dstaddr[INET6_ADDRSTRLEN];
srcaddr[0] = dstaddr[0] = '\0';
switch (IP_V((const struct ip *)bp)) {
case 4:
ip = (const struct ip *)bp;
strlcpy(srcaddr, ipaddr_string(ndo, &ip->ip_src), sizeof(srcaddr));
strlcpy(dstaddr, ipaddr_string(ndo, &ip->ip_dst), sizeof(dstaddr));
break;
case 6:
ip6 = (const struct ip6_hdr *)bp;
strlcpy(srcaddr, ip6addr_string(ndo, &ip6->ip6_src),
sizeof(srcaddr));
strlcpy(dstaddr, ip6addr_string(ndo, &ip6->ip6_dst),
sizeof(dstaddr));
break;
default:
strlcpy(srcaddr, "?", sizeof(srcaddr));
strlcpy(dstaddr, "?", sizeof(dstaddr));
break;
}
ND_PRINT("%s.%s > %s.%s: ", srcaddr, s, dstaddr, d);
}
示例5: getIpHeader
int getIpHeader (struct ip *ip_b, u_int32_t *proto, u_int16_t *id,
u_int32_t *len, u_int32_t *src, u_int32_t *dst)
{
u_int32_t *ip = (u_int32_t *) ip_b;
u_int32_t off;
/*
* If it's not IPv4, then we're completely lost.
*/
if (IP_V (ip_b) != 4) {
return (-1);
}
/*
* If this isn't fragment zero of an higher-level "packet",
* then it's not something that we're interested in, so dump
* it.
*/
off = ntohs(ip_b->ip_off);
if ((off & 0x1fff) != 0) {
printf("# it's a fragment (offset=%d) of %d\n",
(off & 0x1fff), ntohs(ip_b->ip_len));
return (0);
}
*proto = ip_b->ip_p;
*len = ntohs (ip_b->ip_len);
*src = ntohl (ip [3]);
*dst = ntohl (ip [4]);
*id = ntohs (ip_b->ip_id);
return (IP_HL (ip_b) * 4);
}
示例6: xid_map_find
/*
* Returns 0 and puts NFSPROC_xxx in proc return and
* version in vers return, or returns -1 on failure
*/
static int
xid_map_find(const struct sunrpc_msg *rp, const u_char *bp, u_int32_t *proc,
u_int32_t *vers)
{
int i;
struct xid_map_entry *xmep;
u_int32_t xid = rp->rm_xid;
struct ip *ip = (struct ip *)bp;
#ifdef INET6
struct ip6_hdr *ip6 = (struct ip6_hdr *)bp;
#endif
int cmp;
/* Start searching from where we last left off */
i = xid_map_hint;
do {
xmep = &xid_map[i];
cmp = 1;
if (xmep->ipver != IP_V(ip) || xmep->xid != xid)
goto nextitem;
switch (xmep->ipver) {
case 4:
if (memcmp(&ip->ip_src, &xmep->server,
sizeof(ip->ip_src)) != 0 ||
memcmp(&ip->ip_dst, &xmep->client,
sizeof(ip->ip_dst)) != 0) {
cmp = 0;
}
break;
#ifdef INET6
case 6:
if (memcmp(&ip6->ip6_src, &xmep->server,
sizeof(ip6->ip6_src)) != 0 ||
memcmp(&ip6->ip6_dst, &xmep->client,
sizeof(ip6->ip6_dst)) != 0) {
cmp = 0;
}
break;
#endif
default:
cmp = 0;
break;
}
if (cmp) {
/* match */
xid_map_hint = i;
*proc = xmep->proc;
*vers = xmep->vers;
return 0;
}
nextitem:
if (++i >= XIDMAPSIZE)
i = 0;
} while (i != xid_map_hint);
/* search failed */
return (-1);
}
示例7: sizeof
u_char* handle_IP
(u_char *args,const struct pcap_pkthdr* pkthdr,const u_char*
packet)
{
const struct my_ip* ip;
u_int length = pkthdr->len;
u_int hlen,off,version;
int i;
int len;
/* jump pass the ethernet header */
ip = (struct my_ip*)(packet + sizeof(struct ether_header));
length -= sizeof(struct ether_header);
/* check to see we have a packet of valid length */
if (length < sizeof(struct my_ip))
{
printf("truncated ip %d",length);
return NULL;
}
len = ntohs(ip->ip_len);
hlen = IP_HL(ip); /* header length */
version = IP_V(ip);/* ip version */
/* check version */
if(version != 4)
{
fprintf(stdout,"Unknown version %d\n",version);
return NULL;
}
/* check header length */
if(hlen < 5 )
{
fprintf(stdout,"bad-hlen %d \n",hlen);
}
/* see if we have as much packet as we should */
if(length < len)
printf("\ntruncated IP - %d bytes missing\n",len - length);
/* Check to see if we have the first fragment */
off = ntohs(ip->ip_off);
if((off & 0x1fff) == 0 )/* aka no 1's in first 13 bits */
{/* print SOURCE DESTINATION hlen version len offset */
fprintf(stdout,"IP: ");
fprintf(stdout,"%s ",
inet_ntoa(ip->ip_src));
fprintf(stdout,"%s %d %d %d %d\n",
inet_ntoa(ip->ip_dst),
hlen,version,len,off);
}
return NULL;
}
示例8: prepare_raw
void prepare_raw(packetinfo *pi)
{
pi->eth_hlen = 0;
if (IP_V((ip4_header *)pi->packet) == 4) {
pi->eth_type = ETHERNET_TYPE_IP;
}
else {
pi->eth_type = ETHERNET_TYPE_IPV6;
}
}
示例9: prepare_sll
void prepare_sll(packetinfo *pi)
{
pi->eth_hlen = SLL_HDR_LEN;
if (IP_V((ip4_header *)(pi->packet + SLL_HDR_LEN)) == 4) {
pi->eth_type = ETHERNET_TYPE_IP;
}
else {
pi->eth_type = ETHERNET_TYPE_IPV6;
}
}
示例10: parse_http_packet
void parse_http_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *pkt) {
char *header_line, *req_value;
int is_request = 0, is_response = 0;
const struct ip_header *ip;
const struct tcp_header *tcp;
const char *data;
int ip_headlen, tcp_headlen, data_len, family;
ip = (struct ip_header *) (pkt + link_header_offset);
switch (IP_V(ip)) {
case 4:
family = AF_INET;
break;
default:
return;
}
ip_headlen = IP_HL(ip) * 4;
if (ip_headlen < 20) return;
if (ip->ip_p != IPPROTO_TCP) return;
tcp = (struct tcp_header *) ((char *)ip + ip_headlen);
tcp_headlen = TH_OFF(tcp) * 4;
if (tcp_headlen< 20) return;
data = (char *)tcp + tcp_headlen;
data_len = (header->caplen - (link_header_offset + ip_headlen + tcp_headlen));
if (data_len <= 0) return;
if (have_request_method(data)) {
is_request = 1;
} else if (strncmp(data, "HTTP/", strlen("HTTP/")) == 0) {
is_response = 1;
} else {
return;
}
if (data_len > BUFSIZ) data_len = BUFSIZ;
memcpy(buf, data, data_len);
buf[data_len-1] = '\0';
if (is_request) {
char *p = strchr(buf, '?');
if(p) *p = '\0';
debug_ascii(buf, data_len, "TEST" );
}
else if (is_response) {
}
return;
}
示例11: xid_map_enter
static int
xid_map_enter(netdissect_options *ndo,
const struct sunrpc_msg *rp, const u_char *bp)
{
struct ip *ip = NULL;
#ifdef INET6
struct ip6_hdr *ip6 = NULL;
#endif
struct xid_map_entry *xmep;
if (!ND_TTEST(rp->rm_call.cb_vers))
return (0);
switch (IP_V((struct ip *)bp)) {
case 4:
ip = (struct ip *)bp;
break;
#ifdef INET6
case 6:
ip6 = (struct ip6_hdr *)bp;
break;
#endif
default:
return (1);
}
xmep = &xid_map[xid_map_next];
if (++xid_map_next >= XIDMAPSIZE)
xid_map_next = 0;
UNALIGNED_MEMCPY(&xmep->xid, &rp->rm_xid, sizeof(xmep->xid));
if (ip) {
xmep->ipver = 4;
UNALIGNED_MEMCPY(&xmep->client, &ip->ip_src, sizeof(ip->ip_src));
UNALIGNED_MEMCPY(&xmep->server, &ip->ip_dst, sizeof(ip->ip_dst));
}
#ifdef INET6
else if (ip6) {
xmep->ipver = 6;
UNALIGNED_MEMCPY(&xmep->client, &ip6->ip6_src, sizeof(ip6->ip6_src));
UNALIGNED_MEMCPY(&xmep->server, &ip6->ip6_dst, sizeof(ip6->ip6_dst));
}
#endif
xmep->proc = EXTRACT_32BITS(&rp->rm_call.cb_proc);
xmep->vers = EXTRACT_32BITS(&rp->rm_call.cb_vers);
return (1);
}
示例12: xid_map_enter
static void
xid_map_enter(const struct sunrpc_msg *rp, const u_char *bp)
{
struct ip *ip = NULL;
#ifdef INET6
struct ip6_hdr *ip6 = NULL;
#endif
struct xid_map_entry *xmep;
switch (IP_V((struct ip *)bp)) {
case 4:
ip = (struct ip *)bp;
break;
#ifdef INET6
case 6:
ip6 = (struct ip6_hdr *)bp;
break;
#endif
default:
return;
}
xmep = &xid_map[xid_map_next];
if (++xid_map_next >= XIDMAPSIZE)
xid_map_next = 0;
xmep->xid = rp->rm_xid;
if (ip) {
xmep->ipver = 4;
memcpy(&xmep->client, &ip->ip_src, sizeof(ip->ip_src));
memcpy(&xmep->server, &ip->ip_dst, sizeof(ip->ip_dst));
}
#ifdef INET6
else if (ip6) {
xmep->ipver = 6;
memcpy(&xmep->client, &ip6->ip6_src, sizeof(ip6->ip6_src));
memcpy(&xmep->server, &ip6->ip6_dst, sizeof(ip6->ip6_dst));
}
#endif
xmep->proc = EXTRACT_32BITS(&rp->rm_call.cb_proc);
xmep->vers = EXTRACT_32BITS(&rp->rm_call.cb_vers);
}
示例13: reaper_rtcp_format
static int
reaper_rtcp_format(const struct ip *ip, int sport, int dport, const char* data, int len)
{
char hex[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
char *buffer = reaper_packet_buffer_rtcp;
#ifdef INET6
if (IP_V(ip) == 6) {
const struct ip6_hdr *ip6;
ip6 = (const struct ip6_hdr *)ip;
buffer += sprintf(reaper_packet_buffer_rtcp, FORMAT,
reaper_source_mac,
ip6addr_string(&ip6->ip6_src),
udpport_string(sport),
reaper_destination_mac,
ip6addr_string(&ip6->ip6_dst),
udpport_string(dport));
}
else {
#endif /*INET6*/
buffer += sprintf(reaper_packet_buffer_rtcp, FORMAT,
reaper_source_mac,
ipaddr_string(&ip->ip_src),
udpport_string(sport),
reaper_destination_mac,
ipaddr_string(&ip->ip_dst),
udpport_string(dport));
#ifdef INET6
}
#endif /*INET6*/
fprintf(stderr, "Sending RTCP packet <%s>\n", reaper_packet_buffer_rtcp);
char *end_buffer = reaper_packet_buffer_rtcp + sizeof(reaper_packet_buffer_rtcp) - 3;
const char *end_data = data + len;
while (data < end_data) {
*(buffer++) = hex[((*data >> 4) & 0xF)];
*(buffer++) = hex[(*data & 0xF)];
if (buffer >= end_buffer)
break;
++data;
}
*(buffer++) = '\n';
*(buffer) = '\0';
return (buffer - reaper_packet_buffer_rtcp);
}
示例14: handle_IP
uint16_t handle_IP (u_char *args,const struct pcap_pkthdr* hdr,
const u_char *packet){
const struct my_ip *ip;
u_int length =hdr->len;
u_int hlen, off, version;
int len;
ip =(struct my_ip*)(packet+sizeof(struct ether_header));
length-=sizeof(struct ether_header);
// if IP hdr is smaller than the normal
if(length < sizeof(struct my_ip)){
printf("truncated ip %d",length);
return -1;
}
len =ntohs(ip->ip_len);
hlen =IP_HL(ip);
version =IP_V(ip);
if(version != 4){
printf("Unknown version\n");
return -1;
}
if(hlen < 5){
printf("error in IHL\n");
return -1;
}
if(length < len)
printf("\ntruncated IP - %d bytes missing\n", len-length);
off =ntohs(ip->ip_off);
printf("IP: ");
printf("%s ",inet_ntoa(ip->ip_src));
printf("%s %d %d %d %d\n",inet_ntoa(ip->ip_dst),hlen,version,
len,off);
return (uint16_t)ip->ip_p;
}
示例15: print_nfsaddr
static void
print_nfsaddr(netdissect_options *ndo,
const u_char *bp, const char *s, const char *d)
{
struct ip *ip;
#ifdef INET6
struct ip6_hdr *ip6;
char srcaddr[INET6_ADDRSTRLEN], dstaddr[INET6_ADDRSTRLEN];
#else
#ifndef INET_ADDRSTRLEN
#define INET_ADDRSTRLEN 16
#endif
char srcaddr[INET_ADDRSTRLEN], dstaddr[INET_ADDRSTRLEN];
#endif
srcaddr[0] = dstaddr[0] = '\0';
switch (IP_V((struct ip *)bp)) {
case 4:
ip = (struct ip *)bp;
strlcpy(srcaddr, ipaddr_string(ndo, &ip->ip_src), sizeof(srcaddr));
strlcpy(dstaddr, ipaddr_string(ndo, &ip->ip_dst), sizeof(dstaddr));
break;
#ifdef INET6
case 6:
ip6 = (struct ip6_hdr *)bp;
strlcpy(srcaddr, ip6addr_string(ndo, &ip6->ip6_src),
sizeof(srcaddr));
strlcpy(dstaddr, ip6addr_string(ndo, &ip6->ip6_dst),
sizeof(dstaddr));
break;
#endif
default:
strlcpy(srcaddr, "?", sizeof(srcaddr));
strlcpy(dstaddr, "?", sizeof(dstaddr));
break;
}
ND_PRINT((ndo, "%s.%s > %s.%s: ", srcaddr, s, dstaddr, d));
}