/* * Construct an IGMP message in the output packet buffer. The caller may * have already placed data in that buffer, of length 'datalen'. */ void buildIgmp(uint32_t src, uint32_t dst, int type, int code, uint32_t group, int datalen) { struct ip *ip; struct igmp *igmp; extern int curttl; ip = (struct ip *)send_buf; ip->ip_src.s_addr = src; ip->ip_dst.s_addr = dst; ip_set_len(ip, IP_HEADER_RAOPT_LEN + IGMP_MINLEN + datalen); if (IN_MULTICAST(ntohl(dst))) { ip->ip_ttl = curttl; } else { ip->ip_ttl = MAXTTL; } /* Add Router Alert option */ ((u_char*)send_buf+MIN_IP_HEADER_LEN)[0] = IPOPT_RA; ((u_char*)send_buf+MIN_IP_HEADER_LEN)[1] = 0x04; ((u_char*)send_buf+MIN_IP_HEADER_LEN)[2] = 0x00; ((u_char*)send_buf+MIN_IP_HEADER_LEN)[3] = 0x00; igmp = (struct igmp *)(send_buf + IP_HEADER_RAOPT_LEN); igmp->igmp_type = type; igmp->igmp_code = code; igmp->igmp_group.s_addr = group; igmp->igmp_cksum = 0; igmp->igmp_cksum = inetChksum((u_short *)igmp, IP_HEADER_RAOPT_LEN + datalen); }
/** @internal @This fills ipv4/udp headers for RAW sockets * * @param upipe description structure of the pipe * @param dgram raw datagram * @param ipsrc source ip address * @param ipdst destination ip address * @param portsrc source port address * @param portdst destination port address * @param ttl datagram time-to-live * @param tos type of service * @param payload length */ static void upipe_udp_raw_fill_headers(struct upipe *upipe, uint8_t *header, in_addr_t ipsrc, in_addr_t ipdst, uint16_t portsrc, uint16_t portdst, uint8_t ttl, uint8_t tos, uint16_t len) { ip_set_version(header, 4); ip_set_ihl(header, 5); ip_set_tos(header, tos); ip_set_len(header, len + UDP_HEADER_SIZE + IP_HEADER_MINSIZE); ip_set_id(header, 0); ip_set_flag_reserved(header, 0); ip_set_flag_mf(header, 0); ip_set_flag_df(header, 0); ip_set_frag_offset(header, 0); ip_set_ttl(header, ttl); ip_set_proto(header, IPPROTO_UDP); ip_set_cksum(header, 0); ip_set_srcaddr(header, ntohl(ipsrc)); ip_set_dstaddr(header, ntohl(ipdst)); header += IP_HEADER_MINSIZE; udp_set_srcport(header, portsrc); udp_set_dstport(header, portdst); udp_set_len(header, len + UDP_HEADER_SIZE); udp_set_cksum(header, 0); }
void udp_raw_set_len(uint8_t *raw_header, uint16_t len) { uint16_t iplen = len + UDP_HEADER_SIZE + IP_HEADER_MINSIZE; #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__APPLE__) iplen = htons(iplen); #endif ip_set_len(raw_header, iplen); raw_header += IP_HEADER_MINSIZE; udp_set_len(raw_header, len + UDP_HEADER_SIZE); }