Index: include/dnet.h =================================================================== --- include/dnet.h (.../libdnet-stripped) (revision 12426) +++ include/dnet.h (.../-exp/daniel/nmap-sctp/libdnet-stripped) (revision 12426) @@ -19,6 +19,7 @@ #include #include #include +#include #include #include Index: include/dnet/sctp.h =================================================================== --- include/dnet/sctp.h (.../libdnet-stripped) (revision 0) +++ include/dnet/sctp.h (.../-exp/daniel/nmap-sctp/libdnet-stripped) (revision 12426) @@ -0,0 +1,95 @@ +/* + * sctp.h + * + * Stream Control Transmission Protocol (RFC 4960). + * + * Copyright (c) 2008-2009 Daniel Roethlisberger + * Copyright (c) 2000 Dug Song + * + * $Id$ + */ + +#ifndef DNET_SCTP_H +#define DNET_SCTP_H + +#define SCTP_HDR_LEN 12 + +struct sctp_hdr { + uint16_t sh_sport; /* source port */ + uint16_t sh_dport; /* destination port */ + uint32_t sh_vtag; /* sctp verification tag */ + uint32_t sh_sum; /* sctp checksum */ +}; + +#define SCTP_PORT_MAX 65535 + +#define sctp_pack_hdr(hdr, sport, dport, vtag) do { \ + struct sctp_hdr *sctp_pack_p = (struct sctp_hdr *)(hdr); \ + sctp_pack_p->sh_sport = htons(sport); \ + sctp_pack_p->sh_dport = htons(dport); \ + sctp_pack_p->sh_vtag = htonl(vtag); \ +} while (0) + +struct sctp_chunkhdr { + uint8_t sch_type; /* chunk type */ + uint8_t sch_flags; /* chunk flags */ + uint16_t sch_length; /* chunk length */ +}; + +/* chunk types */ +#define SCTP_DATA 0x00 +#define SCTP_INIT 0x01 +#define SCTP_INIT_ACK 0x02 +#define SCTP_SACK 0x03 +#define SCTP_HEARTBEAT 0x04 +#define SCTP_HEARTBEAT_ACK 0x05 +#define SCTP_ABORT 0x06 +#define SCTP_SHUTDOWN 0x07 +#define SCTP_SHUTDOWN_ACK 0x08 +#define SCTP_ERROR 0x09 +#define SCTP_COOKIE_ECHO 0x0a +#define SCTP_COOKIE_ACK 0x0b +#define SCTP_ECNE 0x0c +#define SCTP_CWR 0x0d +#define SCTP_SHUTDOWN_COMPLETE 0x0e +#define SCTP_AUTH 0x0f /* RFC 4895 */ +#define SCTP_ASCONF_ACK 0x80 /* RFC 5061 */ +#define SCTP_PKTDROP 0x81 /* draft-stewart-sctp-pktdrprep-08 */ +#define SCTP_PAD 0x84 /* RFC 4820 */ +#define SCTP_FORWARD_TSN 0xc0 /* RFC 3758 */ +#define SCTP_ASCONF 0xc1 /* RFC 5061 */ + +/* chunk types bitmask flags */ +#define SCTP_TYPEFLAG_REPORT 1 +#define SCTP_TYPEFLAG_SKIP 2 + +#define sctp_pack_chunkhdr(hdr, type, flags, length) do { \ + struct sctp_chunkhdr *sctp_pack_chp = (struct sctp_chunkhdr *)(hdr);\ + sctp_pack_chp->sch_type = type; \ + sctp_pack_chp->sch_flags = flags; \ + sctp_pack_chp->sch_length = htons(length); \ +} while (0) + +struct sctp_chunkhdr_init { + struct sctp_chunkhdr chunkhdr; + + int32_t schi_itag; /* Initiate Tag */ + int32_t schi_arwnd; /* Advertised Receiver Window Credit */ + int16_t schi_nos; /* Number of Outbound Streams */ + int16_t schi_nis; /* Number of Inbound Streams */ + int32_t schi_itsn; /* Initial TSN */ +}; + +#define sctp_pack_chunkhdr_init(hdr, type, flags, length, itag, \ + arwnd, nos, nis, itsn) do { \ + struct sctp_chunkhdr_init *sctp_pack_chip = (struct sctp_chunkhdr_init *)(hdr);\ + sctp_pack_chunkhdr(sctp_pack_chip, type, flags, length);\ + sctp_pack_chip->schi_itag = htonl(itag); \ + sctp_pack_chip->schi_arwnd = htonl(arwnd); \ + sctp_pack_chip->schi_nos = htons(nos); \ + sctp_pack_chip->schi_nis = htons(nis); \ + sctp_pack_chip->schi_itsn = htonl(itsn); \ +} while (0) + +#endif /* DNET_SCTP_H */ + Index: include/dnet/Makefile.am =================================================================== --- include/dnet/Makefile.am (.../libdnet-stripped) (revision 12426) +++ include/dnet/Makefile.am (.../-exp/daniel/nmap-sctp/libdnet-stripped) (revision 12426) @@ -5,4 +5,4 @@ dnetincludedir = $(includedir)/dnet dnetinclude_HEADERS = addr.h arp.h blob.h eth.h fw.h icmp.h intf.h ip.h \ - ip6.h os.h rand.h route.h tcp.h tun.h udp.h + ip6.h os.h rand.h route.h tcp.h tun.h udp.h sctp.h Index: src/ip-util.c =================================================================== --- src/ip-util.c (.../libdnet-stripped) (revision 12426) +++ src/ip-util.c (.../-exp/daniel/nmap-sctp/libdnet-stripped) (revision 12426) @@ -123,6 +123,13 @@ if (!udp->uh_sum) udp->uh_sum = 0xffff; /* RFC 768 */ } + } else if (ip->ip_p == IP_PROTO_SCTP) { + struct sctp_hdr *sctp = (struct sctp_hdr *)((u_char *)ip + hl); + + if (len >= SCTP_HDR_LEN) { + sctp->sh_sum = 0; + sctp->sh_sum = htonl(crc32c(sctp, len)); + } } else if (ip->ip_p == IP_PROTO_ICMP || ip->ip_p == IP_PROTO_IGMP) { struct icmp_hdr *icmp = (struct icmp_hdr *)((u_char *)ip + hl); Index: libdnet-stripped.vcproj =================================================================== --- libdnet-stripped.vcproj (.../libdnet-stripped) (revision 12426) +++ libdnet-stripped.vcproj (.../-exp/daniel/nmap-sctp/libdnet-stripped) (revision 12426) @@ -272,6 +272,10 @@ RelativePath=".\include\dnet\udp.h" > + +