For reasons of efficiency, Cisco IOS doesn't look at an entire packet header unless it has to. If packets are rejected by an access list filter for other reasons, the log message will often list the packet as using “port 0”. To prevent this from happening, instead of the usual logging access list command (such as access-list 106 deny ip any any log), use the special port range arguments shown below.
The last line is necessary to ensure that rejected packets of protocols other than TCP and UDP are properly logged. [Section 4.3]