typedef struct _IPHeader
{
    unsigned char  ip_header_len:4;  
    unsigned char  ip_version   :4;  
    unsigned char  ip_tos;           
    unsigned short ip_total_length;  
    unsigned short ip_id;            
    unsigned short ip_frag_offset;   
    unsigned char  ip_ttl;           
    unsigned char  ip_protocol;     
    unsigned short ip_checksum;      
    unsigned int   ip_srcaddr;       
    unsigned int   ip_destaddr;     
} IPHeader;
typedef struct tcp_hdr
{
unsigned short source_port;      
unsigned short dest_port;        
unsigned short udp_length;      
unsigned short udp_checksum;     
} tcp_HDR;typedef struct tcppacket
{
TCP_HDR  tcp;                    
char     messg[35];             
} TCP_PACKET;void main()
{
   
   IPHeader *ip;
   TCP_PACKET *tcp_pack          = (TCP_PACKET *) (ip + 1);
   int tcp_hdr_n_data_len        = sizeof(*tcp_pack);
   packet_length                 = ((int)(ip + 1) - (int)ip) + tcp_hdr_n_data_len;}
请问TCP_PACKET *tcp_pack          = (TCP_PACKET *) (ip + 1);和((int)(ip + 1) - (int)ip)是什么意思

解决方案 »

  1.   

    那么请问 (TCP_PACKET *) (ip + 1)指向的是哪里呢?还有(int)(ip + 1) - (int)ip是什么意思啊,谢谢你的恢复
      

  2.   

    代码不全,解释不了
    IPHeader *ip; 这里又没有分配空间谁知道ip+1会指向哪里
      

  3.   

     因为ip没有初始化,所以指向哪里是未知的 
    (TCP_PACKET *) (ip + 1)指向哪里也是未知的
    ((int)(ip + 1) - (int)ip)是IPHeader这个结构体的一个变量在内存中的大小,单位是字节不一定对,仅供参考
      

  4.   

    TCP_PACKET *tcp_pack          = (TCP_PACKET *) (ip + 1);和((int)(ip + 1) - (int)ip)是什么意思 
    TCP_PACKET *tcp_pack          = (TCP_PACKET *) (ip + 1);将ip + 1        的值转换成TCP_PACKET型赋给tcp_pack,这里ip + 1也是ip加上1楼所说的常数。
    ((int)(ip + 1) - (int)ip)     中 ip + 1和ip都是指针,指针就是整数,但是直接使用可能会产生警告。
      

  5.   

    ((int)(ip + 1) - (int)ip)     似乎是求sizeof(IPHeader)
      

  6.   

    8楼说的很对,还有就是(TCP_PACKET *) (ip + 1);指向的是sizeof(IPHeader)后面的第一字节