English 中文(简体)
in-转化问题
原标题:inet_ntoa conversion problem
  • 时间:2011-07-08 07:58:28
  •  标签:
  • c

在这项法典中,一只载有包装材料,一只试图通过使用电线显示源和目的地地址,即使在此之前,我还是用六种格式印刷包装单和包装材料。 这里的问题既不相称, in/p inet_ntoa是错误的,如 o/p所示。

  the src ip address should be 172.28.6.87 but inet_ntoa shows 86.212.172.28
  the src ip address should be 172.28.6.110 but inet_ntoa shows 6.87.172.28


  char *ptr = NULL;
  ptr_fltr = (struct packet_filter*)(packet); 
  memcpy(out_data,packet,50);
  printf("
");
  for(i= 28;i<36;i++)
  printf("%#x	",out_data[i]);
  printf("*******************************************************************
");
  printf("---------------------Received Packet Info--------------------
");
  ptr = inet_ntoa(ptr_fltr->ip.ip_src);
  printf("Source Ip Addr :%s
",ptr);

页: 1

 struct packet_filter
  {
    struct mac_filter mac;
    struct ip_filter ip;
    union {
            struct udp_filter proto;
    }protocol;
  }__attribute__((packed));


 struct ip_filter
 {
    u_char ip_vhl;
    u_char ip_tos; /* type of service */
    u_short ip_len; /* total length */
    u_short ip_id; /* identification */
    u_short ip_off; /* fragment offset field */
    u_char ip_ttl; /* time to live */
    u_char ip_p; /* protocol */
    u_short ip_sum; /* checksum */
    struct in_addr ip_src; /* source and dest address */
    struct in_addr ip_dst; /* source and dest address */
 }__attribute__((packed));

产出

  0xac    0x1c    0x6 0x57    0xac    0x1c    0x6 0x6e         
  ************************************************************
  --------------------Received Packet Info--------------------
  Source Ip Addr :86.212.172.28
  Destination Ip Addr :6.87.172.28
问题回答

很显然,到你去IP地址时,你有两条 by。 我对IPv4议定书进行了检查,看着科索沃。 因此,我怀疑<代码>struct mac是错误的。 I presume struct mac is means to be an ethernet framework. 如果是的话,它就会产生怀疑,因为。 透支框架不是固定长度。

另外,(假设你正在从伯克利的包裹过滤器中提取这些设备),确保你正确计算包装机的开端(你可以依靠<条码>。

你的IP包始于被抵消的16个,如果你从外联网头上复制了struct mac,则长为14个。 就像包装中有一些意外数据。





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签